Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment5 Zhaozhuo #125

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions Assignment 5.Rmd
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
---
title: "Assignment 5 - Decision Trees"
author: "Charles Lang"
date: "November 9, 2016"
output: html_document
---
For this assignment we will be using data from the Assistments Intelligent Tutoring system. This system gives students hints based on how they perform on math problems.

#Install & call libraries
```{r}
install.packages("party", "rpart")
#install.packages("party", "rpart")

library(rpart)
library(party)
```

## Part I
```{r}
D1 <-
D1 <- read.csv("intelligent_tutor.csv", header = TRUE)
```

##Classification Tree
Expand All @@ -40,43 +38,61 @@ We want to see if we can build a decision tree to help teachers decide which stu

#Visualize our outcome variable "score"
```{r}

hist(D1$score)
```

#Create a categorical outcome variable based on student score to advise the teacher using an "ifelse" statement

###"We will create three groups
("teacher should intervene",
"teacher should monitor student progress"
and "no action")"

```{r}
D1$advice <-
D1$advice <- ifelse(D1$score<0.3,"intervene",ifelse(D1$score<0.6 & D1$score>0.3,"monitor student progress","no action"))

```

#Build a decision tree that predicts "advice" based on how many problems students have answered before, the percentage of those problems they got correct and how many hints they required
```{r}
score_ctree <-
score_ctree <- ctree(factor(advice)~prior_prob_count+prior_percent_correct+hints,data=D1)
```

#Plot tree
```{r}

plot(score_ctree)
```

Please interpret the tree, which two behaviors do you think the teacher should most closely pay attemtion to?
Please interpret the tree, which two behaviors do you think the teacher should most closely pay attention to?

#The teacher should pay attention to students who need more than 54 hints and prior percentage of correct less than 0.696 most closely.

#Test Tree
Upload the data "intelligent_tutor_new.csv". This is a data set of a differnt sample of students doing the same problems in the same system. We can use the tree we built for the previous data set to try to predict the "advice" we should give the teacher about these new students.

```{r}
#Upload new data

D2 <-
D2 <- read.csv("intelligent_tutor_new.csv", header=TRUE)

#Generate predicted advice using the predict() command for new students based on tree generated from old students

D2$prediction <-
D2$prediction <- predict(score_ctree,D2)

```
## Part III
Compare the predicted advice with the actual advice that these students recieved. What is the difference between the observed and predicted results?

### To Submit Your Assignment
```{r}
D2$advice <- ifelse(D2$score<0.3,"intervene",ifelse(D2$score<0.6 & D1$score>0.3,"monitor student progress","no action"))

#but as for the actul advice received by student, everyone's score is 1, that means no action.

X <- ifelse(D2$prediction=="no action",1,0)
mean(X)

#The observed and predicted results are quite different.
```
### To Submit Your Assignment
Please submit your assignment by first "knitting" your RMarkdown document into an html file and then commit, push and pull request both the RMarkdown file and the html file.

Loading