# gizai:ml/data

the data (row-major f64 matrices), the estimators and the model that the other parts share.

```gizlang
import * as Data from "gizai:ml/data";
```

## Types

### `Data`

```gizlang
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`: `i64`
- `features`: `i64`
- `x`: `Vec<f64>`
- `targets`: `i64`
- `y`: `Vec<f64>`

### `Split`

```gizlang
type Split = { train: Data; validation: Data; }
```

Two disjoint copies of one dataset, preserving each row's feature/target pairing.

- `train`: `M37.Data`
- `validation`: `M37.Data`

## Functions

### `tabular`

```gizlang
function tabular(features: Vec<Vec<f64>>, targets: Vec<Vec<f64>> = []): Data throws string
```

Build 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`

```gizlang
function param(h: Json, key: string): Option<Json>
```

The hyperparameter `key` of `h`, if set.

Effects: fail.

### `number`

```gizlang
function number(h: Json, key: string, d: f64): f64
```

The number under `key` in the hyperparameters `h`, else `d`.

Effects: fail.

### `integer`

```gizlang
function integer(h: Json, key: string, d: i64): i64
```

The integer under `key` in the hyperparameters `h`, else `d`.

Effects: fail.

### `text`

```gizlang
function text(h: Json, key: string, d: string): string
```

The text under `key` in the hyperparameters `h`, else `d`.

Effects: fail.

### `flag`

```gizlang
function flag(h: Json, key: string, d: bool): bool
```

The boolean hyperparameter KEY of H, or D when H does not have it.

Effects: fail.

### `isNull`

```gizlang
function isNull(h: Json, key: string): bool
```

Whether the hyperparameter `key` of `h` is set to null.

Effects: fail.

### `maxFeatures`

```gizlang
function maxFeatures(h: Json, d: i64, fallback: string): i64
```

max_features: "sqrt", "log2", an int, a fraction, or null (all).

Effects: fail.

### `textual`

```gizlang
function textual(v: Json): bool
```

Whether `v` is a JSON string.

### `column`

```gizlang
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`

```gizlang
function Data.validate(self: Data, task: string): bool throws string
```

Validate the physical data contract before any algorithm indexes a row.

Effects: fail.

### `Data.split`

```gizlang
function Data.split(self: Data, validationRows: i64, seed: u64): Split throws string
```

Deterministic 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`

```gizlang
function Data.folds(self: Data, k: i64, seed: u64): Vec<Split> throws string
```

K 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`

```gizlang
function Data.stratifiedFolds(self: Data, k: i64, seed: u64): Vec<Split> throws string
```

Stratified 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`

```gizlang
function Model.predictChecked(self: Model, row: Vec<f64>): Vec<f64> throws string
```

Safe single-row inference. Use this at untrusted API and file boundaries.

Effects: fail.

### `Model.predictRowsChecked`

```gizlang
function Model.predictRowsChecked(self: Model, x: Vec<f64>, rows: i64): Vec<f64> throws string
```

Safe inference of a row-major batch without a database.

Effects: fail.

### `Model.probaChecked`

```gizlang
function Model.probaChecked(self: Model, row: Vec<f64>): Vec<f64> throws string
```

Safe probability inference for one row.

Effects: fail.

### `Model.outputs`

```gizlang
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`

```gizlang
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`

```gizlang
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`

```gizlang
function Model.probaRows(self: Model, x: Vec<f64>, n: i64): Vec<f64> throws string
```

The class probabilities of `n` rows of `x`, one row after another, on all threads.

Effects: fail.

### `Model.proba`

```gizlang
function Model.proba(self: Model, row: Vec<f64>): Vec<f64> throws string
```

The probability of each class, in the order of the classes.

Effects: fail.

## Constants

### `ML_FORMAT`

```gizlang
const ML_FORMAT = 1
```

The version of the model file format.

