GitHub
deepbox/ml

Pipelines & Model Selection

Estimator metadata, output control, composable pipelines, cross-validation, and search utilities.
Workflow orchestration
type Classifier
export type Classifier = Estimator & { /** * Fit the model to training data. * * @param X - Training features of shape (n_samples, n_features) * @param y - Training targets * @returns The fitted estimator */ fit(X: Tens…
Type for classification models.
type Clusterer
export type Clusterer = Estimator<void> & { /** * Fit the model to training data. * * @param X - Training data of shape (n_samples, n_features) * @param y - Ignored (exists for compatibility) * @returns The fitted estim…
Type for clustering models.
type Estimator
export type Estimator<FitParams = void> = { /** * Fit the model to training data. * * @param X - Training features of shape (n_samples, n_features) * @param y - Training targets (optional for unsupervised learning) * @p…
Base type for all estimators (models) in Deepbox.
type EstimatorTags
export type EstimatorTags = { /** Estimator type: "classifier", "regressor", "clusterer", "transformer", "outlier_detector" */ readonly estimatorType: "classifier" | "regressor" | "clusterer" | "transformer" | "outlier_…
Metadata tags describing estimator capabilities and requirements.
type OutlierDetector
export type OutlierDetector = Estimator<void> & { /** * Fit the model to training data. * * @param X - Training data of shape (n_samples, n_features) * @param y - Ignored (exists for compatibility) * @returns The fitted…
Type for outlier/anomaly detection models.
type OutputType
export type OutputType = "default" | "array";
Output format for estimator transform/predict results.
type Regressor
export type Regressor = Estimator & { /** * Fit the model to training data. * * @param X - Training features of shape (n_samples, n_features) * @param y - Training targets * @returns The fitted estimator */ fit(X: Tenso…
Type for regression models.
type Transformer
export type Transformer = Estimator<void> & { /** * Fit the model to training data. * * @param X - Training data of shape (n_samples, n_features) * @param y - Ignored (exists for compatibility) * @returns The fitted est…
Type for transformer models.
type PermutationImportanceResult
export type PermutationImportanceResult = { /** Mean importance for each feature (shape: [n_features]). */ readonly importancesMean: Tensor; /** Std deviation of importance for each feature (shape: [n_features]). */ rea…
Result of a permutation importance computation.
type CrossValidateResult
export type CrossValidateResult = { /** Array of test scores per fold for each scoring metric */ readonly testScores: Record<string, number[]>; /** Array of fit times per fold (ms) */ readonly fitTime: number[]; /** Arr…
Result of cross_validate().
type GridSearchResult
export type GridSearchResult = { readonly params: Record<string, unknown>; readonly meanScore: number; readonly scores: number[]; };
Result of a single parameter combination evaluation

GridSearchCV

Exhaustive search over specified parameter values for an estimator.

RandomizedSearchCV

Randomized search over parameter distributions.

OneVsOneClassifier

One-vs-One (OvO) multiclass strategy.

OneVsRestClassifier

One-vs-Rest (OvR) multiclass strategy.

ColumnTransformer

ColumnTransformer applies transformers to specific column subsets of the data.

FeatureUnion

Concatenate results of multiple transformer objects.

Pipeline

Pipeline of transforms with a final estimator.

assertEstimator
export declare function assertEstimator<T extends Estimator>(value: T): T;

Runtime helper to validate estimator-like objects.

get_output
export declare function get_output(): OutputType;

Get the current global output type setting.

getEstimatorTags
export declare function getEstimatorTags(estimator: Estimator): EstimatorTags;

Get estimator tags from an estimator, using sensible defaults based on the estimator's interface.

reset_output
export declare function reset_output(): void;

Reset the output type to default (Tensor).

set_output
export declare function set_output(outputType: OutputType): void;

Set the global output type for all estimators.

permutationImportance
export declare function permutationImportance(estimator: Scorable, X: Tensor, y: Tensor, options?: { readonly nRepeats?: number; readonly randomState?: number; }): PermutationImportanceResult;

Permutation feature importance.

cross_val_score
export declare function cross_val_score(estimator: Estimator, X: Tensor, y: Tensor, cv?: number): number[];

Evaluate an estimator using cross-validation.

cross_validate
export declare function cross_validate(estimator: Estimator, X: Tensor, y: Tensor, options?: { cv?: number; scoring?: Record<string, (est: Estimator, X: Tensor, y: Tensor) => number> | ((est: Estimator, X: Tensor, y: Tensor) => number); }): CrossValidateResult;

Evaluate an estimator using cross-validation with multiple metrics.

makePipeline
export declare function makePipeline(...estimators: Array<Estimator | Transformer>): Pipeline;

Convenience factory for creating a Pipeline with auto-generated step names.

ml-model-selection.ts
import {  GridSearchCV,  Pipeline,  cross_validate,  permutationImportance,} from "deepbox/ml";import { LogisticRegression } from "deepbox/ml";import { tensor } from "deepbox/ndarray";import { StandardScaler } from "deepbox/preprocess";const X = tensor([[1], [2], [3], [4], [5], [6]]);const y = tensor([0, 0, 0, 1, 1, 1]);const pipeline = new Pipeline([  ["scaler", new StandardScaler()],  ["model", new LogisticRegression()],]);console.log(cross_validate(pipeline, X, y, { cv: 3 }));console.log(  new GridSearchCV(new LogisticRegression(), { maxIter: [50, 100] }, { cv: 3 }).fit(X, y).bestParams);console.log(permutationImportance(new LogisticRegression().fit(X, y), X, y));