我相信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圖中有周期性的刺。
任何人都可以幫忙嗎?