-
Notifications
You must be signed in to change notification settings - Fork 156
/
Assignment7.Rmd
83 lines (56 loc) · 3.23 KB
/
Assignment7.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
title: "Assignment 7 - Answers"
author: "Charles Lang"
date: "11/30/2016"
output: html_document
---
In the following assignment you will be looking at data from an one level of an online geography tutoring system used by 5th grade students. The game involves a pre-test of geography knowledge (pre.test), a series of assignments for which you have the average score (av.assignment.score), the number of messages sent by each student to other students about the assignments (messages), the number of forum posts students posted asking questions about the assignment (forum.posts), a post test at the end of the level (post.test) and whether or not the system allowed the students to go on to the next level (level.up).
## Part I
#Upload data
```{r}
```
#Visualization
```{r}
#Start by creating histograms of the distributions for all variables (#HINT: look up "facet" in the ggplot documentation)
#Then visualize the relationships between variables
#Try to capture an intution about the data and the relationships
```
#Classification tree
```{r}
#Create a classification tree that predicts whether a student "levels up" in the online course using three variables of your choice (As we did last time, set all controls to their minimums)
#Plot and generate a CP table for your tree
#Generate a probability value that represents the probability that a student levels up based your classification tree
D1$pred <- predict(rp, type = "prob")[,2]#Last class we used type = "class" which predicted the classification for us, this time we are using type = "prob" to see the probability that our classififcation is based on.
```
## Part II
#Now you can generate the ROC curve for your model. You will need to install the package ROCR to do this.
```{r}
library(ROCR)
#Plot the curve
pred.detail <- prediction(D1$pred, D1$level.up)
plot(performance(pred.detail, "tpr", "fpr"))
abline(0, 1, lty = 2)
#Calculate the Area Under the Curve
unlist(slot(performance(Pred2,"auc"), "y.values"))#Unlist liberates the AUC value from the "performance" object created by ROCR
#Now repeat this process, but using the variables you did not use for the previous model and compare the plots & results of your two models. Which one do you think was the better model? Why?
```
## Part III
#Thresholds
```{r}
#Look at the ROC plot for your first model. Based on this plot choose a probability threshold that balances capturing the most correct predictions against false positives. Then generate a new variable in your data set that classifies each student according to your chosen threshold.
threshold.pred1 <-
#Now generate three diagnostics:
D1$accuracy.model1 <-
D1$precision.model1 <-
D1$recall.model1 <-
#Finally, calculate Kappa for your model according to:
#First generate the table of comparisons
table1 <- table(D1$level.up, D1$threshold.pred1)
#Convert to matrix
matrix1 <- as.matrix(table1)
#Calculate kappa
kappa(matrix1, exact = TRUE)/kappa(matrix1)
#Now choose a different threshold value and repeat these diagnostics. What conclusions can you draw about your two thresholds?
```
### 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.