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

Assignment6-reup #157

Open
wants to merge 2 commits 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
38 changes: 31 additions & 7 deletions Assignment6.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
title: "Assignment 6"
author: "Charles Lang"
date: "11/16/2016"
output: html_document
output:
html_document: default
pdf_document: default
---
#Addignment 6

Expand All @@ -25,15 +27,15 @@ 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 ~ assignment + grade, method = "class", data = M1)

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

Expand All @@ -52,7 +54,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.085555)#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 @@ -77,10 +79,32 @@ table(M2$certified, M2$predict2)
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}

data <- read.csv("student.record.csv", header = T)
data <- data[,c(4:13)]
data<- na.omit(data)
#For the first prediction model, I use the SAT scores, ACT scores and sex variables to predict the GPA
c.tree3 <- rpart(as.factor(HSGPA) ~., method = "class", data = data)
printcp(c.tree3)
#For the second prediction model, I use the composite SAT scores, composite ACT scores and sex variables to predict the GPA
HSGPA <- data[,1]
SEX <- data[, 10]
ACT <- data[, 2:6]
ACT$ACTscore <- rowSums(ACT)
SAT <- data[, 7:9]
SAT$SATscore <- rowSums(SAT)
data2 <- cbind(HSGPA, ACT, SAT, SEX)
c.tree4 <- rpart(as.factor(HSGPA) ~ ACTscore + SATscore + SEX,
method = "class", data = data2)
printcp(c.tree4)
data2$predict1 <- predict(c.tree3, data2, type = "class")
t1 <- table(data2$HSGPA, data2$predict1)
sum(diag(table(data2$HSGPA, data2$predict1)))/sum(table(data2$HSGPA, data2$predict1))
data2$predict2 <- predict(c.tree4, data2, type = "class")
t2 <- table(data2$HSGPA, data2$predict2)
sum(diag(table(data2$HSGPA, data2$predict2)))/sum(table(data2$HSGPA, data2$predict2))
```

##As we can observe from the table, the accuracy for the first model is roughly 26.08% and the accuracy for the second model is also 26.04%. The prediction accuracy is quiet close to each other for both models.

### 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.
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.
Loading