我相信deeplearning4j和R完全相同的参数应该执行相同的可比较的MSE。但我不确定如何实现这一点。Deeplearning4j与R结果不同
我有一个csv文件,格式如下,其中包含46
变量和2
输出。完全有1,0000
样本。所有数据都进行了归一化处理,模型用于回归分析。
S1 | S2 | ... | S46 | X | Y
在R,我使用neuralnet
包,以及将码是:
rn <- colnames(traindata)
f <- as.formula(paste("X + Y ~", paste(rn[1:(length(rn)-2)], collapse="+")))
nn <- neuralnet(f,
rep=1,
data=traindata,
hidden=c(10),
linear.output=T,
threshold = 0.5)
这是相当简单的。
由于我想将算法整合到Java项目中,所以我认为dl4j来训练模型。火车组与R代码完全一样。测试集是随机选择的。的dl4j代码是:
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.seed(rngSeed) //include a random seed for reproducibility
// use stochastic gradient descent as an optimization algorithm
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.iterations(100)
.learningRate(0.0001) //specify the learning rate
.updater(Updater.NESTEROVS).momentum(0.9) //specify the rate of change of the learning rate.
.regularization(true).l2(0.0001)
.list()
.layer(0, new DenseLayer.Builder() //create the first, input layer with xavier initialization
.nIn(46)
.nOut(10)
.activation(Activation.TANH)
.weightInit(WeightInit.XAVIER)
.build())
.layer(1, new OutputLayer.Builder(LossFunctions.LossFunction.MSE) //create hidden layer
.nIn(10)
.nOut(outputNum)
.activation(Activation.IDENTITY)
.build())
.pretrain(false).backprop(true) //use backpropagation to adjust weights
.build();
时期的数量是10和batchsize是128
dl4j的mornitor是
由于存在dl4j如updater
,regulization
和weightInit
更多参数。所以我认为一些参数设置不正确。顺便说一句,为什么在mornitor图中有周期性的刺。
任何人都可以帮忙吗?