Skip to content

Instantly share code, notes, and snippets.

@JakubMifek
Created November 28, 2018 21:09
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 JakubMifek/f2c19c05372230e67d8c2fd8ca14eb07 to your computer and use it in GitHub Desktop.
Save JakubMifek/f2c19c05372230e67d8c2fd8ca14eb07 to your computer and use it in GitHub Desktop.
attach(train)
m.tree <- rpart(mpg01 ~ ., train)
rpart.plot(m.tree)
prediction.m.tree <- predict(m.tree, test, type="class")
table(prediction.m.tree)
m.tree.cm <- table(prediction.m.tree, test$mpg01)
m.tree.cm
message("Accuracy = ", sum(diag(m.tree.cm))/78)
M.deep <- rpart(mpg01 ~ ., train, cp=0.000001)
rpart.plot(M.deep)
printcp(M.deep)
plotcp(M.deep)
prediction.M.deep <- predict(M.deep, test, type="class")
table(prediction.M.deep)
M.deep.cm = table(prediction.M.deep, test$mpg01)
M.deep.cm
message("Accuracy = ", sum(diag(M.deep.cm))/78)
M.best <- rpart(mpg01 ~ ., train, cp=0.018)
rpart.plot(M.best)
printcp(M.best)
plotcp(M.best)
prediction.M.best <- predict(M.best, test, type="class")
table(prediction.M.best)
M.best.cm = table(prediction.M.best, test$mpg01)
M.best.cm
message("Accuracy = ", sum(diag(M.best.cm))/78)
detach(train)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment