Last active
August 29, 2015 14:23
-
-
Save datalove/2deaa8411262103d835b to your computer and use it in GitHub Desktop.
Basic usage of 'caret' package with artificial neural net from 'nnet' package
This file contains hidden or 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
######################### | |
# find and load packages | |
######################### | |
install.packages(c("nnet","caret")) | |
library(caret) | |
################### | |
# Build neural net | |
################### | |
formula <- mpg ~ cyl + disp + hp + wt + gear | |
net <- train(formula, data = mtcars, method = "nnet", linout = TRUE) | |
################## | |
# Use neural net | |
################## | |
new_data <- data.frame(cyl = 4, disp = 320, hp = 140, wt = 3.4, gear = 4) | |
predict(net, new_data) # predicts 25.67 | |
###################### | |
# Build linear regr, | |
# and predict | |
###################### | |
lm1 <- lm(formula, data = mtcars) | |
predict(lm1, new_data) # predicts 23.49 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment