Skip to content

Instantly share code, notes, and snippets.

@springcoil
Created August 19, 2014 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save springcoil/365c0e43c06625957422 to your computer and use it in GitHub Desktop.
Save springcoil/365c0e43c06625957422 to your computer and use it in GitHub Desktop.
Coursera UW: Introduction to Data Science
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