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

Complete! - Jie Chen #110

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
49 changes: 41 additions & 8 deletions Assignment 5.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ For this assignment we will be using data from the Assistments Intelligent Tutor

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

library(rpart)
library(rpart.plot)
library(party)
```

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

##Classification Tree
Expand All @@ -31,6 +32,11 @@ printcp(c.tree)
#Plot the tree
post(c.tree, file = "tree.ps", title = "Session Completion Action: 1 - Ask teacher, 2 - Start new session, 3 - Give up")

plot(c.tree, compress = TRUE)
text(c.tree, use.n = TRUE)

rpart.plot(c.tree)

```
## Part II

Expand All @@ -40,42 +46,69 @@ 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.3, "Intervene", ifelse(D1$score < 0.6, "Monitor 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 <- rpart(advice ~ prior_prob_count + prior_percent_correct + hints, method="class", data=D1)
```

#Plot tree
```{r}
post(score_ctree, file = "score_tree.ps", title = "Session Completion Advice: 1 - Intervene, 2 - Monitor Progress, 3 - No Action")

plot(score_ctree, compress = TRUE)
text(score_ctree, use.n = TRUE)

rpart.plot(score_ctree)
```

Please interpret the tree, which two behaviors do you think the teacher should most closely pay attemtion to?
1. hints >= 58
2. prior_percent_corect < 0.6


#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, "class")
```
## Part III
Compare the predicted advice with the actual advice that these students recieved. What is the difference between the observed and predicted results?

The following results show that the predicted "no action" is less than the one observed, the "monitor progress" number is more than the observed number, and there is no student need to be intervened. I feel that the predicted one is more centralized since the middle choice - "monitor progress" is more than the observed one.
```{r}

# Observed
# No Action: 34% + 39% = 73%
# Monitor Progress: 6% + 19% = 25%
# Intervene: 2%

# Predicted

# No Action
sum(D2$prediction == "No Action") / nrow(D2) # 64.5%
# Monitor Progress
sum(D2$prediction == "Monitor Progress") / nrow(D2) # 34.5%
# Intervene
sum(D2$prediction == "Intervene") / nrow(D2) # 0.01%
Copy link

Choose a reason for hiding this comment

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

Good work in general! I am not sure why you need to add "class" in "predict" function. Sometimes it is good to specify the argument and add comments to explain that. Attach the predict function document here for your reference: https://www.rdocumentation.org/packages/stats/versions/3.6.0/topics/predict.lm


```


### 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.
Expand Down
522 changes: 522 additions & 0 deletions Assignment-5.html

Large diffs are not rendered by default.

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 score_tree.ps
Binary file not shown.
Binary file added tree.ps
Binary file not shown.