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

Assignment 5 #96

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

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

library(rpart)
library(party)
```

## Part I
```{r}
D1 <-
D1 <- read.csv("~/Desktop/HUDK4050/Assignment 5/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)

#Plot the tree
post(c.tree, file = "tree.ps", title = "Session Completion Action: 1 - Ask teacher, 2 - Start new session, 3 - Give up")
post(c.tree, file = "", title = "Session Completion Action: 1 - Ask teacher, 2 - Start new session, 3 - Give up")


```
## Part II
Expand All @@ -41,41 +41,59 @@ We want to see if we can build a decision tree to help teachers decide which stu
#Visualize our outcome variable "score"
```{r}

score <- table(D1$score)

barplot(score, xlab = "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.70, 1, 0)

```

#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 <-
advice_ctree <- rpart(advice ~ prior_prob_count + prior_percent_correct + hints, method="class", data = D1)
```

#Plot tree
```{r}
post(advice_ctree, file = "", title = "")

summary(advice_ctree)
```

Please interpret the tree, which two behaviors do you think the teacher should most closely pay attemtion to?
# With 5 splits, the error is approximately 60%. The generalizability of this is 70%. Would recommend that the teacher
# pay attention to the number of problems answered incorrectly by the student and the number of hints the student requested.

#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("~/Desktop/HUDK4050/Assignment 5/intelligent_tutor_new.csv")

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

D2$prediction <-
predict(advice_ctree, D2)

D2$prediction <- predict(advice_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}
summary(D2$prediction, D2$prior_percent_correct)

```

The measures of centrality seem to be way off. Other descriptive measures seem to be comparable.

### 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
13 changes: 13 additions & 0 deletions Assignment 5.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
Loading