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
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
28 changes: 24 additions & 4 deletions Assignment6.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ 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(certified ~ grade + assignment, method="class", data=M1)

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


printcp(c.tree1)

#Plot your tree

Expand All @@ -52,7 +52,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.1)#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 @@ -70,14 +70,34 @@ table(M2$certified, M2$predict1)

table(M2$certified, M2$predict2)

accuracy1 <- sum(M2$predict1 == M2$certified)/length(M2$predict1)
accuracy1

accuracy2 <- sum(M2$predict2 == M2$certified)/length(M2$predict2)
accuracy2

#tree1 has an accuracy rate of 0.2186; tree2 has an accuracy rate of 0.5363 so tree2 has a lower error rate
```

##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(readr)
student.course <- read.csv(file = "student.course.csv", header = TRUE)

subject.tree <- rpart(SUBJECT ~ GRD_PTS_PER_UNIT + DIV, method="class", data=student.course)
printcp(subject.tree)
post(subject.tree, file = "subject.tree.ps")

install.packages("PCAmixdata")
library("PCAmixdata")

X.quanti <- splitmix(student.course)$X.quanti
X.quali <- splitmix(student.course)$X.quali

pca<-PCAmix(X.quanti,X.quali)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work. You could continue to change a different set of predictors and compare the two models. Using PCA is a good try. Continue to finish that!

```


Expand Down
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
138,889 changes: 138,889 additions & 0 deletions student.record.csv

Large diffs are not rendered by default.

Binary file added subject.tree.ps
Binary file not shown.
Binary file added tree1.ps
Binary file not shown.
Binary file added tree2.ps
Binary file not shown.