Created
August 19, 2014 11:56
-
-
Save springcoil/92c5cb4f41021553d726 to your computer and use it in GitHub Desktop.
Coursera UW: Introduction to Data Science
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages("caret") | |
install.packages("rpart") | |
install.packages("tree") | |
install.packages("randomForest") | |
install.packages("e1071") | |
install.packages("ggplot2") | |
table <- read.csv("DataSciIntro/assignment5//seaflow_21min.csv") | |
library("caret") | |
library("rpart") | |
library("tree") | |
library("randomForest") | |
library("e1071") | |
library("ggplot2") | |
set.seed(730) | |
trainIndex = createDataPartition(table$pop, p = 0.5, list = FALSE) | |
head(trainIndex) | |
summary(trainIndex) | |
trainPredictors <- table[trainIndex, ] | |
testPredictors <- table[-trainIndex, ] | |
str(trainPredictors) | |
summary(trainPredictors) | |
summary(testPredictors) | |
# As is always the case we can do the plot | |
ggplot(trainPredictors, aes(x=chl_small, y=pe)) + geom_point(aes(colour=pop)) | |
#Let us the decision tree stuff | |
response ~ fsc_small + fsc_perp + fsc_big + pe + chl_big + chl_small | |
fol <- formula(pop ~ fsc_small + fsc_perp + fsc_big + pe + chl_big + chl_small) | |
model <- rpart(fol, method="class", data=trainPredictors) | |
print(model) | |
help(predict) | |
a <- predict(model, newdata=testPredictors, type="class") | |
b <-c(testPredictors$pop) | |
c <- a==b | |
summary(c) | |
31011/(5160+31011) | |
model <- randomForest(fol, data=trainPredictors, nodesize=8) | |
help(randomForest) | |
rf <- predict(model, method="class", newdata=testPredictors) | |
d <-c(testPredictors$pop) | |
c <- rf==d | |
importance(model) | |
model <- svm(fol, data=trainPredictors, method="class") | |
predictions <- predict(model, method="class", newdata=testPredictors) | |
e<-c(testPredictors$pop) | |
g <- rfsvm==e | |
summary(g) | |
table(pred = predictions, true = testPredictors$pop) | |
table(pred = rf, true = testPredictors$pop) | |
table(pred = a, true = testPredictors$pop) | |
ggplot(table, aes(x=table$chl_small, y=table$time)) + geom_point(aes(colour=table$pop)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment