apache mxnet 深度学习神经网络小试

http://mxnet.incubator.apache.org/versions/master/install/index.html?platform=Windows&language=R&processor=CPU

1 cran <- getOption("repos")
2 cran["dmlc"] <- "https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/R/CRAN/"
3 options(repos = cran)
4 install.packages("mxnet")

安装之前需要指定repository

一起安装的包

package ‘brew’ successfully unpacked and MD5 sums checked
package ‘hms’ successfully unpacked and MD5 sums checked
package ‘clipr’ successfully unpacked and MD5 sums checked
package ‘XML’ successfully unpacked and MD5 sums checked
package ‘Rook’ successfully unpacked and MD5 sums checked
package ‘downloader’ successfully unpacked and MD5 sums checked
package ‘igraph’ successfully unpacked and MD5 sums checked
package ‘influenceR’ successfully unpacked and MD5 sums checked
package ‘readr’ successfully unpacked and MD5 sums checked
package ‘rgexf’ successfully unpacked and MD5 sums checked
package ‘DiagrammeR’ successfully unpacked and MD5 sums checked
package ‘visNetwork’ successfully unpacked and MD5 sums checked
package ‘mxnet’ successfully unpacked and MD5 sums checked

额外的依赖

To run MXNet you also should have OpenCV and OpenBLAS installed.

第一步:数据准备

1 set.seed(0)
2 #随机分配训练集和测试集
3 train.ind = sample(1:nrow(inp), size=ceiling(0.7*nrow(inp)))
4 
5 train.x = data.matrix(inp[train.ind,NIRDATA])
6 train.y = inp[train.ind,NIC]
7 test.x = data.matrix(inp[-train.ind,NIRDATA])
8 test.y = inp[-train.ind,NIC]

第二步:创建网络并训练

1 mx.set.seed(0)
2 
3 model <- mx.mlp(train.x, train.y, hidden_node=c(7), out_node=1, out_activation="rmse",
4                 num.round=2000, array.batch.size=15, learning.rate=0.05, momentum=0.9,
5                 eval.metric=mx.metric.rmse)

hidden_node接受向量,c(100,50)代表两层隐含层,分别具有100和50个节点

out_node输出层

eval.metric=mx.metric.rmse
评估方法,rmse 标准差
评估测试集
predict(model,test.x)->prd

plot(prd,test.y)

猜你喜欢

转载自www.cnblogs.com/qianheng/p/10850162.html