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

finish! #109

Open
wants to merge 1 commit 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
35 changes: 26 additions & 9 deletions Assignment 5.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ library(party)

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

##Classification Tree
First we will build a classification tree to predict which students ask a teacher for help, which start a new session, or which give up, based on whether or not the student completed a session (D1$complete) and whether or not they asked for hints (D1$hint.y).
```{r}

c.tree <- rpart(action ~ hint.y + complete, method="class", data=D1) #Notice the standard R notion for a formula X ~ Y
c.tree <- rpart(action ~ hint.y + complete, method="class", data=D1)


#Notice the standard R notion for a formula X ~ Y

#Look at the error of this tree
printcp(c.tree)
Expand All @@ -40,41 +43,55 @@ 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
```{r}
D1$advice <-
D1$advice <- ifelse(D1$score <=0.4,"intervene", ifelse(D1$score>0.4 & D1$score<=0.8,"monitor", "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 <-
#regress advice on the other three variables
score_ctree <- ctree(factor(advice) ~ prior_prob_count + prior_percent_correct + hints, 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?

1.For students who ask for over 12 times of hints and still ask for 40% of intervene and 60% of monitoring, teachers should pay more attention to them.
2. For 40% students who ask no hints and grades lower than 85 and ask for no actions is also problematic, since they do not understand and they don't ask for hints or any other intervence.
#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")

#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?
```{r}
T1 <-table(D2$prediction)

#monitor
T1[2]/sum(T1)

#no action
T1[3]/sum(T1)

since everybody gets 1, and that means everybody should get no action. But our model says some students need monitor, so that means our model is not perfect!
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. You can specify and report the accuracy rate of the model. To determine whether the model did a good job in prediction precision, we can compare it with a baseline model (prediction) which is unfortunately 100% here but should not be like this in the real-world dataset.

```

### To Submit Your Assignment

Expand Down
13 changes: 13 additions & 0 deletions assignment5.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
Binary file added tree.ps
Binary file not shown.