GizStack
View .mdOpen in ChatGPTOpen in Claude

gizai:ml/metrics

metrics of models.

gizlang
import * as Metrics from "gizai:ml/metrics";

Types

ClassMetrics

gizlang
type ClassMetrics = { f1: f64; f1Micro: f64; precision: f64; recall: f64; accuracy: f64; mcc: f64; }

The confusion metrics of PostgresML (src/metrics.rs): f1 macro, precision, recall and accuracy, f32; mcc as linfa's multiclass formula. y and yhat are labels rounded to integers.

  • f1: f64
  • f1Micro: f64
  • precision: f64
  • recall: f64
  • accuracy: f64
  • mcc: f64

Functions

sum32

gizlang
function sum32(v: Vec<f64>): f64

The f32 sum of ndarray (linfa's): eight running sums over blocks of eight, joined pairwise, then the rest in order.

Effects: fail.

r2

gizlang
function r2(y: Vec<f64>, yhat: Vec<f64>): f64

R², mean absolute and mean squared error in f32, as linfa computes them for PostgresML over the flattened targets.

Effects: fail.

meanAbsoluteError

gizlang
function meanAbsoluteError(y: Vec<f64>, yhat: Vec<f64>): f64

The mean of the absolute differences between y and yhat.

Effects: fail.

meanSquaredError

gizlang
function meanSquaredError(y: Vec<f64>, yhat: Vec<f64>): f64

The mean of the squared differences between y and yhat.

Effects: fail.

classMetrics

gizlang
function classMetrics(y: Vec<f64>, yhat: Vec<f64>, classes: i64): ClassMetrics throws string

The confusion metrics of predictions YHAT for labels Y of CLASSES classes. It fails when the lengths differ.

Effects: fail.

sklearnScores

gizlang
function sklearnScores(y: Vec<f64>, yhat: Vec<f64>): ClassMetrics throws string

scikit-learn's classification scores of PostgresML's sklearn_classification_metrics, in f32: f1, precision and recall of class 1 (average "binary") for at most two labels, else their mean over the labels (average "macro").

Effects: fail.

sklearnF1

gizlang
function sklearnF1(y: Vec<f64>, yhat: Vec<f64>): f64 throws string

scikit-learn's f1_score with average "binary": an error for more than two labels.

Effects: fail.

sklearnRocAuc

gizlang
function sklearnRocAuc(y: Vec<f64>, score: Vec<f64>): f64 throws string

scikit-learn's roc_auc_score of two classes, the larger one positive: the Mann-Whitney statistic, ties as halves.

Effects: fail.

sklearnRegression

gizlang
function sklearnRegression(y: Vec<f64>, yhat: Vec<f64>): Vec<f64>

scikit-learn's r2_score, mean_squared_error and mean_absolute_error, in f32: [r2, mse, mae]. A constant truth gives an r2 of 1 for an exact prediction, else 0.

Effects: fail.

rocAuc

gizlang
function rocAuc(y: Vec<f64>, score: Vec<f64>): f64

linfa's area under the ROC curve (PostgresML's roc_auc): the scores of 0 or more in ascending order, a point at each new score, the (tp, fp) rates of the points integrated by the trapezoid rule over tp, in f32.

Effects: fail.

logLoss

gizlang
function logLoss(y: Vec<f64>, p: Vec<f64>): f64

linfa's log loss: each probability clamped to [ε, 1 − ε] of f32, in f32.

Effects: fail.

silhouette

gizlang
function silhouette(x: Vec<f64>, n: i64, d: i64, labels: Vec<f64>): f64 throws string

The mean silhouette coefficient (Euclidean); 2 to n - 1 distinct labels.

Effects: fail.