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

heartbroken #154

Open
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
45 changes: 41 additions & 4 deletions Assignment6.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ library(rpart)
#Upload the data sets MOOC1.csv and MOOC2.csv
M1 <- read.csv("MOOC1.csv", header = TRUE)

M2 <-
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 <-
c.tree1 <- rpart(as.factor(certified) ~ grade + assignment, method="class", data=M1)

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

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

printcp(c.tree1)

#Plot your tree

Expand All @@ -48,7 +50,7 @@ post(c.tree1, file = "tree1.ps", title = "MOOC") #This creates a pdf image of th
#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
c.tree2 <- prune(c.tree1, cp = 0.058182)#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

Expand All @@ -67,3 +69,38 @@ 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}
library(dplyr)
library(tidyverse)
ABC <- read.csv("student.course.csv",header = TRUE)
ABC <- filter(ABC, DIV == "P")
#Create column for letter grade
ABC$LETTER_GRADE = ifelse(ABC$GPAO>3.3,"A",ifelse(ABC$GPAO>2.3,"B",ifelse(ABC$GPAO>1,"C","F")))
#split data into train set and test set
set.seed(123)
train <- sample(1:nrow(ABC), size=0.8*nrow(ABC))
train_set <- ABC[train,]
test_set <- ABC[-train,]
#Create the tree
c.tree3<-rpart(LETTER_GRADE ~ .-GPAO,train_set)
printcp(c.tree3)
post(c.tree3,file = "tree3.ps", title = "course 1")
prediction<-predict(c.tree3,test_set)
#Pruned tree
c.tree4<-rpart(LETTER_GRADE ~ GRD_PTS_PER_UNIT + SUBJECT,train_set)
printcp(c.tree4)
post(c.tree3,file = "tree4.ps", title = "course 1")
prediction2 <- predict(c.tree4, test_set)
#The second model is slightly better since the xerror is 0.750. The first is 0.751

```


### 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.
557 changes: 557 additions & 0 deletions Assignment6.html

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions assignment6.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