For the complete documentation index, see llms.txt. This page is also available as Markdown.

Evaluation

Evaluating model performance — classification metrics, ROC curves, regression metrics, and evaluation during training

Evaluating model performance is essential for understanding whether your network is learning and for comparing different configurations. DL4J provides a comprehensive set of evaluation classes.

Migration note (beta4 → M2.1): All evaluation classes moved from org.deeplearning4j.eval to org.nd4j.evaluation. If upgrading from beta4, update your imports.

Classification: Evaluation

The primary evaluation class for multi-class classification tasks. Located at org.nd4j.evaluation.classification.Evaluation.

Running Evaluation

import org.nd4j.evaluation.classification.Evaluation;

// Option 1: Evaluate directly from a model
Evaluation eval = model.evaluate(testIter);
System.out.println(eval.stats());

// Option 2: Evaluate manually
Evaluation eval = new Evaluation(numClasses);
while (testIter.hasNext()) {
    DataSet batch = testIter.next();
    INDArray predictions = model.output(batch.getFeatures());
    eval.eval(batch.getLabels(), predictions);
}
testIter.reset();
System.out.println(eval.stats());

Available Metrics

The eval.stats() output looks like:

Averaging Methods

By default, metrics are macro-averaged (average per-class metrics equally). You can also get:

Binary Classification: EvaluationBinary

For multi-label binary classification where each output is an independent binary decision (sigmoid outputs):

ROC Curves

ROC (Receiver Operating Characteristic) curves measure the trade-off between true positive rate and false positive rate at various classification thresholds.

Binary ROC

Multi-Class ROC

Computes one ROC curve per class (one-vs-all):

Multi-Label Binary ROC

For multi-label tasks (multiple independent binary outputs):

Regression: RegressionEvaluation

For regression tasks (continuous output values):

Calibration: EvaluationCalibration

Measures how well predicted probabilities match actual frequencies. Useful for assessing whether a model's softmax outputs are reliable as confidence scores.

Evaluation During Training

Using EvaluativeListener

Run evaluation automatically at the end of each epoch:

The EvaluativeListener prints evaluation metrics after every N epochs (or iterations).

Manual Evaluation in the Training Loop

For more control, evaluate manually between epochs:

Evaluating ComputationGraph

ComputationGraph has the same evaluation methods:

For multi-output graphs, specify which output to evaluate:

Evaluating Recurrent Networks

For sequence-to-sequence tasks, evaluation works the same way but considers all time steps:

If your sequences have different lengths and you use masking, the evaluation automatically accounts for mask arrays — time steps where the mask is 0 are excluded from metrics.

Custom Evaluation

All evaluation classes implement the IEvaluation interface. You can run multiple evaluations in a single pass:

Quick Reference

Task
Evaluation Class
Key Metric

Multi-class classification

Evaluation

accuracy(), f1()

Multi-label binary

EvaluationBinary

per-output accuracy(), f1()

Binary ROC

ROC

calculateAUC()

Multi-class ROC

ROCMultiClass

calculateAverageAUC()

Regression

RegressionEvaluation

meanSquaredError(), rSquared()

Probability calibration

EvaluationCalibration

reliability diagram

Last updated

Was this helpful?