Java Code Examples for org.deeplearning4j.nn.multilayer.MultiLayerNetwork#evaluateRegression()
The following examples show how to use
org.deeplearning4j.nn.multilayer.MultiLayerNetwork#evaluateRegression() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegressionEvalTest.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Test public void testRegressionEvalMethods() { //Basic sanity check MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.ZERO).list() .layer(0, new OutputLayer.Builder().activation(Activation.TANH) .lossFunction(LossFunctions.LossFunction.MSE).nIn(10).nOut(5).build()) .build(); MultiLayerNetwork net = new MultiLayerNetwork(conf); net.init(); INDArray f = Nd4j.zeros(4, 10); INDArray l = Nd4j.ones(4, 5); DataSet ds = new DataSet(f, l); DataSetIterator iter = new ExistingDataSetIterator(Collections.singletonList(ds)); org.nd4j.evaluation.regression.RegressionEvaluation re = net.evaluateRegression(iter); for (int i = 0; i < 5; i++) { assertEquals(1.0, re.meanSquaredError(i), 1e-6); assertEquals(1.0, re.meanAbsoluteError(i), 1e-6); } ComputationGraphConfiguration graphConf = new NeuralNetConfiguration.Builder().weightInit(WeightInit.ZERO).graphBuilder() .addInputs("in").addLayer("0", new OutputLayer.Builder() .lossFunction(LossFunctions.LossFunction.MSE) .activation(Activation.TANH).nIn(10).nOut(5).build(), "in") .setOutputs("0").build(); ComputationGraph cg = new ComputationGraph(graphConf); cg.init(); RegressionEvaluation re2 = cg.evaluateRegression(iter); for (int i = 0; i < 5; i++) { assertEquals(1.0, re2.meanSquaredError(i), 1e-6); assertEquals(1.0, re2.meanAbsoluteError(i), 1e-6); } }
Example 2
Source File: RegressionScoreFunction.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public double score(MultiLayerNetwork net, DataSetIterator iterator) { RegressionEvaluation e = net.evaluateRegression(iterator); return e.scoreForMetric(metric); }
Example 3
Source File: TestSetRegressionScoreFunction.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public double score(MultiLayerNetwork net, DataSetIterator iterator) { RegressionEvaluation e = net.evaluateRegression(iterator); return ScoreUtil.getScoreFromRegressionEval(e, regressionValue); }
Example 4
Source File: ScoreUtil.java From deeplearning4j with Apache License 2.0 | 2 votes |
/** * Score the given multi layer network * @param model the model to score * @param testSet the test set * @param regressionValue the regression function to use * @return the score from the given test set */ public static double score(MultiLayerNetwork model, DataSetIterator testSet, RegressionValue regressionValue) { RegressionEvaluation eval = model.evaluateRegression(testSet); return getScoreFromRegressionEval(eval, regressionValue); }