我已经使用r中的插入符号包成功创建了多层感知器模型。如何绘制神经网络模型?我的代码如下
ctrl <- trainControl(method="repeatedcv", number=10, repeats =5)
mlpMLFit <- train(demand ~ ., data = datatrain, method = "mlpML", trControl = ctrl, preProcess = c("center", "scale"), tuneLength = 20)
mlpMLFit
plot(mlpMLFit)
summary(mlpMLFit)
这不完全有效,因为示例中的mlpMLFit
是插入符号的train
对象。我认为一种好而安全的方法可能是使用最佳的调整参数再次拟合模型,例如:
library(caret)
library(mlbench)
data(BostonHousing)
ctrl <- trainControl(method="cv", number=4)
TG = expand.grid(layer1=2:4,layer2=2:4,layer3=2:4)
mlpMLFit <- train(medv ~ ., data = BostonHousing, method = "mlpML", trControl = ctrl, preProcess = c("center", "scale"), tuneGrid=TG)
我们使用mlp()
修改模型:
library(RSNNS)
library(devtools)
source_url('https://gist.githubusercontent.com/fawda123/7471137/raw/466c1474d0a505ff044412703516c34f1a4684a5/nnet_plot_update.r')
fit = mlp(x=model.matrix(medv ~ .,data=BostonHousing),
y=BostonHousing$medv,size=as.numeric(mlpMLFit$bestTune))
并且您可以使用here中描述的绘图功能:
library(devtools)
source_url('https://gist.githubusercontent.com/fawda123/7471137/raw/466c1474d0a505ff044412703516c34f1a4684a5/nnet_plot_update.r')
plot.nnet(fit)