Evaluation
Detailed evaluation guide — classification metrics, regression metrics, ROC curves, calibration, and multi-output evaluation
Evaluating a trained model provides quantitative measures of how well it is performing. Eclipse Deeplearning4j provides a comprehensive set of evaluation classes covering classification, binary classification, regression, ROC analysis, and calibration.
Package migration (beta4 → M2.1): All evaluation classes have moved from
org.deeplearning4j.evaltoorg.nd4j.evaluation. Update your imports accordingly. The classes in the old package are kept as deprecated wrappers.
Classification: Evaluation
org.nd4j.evaluation.classification.Evaluation is the primary class for evaluating multi-class classifiers, including time-series classifiers. It accumulates predictions and labels across multiple minibatches before computing metrics.
Running Evaluation
Shortcut — using model.evaluate():
import org.nd4j.evaluation.classification.Evaluation;
DataSetIterator testIter = /* your test data */;
// Most convenient: model handles iteration internally
Evaluation eval = model.evaluate(testIter);
System.out.println(eval.stats());Manual evaluation over minibatches:
Evaluation eval = new Evaluation(numClasses);
while (testIter.hasNext()) {
DataSet batch = testIter.next();
INDArray predictions = model.output(batch.getFeatures(), false);
eval.eval(batch.getLabels(), predictions);
}
testIter.reset();
System.out.println(eval.stats());Available Metrics
Confusion Matrix
Example eval.stats() output:
Averaging Modes
Metrics that aggregate across classes support two averaging modes:
Macro (default)
Unweighted mean across all classes — treats each class equally.
Micro
Compute metric globally by counting total TPs, FPs, FNs across all classes. Appropriate for imbalanced datasets.
Binary Classification: EvaluationBinary
org.nd4j.evaluation.classification.EvaluationBinary is for networks with multiple binary outputs — typically with Sigmoid activation and binary cross-entropy loss. It computes the full set of classification metrics independently for each output.
Or using model.evaluate():
Regression: RegressionEvaluation
org.nd4j.evaluation.regression.RegressionEvaluation computes standard regression metrics independently for each output column.
Or via shortcut:
The stats output reports per-column:
MSE
Mean Squared Error
MAE
Mean Absolute Error
RMSE
Root Mean Squared Error
RSE
Relative Squared Error
R^2
Coefficient of Determination
Access individual metrics programmatically:
ROC Curves
Three ROC classes cover different classification scenarios. All support two computation modes:
Exact (
new ROC()ornew ROC(0)) — exact AUROC/AUPRC calculation. Can require significant memory with very large datasets.Thresholded (
new ROC(numBins)) — approximate calculation using a fixed number of threshold bins. Constant memory. Recommended for large datasets.
ROC — Single Binary Label
For networks with a single binary output (single Sigmoid, or 2-class Softmax):
Or via shortcut:
ROCBinary — Multiple Binary Labels
For networks with multiple binary outputs (multiple Sigmoid neurons):
ROCMultiClass — Multi-class One-vs-All
For Softmax classifiers, computes ROC for each class using a one-versus-all strategy:
Or via shortcut:
Exporting ROC Charts to HTML
Calibration: EvaluationCalibration
org.nd4j.evaluation.classification.EvaluationCalibration analyses how well predicted probabilities align with actual outcome frequencies (calibration). A well-calibrated model that predicts 70% probability for a class should be correct roughly 70% of the time.
The calibration evaluator provides:
Reliability diagram (calibration curve) — predicted probability vs. actual frequency.
Residual histogram — distribution of prediction errors.
Probability histograms — overall and per-class.
Export all plots to HTML:
Performing Multiple Evaluations in One Pass
Running several evaluation types on the same test data requires only a single pass through the dataset when using model.doEvaluation(...):
This is significantly more efficient than iterating the dataset three separate times.
Time Series Evaluation
Evaluation of RNNs proceeds in the same way as feedforward networks. DL4J evaluates all (non-masked) time steps independently. A sequence of length 10 contributes 10 prediction–label pairs per example.
Mask arrays (marking padding time steps) are handled automatically when using the model shortcut methods:
When evaluating manually, pass the mask array to eval:
Multi-task Evaluation
For ComputationGraph networks with multiple outputs, use MultiTaskGraphEvaluation or evaluate each output head separately using model.doEvaluation() with explicit output indices:
Distributed (Spark) Evaluation
For Spark-distributed training, use evaluation methods on SparkDl4jMultiLayer or SparkComputationGraph:
Serialization
All evaluation objects implement IEvaluation and can be serialised to JSON or YAML for storage and later combination (e.g., collecting partial results from distributed workers):
API Reference
Evaluation
org.nd4j.evaluation.classification
EvaluationBinary
org.nd4j.evaluation.classification
ROC
org.nd4j.evaluation.classification
ROCBinary
org.nd4j.evaluation.classification
ROCMultiClass
org.nd4j.evaluation.classification
EvaluationCalibration
org.nd4j.evaluation.classification
RegressionEvaluation
org.nd4j.evaluation.regression
ConfusionMatrix
org.nd4j.evaluation.classification
EvaluationAveraging
org.nd4j.evaluation.classification
IEvaluation (interface)
org.nd4j.evaluation
EvaluationTools
org.deeplearning4j.evaluation
Last updated
Was this helpful?