Skip to content
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
170 changes: 85 additions & 85 deletions Assignment6.Rmd
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
---
title: "Assignment 6"
author: "Charles Lang"
date: "11/16/2016"
output: html_document
---
#Addignment 6

In this assignment you will be looking at data from a MOOC. It contains the following per-student variables:

certified (yes/no) - Whether or not a student paid for the course
forum.posts (numeric) - How many forum posts a student made throughout the course
grade (numeric) - A student's average grade for the course exam
assignment (numeric) - A student's average grade for the course assignments

##Part I

#Packages
```{r}
library(rpart)
```

#Data
```{r}
#Upload the data sets MOOC1.csv and MOOC2.csv
M1 <- read.csv("MOOC1.csv", header = TRUE)

M2 <-

```

#Decision tree
```{r}
#Using the rpart package generate a classification tree predicting certified from the other variables in the M1 data frame. Which variables should you use?

c.tree1 <-

#Check the results from the classifcation tree using the printcp() command



#Plot your tree

post(c.tree1, file = "tree1.ps", title = "MOOC") #This creates a pdf image of the tree

```

##Part II

#The heading "xerror" in the printcp table stands for "cross validation error", it is the error rate of assigning students to certified/uncertified of the model averaged over 10-fold cross validation. CP stands for "Complexity Parameter" and represents the cost to error for adding a node to the tree. Notice it decreases as we add more nodes to the tree which implies that more nodes make better predictions. However, more nodes also mean that we may be making the model less generalizable, this is known as "overfitting".

#If we are worried about overfitting we can remove nodes form our tree using the prune() command, setting cp to the CP value from the table that corresponds to the number of nodes we want the tree to terminate at. Let's set it to two nodes.

```{r}
c.tree2 <- prune(c.tree1, cp = )#Set cp to the level at which you want the tree to end

#Visualize this tree and compare it to the one you generated earlier

post(c.tree2, file = "tree2.ps", title = "MOOC") #This creates a pdf image of the tree
```

#Now use both the original tree and the pruned tree to make predictions about the the students in the second data set. Which tree has a lower error rate?

```{r}
M2$predict1 <- predict(c.tree1, M2, type = "class")

M2$predict2 <- predict(c.tree2, M2, type = "class")

table(M2$certified, M2$predict1)

table(M2$certified, M2$predict2)

```

##Part III

Choose a data file from the (University of Michigan Open Data Set)[https://github.com/bkoester/PLA/tree/master/data]. Choose an outcome variable that you would like to predict. Build two models that predict that outcome from the other variables. The first model should use raw variables, the second should feature select or feature extract variables from the data. Which model is better according to the cross validation metrics?

```{r}

```


### To Submit Your Assignment

---
title: "Assignment 6"
author: "Charles Lang"
date: "11/16/2016"
output: html_document
---
#Assignment 6
In this assignment you will be looking at data from a MOOC. It contains the following per-student variables:
certified (yes/no) - Whether or not a student paid for the course
forum.posts (numeric) - How many forum posts a student made throughout the course
grade (numeric) - A student's average grade for the course exam
assignment (numeric) - A student's average grade for the course assignments
##Part I
#Packages
```{r}
library(rpart)
```
#Data
```{r}
#Upload the data sets MOOC1.csv and MOOC2.csv
M1 <- read.csv("MOOC1.csv", header = TRUE)
M2 <- read.csv("MOOC2.csv", header = TRUE)
```
#Decision tree
```{r}
#Using the rpart package generate a classification tree predicting certified from the other variables in the M1 data frame. Which variables should you use?
c.tree1 <- rpart(certified ~ forum.posts + grade, method="class", data=M1)
#Check the results from the classifcation tree using the printcp() command
printcp(c.tree1)
#Plot your tree
post(c.tree1, file = "tree1.ps", title = "MOOC") #This creates a pdf image of the tree
```
##Part II
#The heading "xerror" in the printcp table stands for "cross validation error", it is the error rate of assigning students to certified/uncertified of the model averaged over 10-fold cross validation. CP stands for "Complexity Parameter" and represents the cost to error for adding a node to the tree. Notice it decreases as we add more nodes to the tree which implies that more nodes make better predictions. However, more nodes also mean that we may be making the model less generalizable, this is known as "overfitting".
#If we are worried about overfitting we can remove nodes form our tree using the prune() command, setting cp to the CP value from the table that corresponds to the number of nodes we want the tree to terminate at. Let's set it to two nodes.
```{r}
c.tree2 <- prune(c.tree1, cp = .01000 )#Set cp to the level at which you want the tree to end
#Visualize this tree and compare it to the one you generated earlier
post(c.tree2, file = "tree2.ps", title = "MOOC") #This creates a pdf image of the tree
```
#Now use both the original tree and the pruned tree to make predictions about the the students in the second data set. Which tree has a lower error rate?
```{r}
M2$predict1 <- predict(c.tree1, M2, type = "class")
M2$predict2 <- predict(c.tree2, M2, type = "class")
table(M2$certified, M2$predict1)
table(M2$certified, M2$predict2)
```
##Part III
Choose a data file from the (University of Michigan Open Data Set)[https://github.com/bkoester/PLA/tree/master/data]. Choose an outcome variable that you would like to predict. Build two models that predict that outcome from the other variables. The first model should use raw variables, the second should feature select or feature extract variables from the data. Which model is better according to the cross validation metrics?
```{r}
```
### 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.
Loading