diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6a065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata diff --git a/Assignment6.Rmd b/Assignment6.Rmd index 8e65135..f0c5b7e 100644 --- a/Assignment6.Rmd +++ b/Assignment6.Rmd @@ -18,14 +18,14 @@ assignment (numeric) - A student's average grade for the course assignments #Packages ```{r} library(rpart) +library(party) ``` #Data ```{r} #Upload the data sets MOOC1.csv and MOOC2.csv M1 <- read.csv("MOOC1.csv", header = TRUE) - -M2 <- +M2 <- read.csv("MOOC2.csv", header = TRUE) ``` @@ -33,15 +33,15 @@ M2 <- ```{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 - +printcp(c.tree1) #Plot your tree -post(c.tree1, file = "tree1.ps", title = "MOOC") #This creates a pdf image of the tree +post(c.tree1, file = "tree1.ps", title = "MOOC") #This creates a pdf image of the tree ``` @@ -52,9 +52,10 @@ 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.06)#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 +printcp(c.tree2) post(c.tree2, file = "tree2.ps", title = "MOOC") #This creates a pdf image of the tree ``` @@ -72,12 +73,26 @@ table(M2$certified, M2$predict2) ``` +```{r} +sum(diag(table(M2$certified, M2$predict1)))/sum(table(M2$certified, M2$predict1))*100 +``` + +```{r} +table(M2$certified, M2$predict2) +``` + +```{r} +sum(diag(table(M2$certified, M2$predict2)))/sum(table(M2$certified, M2$predict2))*100 +``` + ##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} +D1 <- as.data.frame(read_csv("https://raw.githubusercontent.com/fcarnauba/PLA/master/data/student.course.csv")) + ``` diff --git a/assignment6.Rproj b/assignment6.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/assignment6.Rproj @@ -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 diff --git a/tree1.ps b/tree1.ps new file mode 100644 index 0000000..e71d1b5 Binary files /dev/null and b/tree1.ps differ diff --git a/tree2.ps b/tree2.ps new file mode 100644 index 0000000..a6a7043 Binary files /dev/null and b/tree2.ps differ