-
Notifications
You must be signed in to change notification settings - Fork 231
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
Jiancong Shen Assignment 5 #98
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,14 @@ 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) | ||
library(rpart.plot) | ||
``` | ||
|
||
## Part I | ||
```{r} | ||
D1 <- | ||
D1 <- read.csv("intelligent_tutor.csv",header=TRUE) | ||
``` | ||
|
||
##Classification Tree | ||
|
@@ -40,22 +39,25 @@ We want to see if we can build a decision tree to help teachers decide which stu | |
|
||
#Visualize our outcome variable "score" | ||
```{r} | ||
|
||
boxplot(D1$score,axes = FALSE,staplewex = 1) | ||
text(y=boxplot.stats(D1$score)$stats, labels = boxplot.stats(D1$score)$stats,x=1.4) | ||
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.8,1,ifelse(D1$score<=0.5,3,2)) | ||
D1$advice<-as.factor(D1$advice) | ||
``` | ||
|
||
#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(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? | ||
|
@@ -65,16 +67,22 @@ Upload the data "intelligent_tutor_new.csv". This is a data set of a differnt sa | |
|
||
```{r} | ||
#Upload new data | ||
|
||
D2 <- | ||
library(dplyr) | ||
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} | ||
D2$advice <- ifelse(D2$score>=0.8,1,ifelse(D2$score<=0.5,3,2)) | ||
accuracy<-nrow(filter(D2,prediction==1))/nrow(D2) | ||
|
||
#The predicted score is 65% accurate. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Elaborate on it, as in, specify whether the model overfits or whether it is generalizable. Also, calculate the error rate of the model predictions. |
||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall, great job on the coding part of this assignment but you may want to work on the analysis. |
||
|
||
### To Submit Your Assignment | ||
|
||
|
Large diffs are not rendered by default.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to answer this question.