gizai:ml/data
the data (row-major f64 matrices), the estimators and the model that the other parts share.
import * as Data from "gizai:ml/data";Types
Data
type Data = { rows: i64; features: i64; x: Vec<f64>; targets: i64; y: Vec<f64>; }A training set: rows × features in x, rows × targets in y (labels for classification, none for clustering).
rows:i64features:i64x:Vec<f64>targets:i64y:Vec<f64>
Split
type Split = { train: Data; validation: Data; }Two disjoint copies of one dataset, preserving each row's feature/target pairing.
train:M37.Datavalidation:M37.Data
Functions
tabular
function tabular(features: Vec<Vec<f64>>, targets: Vec<Vec<f64>> = []): Data throws stringBuild a row-major dataset without a database. Labels are optional for clustering or PCA. Every feature row and target row must have one consistent width.
Effects: fail.
param
function param(h: Json, key: string): Option<Json>The hyperparameter key of h, if set.
Effects: fail.
number
function number(h: Json, key: string, d: f64): f64The number under key in the hyperparameters h, else d.
Effects: fail.
integer
function integer(h: Json, key: string, d: i64): i64The integer under key in the hyperparameters h, else d.
Effects: fail.
text
function text(h: Json, key: string, d: string): stringThe text under key in the hyperparameters h, else d.
Effects: fail.
flag
function flag(h: Json, key: string, d: bool): boolThe boolean hyperparameter KEY of H, or D when H does not have it.
Effects: fail.
isNull
function isNull(h: Json, key: string): boolWhether the hyperparameter key of h is set to null.
Effects: fail.
maxFeatures
function maxFeatures(h: Json, d: i64, fallback: string): i64max_features: "sqrt", "log2", an int, a fraction, or null (all).
Effects: fail.
textual
function textual(v: Json): boolWhether v is a JSON string.
column
function column(y: Vec<f64>, n: i64, t: i64, j: i64): Vec<f64>Column j of the n by t row-major matrix y.
Effects: fail.
Methods
Data.validate
function Data.validate(self: Data, task: string): bool throws stringValidate the physical data contract before any algorithm indexes a row.
Effects: fail.
Data.split
function Data.split(self: Data, validationRows: i64, seed: u64): Split throws stringDeterministic shuffled holdout. Fit preprocessing on train, never on validation. For class-stratified or time-series splits, select rows in the caller instead.
Effects: fail.
Data.folds
function Data.folds(self: Data, k: i64, seed: u64): Vec<Split> throws stringK disjoint validation folds: each row appears in exactly one validation set. Each fold trains on the remaining rows; deterministic for a given seed.
Effects: fail.
Data.stratifiedFolds
function Data.stratifiedFolds(self: Data, k: i64, seed: u64): Vec<Split> throws stringStratified K-folds for classification: preserve class proportions in every fold. Require at least K examples per class to keep minority classes evaluable.
Effects: fail.
Model.predictChecked
function Model.predictChecked(self: Model, row: Vec<f64>): Vec<f64> throws stringSafe single-row inference. Use this at untrusted API and file boundaries.
Effects: fail.
Model.predictRowsChecked
function Model.predictRowsChecked(self: Model, x: Vec<f64>, rows: i64): Vec<f64> throws stringSafe inference of a row-major batch without a database.
Effects: fail.
Model.probaChecked
function Model.probaChecked(self: Model, row: Vec<f64>): Vec<f64> throws stringSafe probability inference for one row.
Effects: fail.
Model.outputs
function Model.outputs(self: Model, row: Vec<f64>): Vec<f64>The raw outputs of a row: the concatenation of the outputs of each part.
Effects: fail.
Model.predict
function Model.predict(self: Model, row: Vec<f64>): Vec<f64>The prediction of a row: each target (regression), the label (classification), the cluster (clustering), the components (decomposition).
Effects: fail.
Model.predictRows
function Model.predictRows(self: Model, x: Vec<f64>, n: i64): Vec<f64>The predictions of n rows of x (row-major, features wide), one row after another, on all threads.
Effects: fail.
Model.probaRows
function Model.probaRows(self: Model, x: Vec<f64>, n: i64): Vec<f64> throws stringThe class probabilities of n rows of x, one row after another, on all threads.
Effects: fail.
Model.proba
function Model.proba(self: Model, row: Vec<f64>): Vec<f64> throws stringThe probability of each class, in the order of the classes.
Effects: fail.
Constants
ML_FORMAT
const ML_FORMAT = 1The version of the model file format.