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

Assignment 6 submission #144

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
46 changes: 40 additions & 6 deletions Assignment6.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Assignment 6"
author: "Charles Lang"
date: "11/16/2016"
author: "Maho Hayashi"
date: "11/24/2019"
output: html_document
---
#Addignment 6
Expand All @@ -18,26 +18,27 @@ assignment (numeric) - A student's average grade for the course assignments
#Packages
```{r}
library(rpart)

```

#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)

```

#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, data = M1)

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


printcp(c.tree1)

#Plot your tree

Expand All @@ -52,10 +53,12 @@ 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

printcp(c.tree2)

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

Expand All @@ -68,15 +71,46 @@ M2$predict2 <- predict(c.tree2, M2, type = "class")

table(M2$certified, M2$predict1)

sum(diag(table(M2$certified, M2$predict1)))/sum(table(M2$certified, M2$predict1))


table(M2$certified, M2$predict2)

sum(diag(table(M2$certified, M2$predict2)))/sum(table(M2$certified, M2$predict2))

#The first model has an accuracy rate of 21.8% whereas the second model has the accuracy rate of 53.6%. This tells us that the second model probably has the lower error rate...


```


```{r}

```

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

#Outcome variable <- grade point per unit

c.tree3 <- rpart(GRD_PTS_PER_UNIT~ANONID + GPAO, data = D1)

printcp(c.tree3)

D2 <- D1 %>% select (-SUBJECT, -DIV)
D2 <- scale (D2, center = TRUE)

pca <- prcomp (D2, scale = TRUE)


D3 <- data.frame(pca$x)



```

Expand Down
547 changes: 547 additions & 0 deletions Assignment6.html

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions assignment6_Maho Hayashi.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
Binary file added tree1.ps
Binary file not shown.
Binary file added tree2.ps
Binary file not shown.