From 385aeef505588d0c3a85795b38bf6efc7349bcc9 Mon Sep 17 00:00:00 2001 From: wuuyiijiaa Date: Thu, 19 Dec 2019 10:44:15 -0500 Subject: [PATCH 1/2] 6 --- .gitignore | 4 ++++ assignment6.Rproj | 13 +++++++++++++ tree1.ps | Bin 0 -> 5823 bytes tree2.ps | Bin 0 -> 4675 bytes 4 files changed, 17 insertions(+) create mode 100644 .gitignore create mode 100644 assignment6.Rproj create mode 100644 tree1.ps create mode 100644 tree2.ps 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.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 0000000000000000000000000000000000000000..e71d1b571d4a6f2dfe65bb8b2415f47d22392fdd GIT binary patch literal 5823 zcmd5=ZEu{$7XHq!IQ?L0qiScF0T!^*NVSvnMoQ`^snicqKCm!e)5`)E*u2Qs|Gm!{ z7#7xRH?34Dtz$Sd=ggevyyLSU-o9V{oK+jW^n~l2ojtG8{Z5zNuUcn1d#BrK-=w-d zr|YWh=s&vnq`N##!1?3R((-{fgaSNpEsci6gYbkbD~Z@#atyU$6(I=oG`3}=ya zy3F{5t0o8Dq|2-FoL(no)}~3#oEO!;%<^)3QGGcl8SzgLh7>6un=i`jvf8nwT4vST zynNeKMYVNSo0{mBwk@^qez{+)Ks`pGt(Vq`r0|84Ie?GZbdzu zgH3Zz@=1ehlb4xcU2Pk)-sl$S=3Cla-QHB6YrrIM;%6$mBbMD&@M1OF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FTMjS&nnK+U`S2652t}aqaD}&oqjU5q9~}}z#zX)&1iB9hDICSU({G6Y zldo_>Ch%kqcWfs70EA?i_=r;qZ6!2fI4vfyrQwA5gb_>0gez1C0+EIko`R?qPNZ)o%~OfZ1DyPoP>o zN5EZBt-l5ds2&PHf@)D3{D?vu023NeZET>ylV%q-6HriXL`|$gwZS&Wz!XPeAULLj z9AlkqG1+}$c<{-EjyaRw-2n*)cmmR#3B=41o9qB#LNi2-)57H&#Q|kU&6)JEo*cvY zfW{|h)I06|tlMpONzi47am2XT9Ydc_t?Ro)>obtSj#Jabrwjf#nfol~fcELnk;VsQ z>F{kPx%4q@5(Y3KL);Rimt#VLY{LaYo#D*IXJWUw)AU{ZKL&F9ziGPCKy-bV<2w6# z$WUDyL} z85*3jQ+wLHZwJD2sNY0RjXzh%O{rEx8zSlME!Ccj!*pnNesOU!xTkpt`%pz`rYpR4 N|AQj&dV2B3`Ujnq4Nw38 literal 0 HcmV?d00001 From 9ab1722907f61cd4d4323f0e50b3b9900c73c543 Mon Sep 17 00:00:00 2001 From: wuuyiijiaa Date: Thu, 19 Dec 2019 17:38:12 -0500 Subject: [PATCH 2/2] /// --- Assignment6.Rmd | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) 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")) + ```