Skip to content

Metrics d2absoluteerror score

github-actions[bot] edited this page Aug 22, 2026 · 23 revisions

D2AbsoluteError.Score

The fraction of absolute error explained — sklearn.metrics.d2_absolute_error_score.

public static double Score(ReadOnlySpan<double> yTrue, ReadOnlySpan<double> yPred, int outputCount = 1, ReadOnlySpan<double> sampleWeight = default, ReadOnlySpan<double> outputWeights = default, ZeroDivision zeroDivision = ZeroDivision.NaN)

ParametersyTrue and yPred are the true and predicted values, row-major when there is more than one output. outputCount is how many outputs each row holds. sampleWeight is one weight per row — per sample, not per value. outputWeights is a weight per output, multioutput=[…]; omit it for multioutput="uniform_average". zeroDivision decides the answer for fewer than two samples.

Returnsdouble. 1 for a perfect prediction, 0 for one no better than always predicting the weighted median, and negative below that.

ExceptionsArgumentException when a length disagrees with the shape, the input is empty, or it holds a non-finite value. ArgumentOutOfRangeException when outputCount is below one. UndefinedMetricException when there are fewer than two samples and zeroDivision is ZeroDivision.Throw.

Example — the worked case, and the same weights read differently.

using Lodestar.Metrics;

double[] truth = [1.0, 2.0, 3.0, 4.0];
double[] predicted = [1.5, 2.5, 2.0, 4.5];

double explained = D2AbsoluteError.Score(truth, predicted);  // => 0.375
using Lodestar.Metrics;

double[] truth = [1.0, 2.0, 3.0, 4.0];
double[] predicted = [1.5, 2.5, 2.0, 4.5];
double[] weights = [1.0, 2.0, 3.0, 4.0];

double weighted = D2AbsoluteError.Score(truth, predicted, 1, weights);  // => 0.1875

Weighting the later samples more halves the score, because the third prediction — the worst of the four — is where most of the weight now sits.

RemarksD2Pinball.Score at alpha: 0.5, asserted across the whole frozen corpus rather than on one pair, since the two reach their baseline through different code.

A truth that never varies answers 0 rather than raising: the reference masks that denominator here, where d2_tweedie_score divides by it — D2Tweedie.Score reproduces that side of the split.

Applies to — net10.0, netstandard2.0.

See alsoD2AbsoluteError.PerOutput, D2Pinball.Score, R2.Score, MeanAbsoluteError.Score, the Python equivalence table.

Lodestar

Project

Clone this wiki locally