Skip to content

metrics #

vtl.ml.metrics

Metrics compare tensor predictions with reference values. The module currently provides elementwise squared, absolute, and relative error tensors; their mean forms; and accuracy_score for elementwise-equal labels.

import vtl
import vtl.ml.metrics

predicted := vtl.from_1d[f64]([1.0, 3.0, 1.0, 2.0])!
expected := vtl.from_1d[f64]([1.0, 2.0, 1.0, 0.0])!
accuracy := metrics.accuracy_score(predicted, expected)!
mae := metrics.mean_absolute_error[f64](predicted, expected)!

accuracy_score compares corresponding tensor elements and returns the fraction that match. It expects class IDs or labels already represented in comparable tensors; it does not apply argmax to logits. Error functions compare corresponding numeric values. See metrics_test.v for executable examples and edge cases.

fn absolute_error #

@[inline]
fn absolute_error[T](y &vtl.Tensor[T], y_true &vtl.Tensor[T]) !&vtl.Tensor[T]

absolute_error exposes this operation as part of the public API.

fn accuracy_score #

fn accuracy_score[T](y_pred &vtl.Tensor[T], y_true &vtl.Tensor[T]) !f64

accuracy_score returns the proportion of correctly classified samples (as f64)

fn mean_absolute_error #

@[inline]
fn mean_absolute_error[T](y &vtl.Tensor[T], y_true &vtl.Tensor[T]) !T

mean_absolute_error exposes this operation as part of the public API.

fn mean_relative_error #

@[inline]
fn mean_relative_error[T](y &vtl.Tensor[T], y_true &vtl.Tensor[T]) !T

mean_relative_error exposes this operation as part of the public API.

fn mean_squared_error #

@[inline]
fn mean_squared_error[T](y &vtl.Tensor[T], y_true &vtl.Tensor[T]) !T

mean_squared_error exposes this operation as part of the public API.

fn relative_error #

@[inline]
fn relative_error[T](y &vtl.Tensor[T], y_true &vtl.Tensor[T]) !&vtl.Tensor[T]

relative_error exposes this operation as part of the public API.

fn squared_error #

@[inline]
fn squared_error[T](y &vtl.Tensor[T], y_true &vtl.Tensor[T]) !&vtl.Tensor[T]

squared_error exposes this operation as part of the public API.