iris nn-model Published by onesixx on 19-05-02 19-05-02
# Classification And REgression Training
# visualizing classifier performance
pacman::p_load(nnet, caret , NeuralNetTools,ROCR)
# DATA -------------------------------------------------------------------------
cb <- iris
# preprocessing 1 (Y가 불연속인결우, factor로 변환) ------------------------------
cb %>% str()
cb$Species %>% summary()
# Train/Test dataset -------------------------------------------------------------
set.seed(666)
inTrain <- createDataPartition(y=cb$Species, p=.6, list=F)
cb.train <- cb[inTrain,]
cb.test <- cb[-inTrain,]
# Modeling ---------------------------------------------------------------------
fit_model <- nnet( Species ~ . , data=cb.train,
\t\t\t\t\t\t\t\t\t size=3, maxit=1000, # size=hidden_node, maxit=NoOf iterations
\t\t\t\t\t\t\t\t\t act.fct="logistic", linear.output = FALSE)
fit_model1 <- nnet( as.formula(
\t\t\t\t\t\t\t\t\t\t\tstr_c(names(cb)[length(cb)],
\t\t\t\t\t\t\t\t\t\t\t\t\t\tstr_c(names(cb)[-length(cb)], collapse="+") ,
\t\t\t\t\t\t\t\t\t\t\t\t\t\tsep="~")
\t\t\t\t\t\t\t\t\t\t) , data=cb.train,
\t\t\t\t\t\t\t\t\t size=3, maxit=1000, # size=hidden_node, maxit=NoOf iterations
\t\t\t\t\t\t\t\t\t act.fct="logistic", linear.output = FALSE)
fit_model2 <- nnet(Species ~ . , data=cb.train,
\t\t\t\t\t\t\t\t\t size=5, maxit=1000,
\t\t\t\t\t\t\t\t\t decay=0.0005, rang=0.1)\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t
fit_model2 %>% summary()
fit_model2 %>% plot.nnet()
fit_model2 %>% garson()