Skip to content

scikit-learn

scikit-learn β€” datasets, metrics, transforms and a train/predict model registry

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/scikit-learn/index.md to help me query scikit-learn with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Train a random forest and predict from SQL

Example output Β· captured
Connector release
v0.4.0
Engine
2.0.1
VGI protocol
3.4.0
SET VARIABLE iris_model = (SELECT model FROM sklearn.models.fit((SELECT * FROM sklearn.datasets.iris()), estimator := 'random_forest_classifier', target := 'target'));
SELECT sample_id, prediction FROM sklearn.models.predict((SELECT * FROM sklearn.datasets.iris()), model := getvariable('iris_model'), id := 'sample_id') LIMIT 5;
Result
sample_id prediction
0 0
1 0
2 0
3 0
4 0

Quick start

Choose where to run scikit-learn, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'sklearn' AS sklearn (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-sklearn'
);

3. Run a query

query.sql
SET VARIABLE iris_model = (SELECT model FROM sklearn.models.fit((SELECT * FROM sklearn.datasets.iris()), estimator := 'random_forest_classifier', target := 'target'));
SELECT sample_id, prediction FROM sklearn.models.predict((SELECT * FROM sklearn.datasets.iris()), model := getvariable('iris_model'), id := 'sample_id') LIMIT 5;
More example queries β†’
Technical details
Verified connector release
v0.4.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'sklearn' AS sklearn (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-sklearn'
);

Overview

scikit-learn datasets, metrics, transforms, and a train/predict model registry for DuckDB/SQL

Catalog

Everything sklearn exposes once attached β€” read straight from the worker's released build.

sklearn 5 schemas
datasets 6 tables Β· 5 functions

scikit-learn toy datasets and synthetic generators as table functions.

Schema examples (1)
Example

Load the iris dataset

SELECT * FROM sklearn.datasets.iris() LIMIT 5;
Tables
breast_cancer 2 examples33 cols

569 tumour samples with 30 cell-nucleus measurements and a benign/malignant label.

Columns
sample_idnot null INTEGER
Row index within the dataset (0-based).
mean_radiusnot null DOUBLE
Feature: mean radius.
mean_texturenot null DOUBLE
Feature: mean texture.
mean_perimeternot null DOUBLE
Feature: mean perimeter.
mean_areanot null DOUBLE
Feature: mean area.
mean_smoothnessnot null DOUBLE
Feature: mean smoothness.
mean_compactnessnot null DOUBLE
Feature: mean compactness.
mean_concavitynot null DOUBLE
Feature: mean concavity.
mean_concave_pointsnot null DOUBLE
Feature: mean concave points.
mean_symmetrynot null DOUBLE
Feature: mean symmetry.
mean_fractal_dimensionnot null DOUBLE
Feature: mean fractal dimension.
radius_errornot null DOUBLE
Feature: radius error.
texture_errornot null DOUBLE
Feature: texture error.
perimeter_errornot null DOUBLE
Feature: perimeter error.
area_errornot null DOUBLE
Feature: area error.
smoothness_errornot null DOUBLE
Feature: smoothness error.
compactness_errornot null DOUBLE
Feature: compactness error.
concavity_errornot null DOUBLE
Feature: concavity error.
concave_points_errornot null DOUBLE
Feature: concave points error.
symmetry_errornot null DOUBLE
Feature: symmetry error.
fractal_dimension_errornot null DOUBLE
Feature: fractal dimension error.
worst_radiusnot null DOUBLE
Feature: worst radius.
worst_texturenot null DOUBLE
Feature: worst texture.
worst_perimeternot null DOUBLE
Feature: worst perimeter.
worst_areanot null DOUBLE
Feature: worst area.
worst_smoothnessnot null DOUBLE
Feature: worst smoothness.
worst_compactnessnot null DOUBLE
Feature: worst compactness.
worst_concavitynot null DOUBLE
Feature: worst concavity.
worst_concave_pointsnot null DOUBLE
Feature: worst concave points.
worst_symmetrynot null DOUBLE
Feature: worst symmetry.
worst_fractal_dimensionnot null DOUBLE
Feature: worst fractal dimension.
targetnot null INTEGER
Integer class label.
target_namenot null VARCHAR
Human-readable class name (one of: malignant, benign).
ConstraintsPRIMARY KEY (sample_id)
Examples (2)

Class balance

SELECT target_name, count(*)
FROM sklearn.datasets.breast_cancer
GROUP BY target_name;
SELECT target_name, avg(mean_radius) AS mean_radius
FROM sklearn.datasets.breast_cancer()
GROUP BY target_name;
Link
california_housing 2 examples10 cols

20640 census block groups with 8 features and the median house value (regression).

Columns
sample_idnot null INTEGER
Row index within the dataset (0-based).
medincnot null DOUBLE
Feature: MedInc.
houseagenot null DOUBLE
Feature: HouseAge.
averoomsnot null DOUBLE
Feature: AveRooms.
avebedrmsnot null DOUBLE
Feature: AveBedrms.
populationnot null DOUBLE
Feature: Population.
aveoccupnot null DOUBLE
Feature: AveOccup.
latitudenot null DOUBLE
Feature: Latitude.
longitudenot null DOUBLE
Feature: Longitude.
targetnot null DOUBLE
Continuous regression target.
ConstraintsPRIMARY KEY (sample_id)
Examples (2)

Average value by latitude band

SELECT round(latitude) AS lat, round(avg(target), 2)
FROM sklearn.datasets.california_housing
GROUP BY lat
ORDER BY lat;
SELECT sample_id, medinc, target
FROM sklearn.datasets.california_housing()
WHERE target >= 5;
Link
diabetes 2 examples12 cols

442 patients with 10 baseline measurements and a one-year disease-progression score.

Columns
sample_idnot null INTEGER
Row index within the dataset (0-based).
agenot null DOUBLE
Feature: age.
sexnot null DOUBLE
Feature: sex.
bminot null DOUBLE
Feature: bmi.
bpnot null DOUBLE
Feature: bp.
s1not null DOUBLE
Feature: s1.
s2not null DOUBLE
Feature: s2.
s3not null DOUBLE
Feature: s3.
s4not null DOUBLE
Feature: s4.
s5not null DOUBLE
Feature: s5.
s6not null DOUBLE
Feature: s6.
targetnot null DOUBLE
Continuous regression target.
ConstraintsPRIMARY KEY (sample_id)
Examples (2)

Target range

SELECT min(target), max(target), round(avg(target), 1)
FROM sklearn.datasets.diabetes;
SELECT sample_id, bmi, target
FROM sklearn.datasets.diabetes()
WHERE target > 250;
Link
digits 2 examples67 cols

1797 handwritten digits as 64 pixel-intensity features (8x8) plus the digit label.

Columns
sample_idnot null INTEGER
Row index within the dataset (0-based).
pixel_0_0not null DOUBLE
Feature: pixel_0_0.
pixel_0_1not null DOUBLE
Feature: pixel_0_1.
pixel_0_2not null DOUBLE
Feature: pixel_0_2.
pixel_0_3not null DOUBLE
Feature: pixel_0_3.
pixel_0_4not null DOUBLE
Feature: pixel_0_4.
pixel_0_5not null DOUBLE
Feature: pixel_0_5.
pixel_0_6not null DOUBLE
Feature: pixel_0_6.
pixel_0_7not null DOUBLE
Feature: pixel_0_7.
pixel_1_0not null DOUBLE
Feature: pixel_1_0.
pixel_1_1not null DOUBLE
Feature: pixel_1_1.
pixel_1_2not null DOUBLE
Feature: pixel_1_2.
pixel_1_3not null DOUBLE
Feature: pixel_1_3.
pixel_1_4not null DOUBLE
Feature: pixel_1_4.
pixel_1_5not null DOUBLE
Feature: pixel_1_5.
pixel_1_6not null DOUBLE
Feature: pixel_1_6.
pixel_1_7not null DOUBLE
Feature: pixel_1_7.
pixel_2_0not null DOUBLE
Feature: pixel_2_0.
pixel_2_1not null DOUBLE
Feature: pixel_2_1.
pixel_2_2not null DOUBLE
Feature: pixel_2_2.
pixel_2_3not null DOUBLE
Feature: pixel_2_3.
pixel_2_4not null DOUBLE
Feature: pixel_2_4.
pixel_2_5not null DOUBLE
Feature: pixel_2_5.
pixel_2_6not null DOUBLE
Feature: pixel_2_6.
pixel_2_7not null DOUBLE
Feature: pixel_2_7.
pixel_3_0not null DOUBLE
Feature: pixel_3_0.
pixel_3_1not null DOUBLE
Feature: pixel_3_1.
pixel_3_2not null DOUBLE
Feature: pixel_3_2.
pixel_3_3not null DOUBLE
Feature: pixel_3_3.
pixel_3_4not null DOUBLE
Feature: pixel_3_4.
pixel_3_5not null DOUBLE
Feature: pixel_3_5.
pixel_3_6not null DOUBLE
Feature: pixel_3_6.
pixel_3_7not null DOUBLE
Feature: pixel_3_7.
pixel_4_0not null DOUBLE
Feature: pixel_4_0.
pixel_4_1not null DOUBLE
Feature: pixel_4_1.
pixel_4_2not null DOUBLE
Feature: pixel_4_2.
pixel_4_3not null DOUBLE
Feature: pixel_4_3.
pixel_4_4not null DOUBLE
Feature: pixel_4_4.
pixel_4_5not null DOUBLE
Feature: pixel_4_5.
pixel_4_6not null DOUBLE
Feature: pixel_4_6.
pixel_4_7not null DOUBLE
Feature: pixel_4_7.
pixel_5_0not null DOUBLE
Feature: pixel_5_0.
pixel_5_1not null DOUBLE
Feature: pixel_5_1.
pixel_5_2not null DOUBLE
Feature: pixel_5_2.
pixel_5_3not null DOUBLE
Feature: pixel_5_3.
pixel_5_4not null DOUBLE
Feature: pixel_5_4.
pixel_5_5not null DOUBLE
Feature: pixel_5_5.
pixel_5_6not null DOUBLE
Feature: pixel_5_6.
pixel_5_7not null DOUBLE
Feature: pixel_5_7.
pixel_6_0not null DOUBLE
Feature: pixel_6_0.
pixel_6_1not null DOUBLE
Feature: pixel_6_1.
pixel_6_2not null DOUBLE
Feature: pixel_6_2.
pixel_6_3not null DOUBLE
Feature: pixel_6_3.
pixel_6_4not null DOUBLE
Feature: pixel_6_4.
pixel_6_5not null DOUBLE
Feature: pixel_6_5.
pixel_6_6not null DOUBLE
Feature: pixel_6_6.
pixel_6_7not null DOUBLE
Feature: pixel_6_7.
pixel_7_0not null DOUBLE
Feature: pixel_7_0.
pixel_7_1not null DOUBLE
Feature: pixel_7_1.
pixel_7_2not null DOUBLE
Feature: pixel_7_2.
pixel_7_3not null DOUBLE
Feature: pixel_7_3.
pixel_7_4not null DOUBLE
Feature: pixel_7_4.
pixel_7_5not null DOUBLE
Feature: pixel_7_5.
pixel_7_6not null DOUBLE
Feature: pixel_7_6.
pixel_7_7not null DOUBLE
Feature: pixel_7_7.
targetnot null INTEGER
Integer class label.
target_namenot null VARCHAR
Human-readable class name (one of: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9).
ConstraintsPRIMARY KEY (sample_id)
Examples (2)

Images per digit

SELECT target, count(*)
FROM sklearn.datasets.digits
GROUP BY target
ORDER BY target;
SELECT target, count(*) AS n_images
FROM sklearn.datasets.digits()
GROUP BY target
ORDER BY target;
Link
iris 3 examples7 cols

150 iris flowers with four sepal/petal measurements (cm) and their species.

Columns
sample_idnot null INTEGER
Row index within the dataset (0-based).
sepal_length_cmnot null DOUBLE
Feature: sepal length (cm).
sepal_width_cmnot null DOUBLE
Feature: sepal width (cm).
petal_length_cmnot null DOUBLE
Feature: petal length (cm).
petal_width_cmnot null DOUBLE
Feature: petal width (cm).
targetnot null INTEGER
Integer class label.
target_namenot null VARCHAR
Human-readable class name (one of: setosa, versicolor, virginica).
ConstraintsPRIMARY KEY (sample_id)
Examples (3)

Row count per species

SELECT target_name, count(*)
FROM sklearn.datasets.iris
GROUP BY target_name;
SELECT sample_id, petal_length_cm, target_name
FROM sklearn.datasets.iris()
WHERE petal_length_cm > 5;
SELECT target_name, avg(petal_length_cm)
FROM sklearn.datasets.iris()
GROUP BY target_name;
Link
wine 2 examples16 cols

178 wines with 13 chemical measurements and their cultivar of origin.

Columns
sample_idnot null INTEGER
Row index within the dataset (0-based).
alcoholnot null DOUBLE
Feature: alcohol.
malic_acidnot null DOUBLE
Feature: malic_acid.
ashnot null DOUBLE
Feature: ash.
alcalinity_of_ashnot null DOUBLE
Feature: alcalinity_of_ash.
magnesiumnot null DOUBLE
Feature: magnesium.
total_phenolsnot null DOUBLE
Feature: total_phenols.
flavanoidsnot null DOUBLE
Feature: flavanoids.
nonflavanoid_phenolsnot null DOUBLE
Feature: nonflavanoid_phenols.
proanthocyaninsnot null DOUBLE
Feature: proanthocyanins.
color_intensitynot null DOUBLE
Feature: color_intensity.
huenot null DOUBLE
Feature: hue.
od280_od315_of_diluted_winesnot null DOUBLE
Feature: od280/od315_of_diluted_wines.
prolinenot null DOUBLE
Feature: proline.
targetnot null INTEGER
Integer class label.
target_namenot null VARCHAR
Human-readable class name (one of: class_0, class_1, class_2).
ConstraintsPRIMARY KEY (sample_id)
Examples (2)

Average alcohol per cultivar

SELECT target_name, round(avg(alcohol), 2)
FROM sklearn.datasets.wine
GROUP BY target_name;
SELECT target_name, avg(alcohol) AS mean_alcohol
FROM sklearn.datasets.wine()
GROUP BY target_name;
Link
Table functions
make_blobs (centers := BIGINT, cluster_std := DOUBLE, n_features := BIGINT, n_samples := BIGINT, random_state := BIGINT) 1 example

Generate Gaussian blobs for clustering

Named arguments
centers := BIGINT
Number of cluster centers. Β· default 3
cluster_std := DOUBLE
Std-dev of the clusters. Β· default 1.0
n_features := BIGINT
Number of features per sample. Β· default 2
n_samples := BIGINT
Number of samples to generate. Β· default 100
random_state := BIGINT
Random seed for reproducibility. Β· default 0
Returns columns
sample_id INTEGER
Row index within the generated sample (0-based).
cluster INTEGER
Ground-truth cluster index.
Returns columns Β· depends on the arguments
sample_id INTEGER
Row index within the generated sample (0-based).
cluster INTEGER
Ground-truth cluster index.
Example

300 points in 4 clusters

SELECT cluster, avg(feature_0) AS x, avg(feature_1) AS y
FROM sklearn.datasets.make_blobs(n_samples => 300, centers => 4)
GROUP BY cluster;
Link
make_circles (n_samples := BIGINT, noise := DOUBLE, random_state := BIGINT) 1 example

Generate two concentric circles (2 features, binary)

Named arguments
n_samples := BIGINT
Number of samples to generate. Β· default 100
noise := DOUBLE
Std-dev of gaussian noise added to the data. Β· default 0.1
random_state := BIGINT
Random seed for reproducibility. Β· default 0
Returns columns
sample_id INTEGER
Row index within the generated sample (0-based).
feature_0 DOUBLE
Feature: feature_0.
feature_1 DOUBLE
Feature: feature_1.
target INTEGER
Binary class label (0 or 1).
Example

200 points in two concentric rings

SELECT target,
  avg(sqrt(feature_0 * feature_0 + feature_1 * feature_1)) AS mean_radius
FROM sklearn.datasets.make_circles(n_samples => 200, noise => 0.05)
GROUP BY target;
Link
make_classification (n_classes := BIGINT, n_features := BIGINT, n_informative := BIGINT, n_samples := BIGINT, random_state := BIGINT) 1 example

Generate a synthetic classification dataset

Named arguments
n_classes := BIGINT
Number of target classes. Β· default 2
n_features := BIGINT
Total number of features. Β· default 20
n_informative := BIGINT
Number of informative features. Β· default 2
n_samples := BIGINT
Number of samples to generate. Β· default 100
random_state := BIGINT
Random seed for reproducibility. Β· default 0
Returns columns
sample_id INTEGER
Row index within the generated sample (0-based).
target INTEGER
Integer class label.
Returns columns Β· depends on the arguments
sample_id INTEGER
Row index within the generated sample (0-based).
target INTEGER
Integer class label.
Example

500 rows, 5 features, 3 classes

SELECT target, count(*) AS n
FROM sklearn.datasets.make_classification(n_samples => 500, n_features => 5, n_classes => 3)
GROUP BY target;
Link
make_moons (n_samples := BIGINT, noise := DOUBLE, random_state := BIGINT) 1 example

Generate two interleaving half-moons (2 features, binary)

Named arguments
n_samples := BIGINT
Number of samples to generate. Β· default 100
noise := DOUBLE
Std-dev of gaussian noise added to the data. Β· default 0.1
random_state := BIGINT
Random seed for reproducibility. Β· default 0
Returns columns
sample_id INTEGER
Row index within the generated sample (0-based).
feature_0 DOUBLE
Feature: feature_0.
feature_1 DOUBLE
Feature: feature_1.
target INTEGER
Binary class label (0 or 1).
Example

200 points in a two-moon shape

SELECT target, count(*) AS n
FROM sklearn.datasets.make_moons(n_samples => 200, noise => 0.1)
GROUP BY target;
Link
make_regression (n_features := BIGINT, n_informative := BIGINT, n_samples := BIGINT, noise := DOUBLE, random_state := BIGINT) 1 example

Generate a synthetic regression dataset

Named arguments
n_features := BIGINT
Total number of features. Β· default 20
n_informative := BIGINT
Number of informative features. Β· default 10
n_samples := BIGINT
Number of samples to generate. Β· default 100
noise := DOUBLE
Std-dev of gaussian noise on the output. Β· default 0.0
random_state := BIGINT
Random seed for reproducibility. Β· default 0
Returns columns
sample_id INTEGER
Row index within the generated sample (0-based).
target DOUBLE
Continuous regression target.
Returns columns Β· depends on the arguments
sample_id INTEGER
Row index within the generated sample (0-based).
target DOUBLE
Continuous regression target.
Example

500 rows, 4 features, noisy target

SELECT corr(feature_0, target) AS r
FROM sklearn.datasets.make_regression(n_samples => 500, n_features => 4, noise => 5.0);
Link
estimators 42 functions

Typed fit_ functions with named, documented hyperparameters.

Schema examples (1)
Example

Fit a logistic-regression classifier on iris

SELECT n_samples, n_features
FROM sklearn.estimators.fit_logistic_regression((SELECT * FROM sklearn.datasets.iris()), target := 'target');
Table in-out functions
fit_ada_boost_classifier (data TABLE, id := VARCHAR, learning_rate := DOUBLE, model_name := VARCHAR, n_estimators := BIGINT, random_state := BIGINT, target := VARCHAR) 1 example

Fit a ada_boost_classifier with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
learning_rate := DOUBLE
Weight applied to each classifier. Β· default 1.0
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_estimators := BIGINT
Number of boosting stages. Β· default 50
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a ada_boost_classifier with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_ada_boost_classifier((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', n_estimators := 50, learning_rate := 1.0);
Link
fit_ada_boost_regressor (data TABLE, id := VARCHAR, learning_rate := DOUBLE, model_name := VARCHAR, n_estimators := BIGINT, random_state := BIGINT, target := VARCHAR) 1 example

Fit a ada_boost_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
learning_rate := DOUBLE
Weight applied to each regressor. Β· default 1.0
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_estimators := BIGINT
Number of boosting stages. Β· default 50
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a ada_boost_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_ada_boost_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', n_estimators := 50, learning_rate := 1.0);
Link
fit_bagging_classifier (data TABLE, id := VARCHAR, max_features := DOUBLE, max_samples := DOUBLE, model_name := VARCHAR, n_estimators := BIGINT, random_state := BIGINT, target := VARCHAR) 1 example

Fit a bagging_classifier with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
max_features := DOUBLE
Fraction of features per base estimator. Β· default 1.0
max_samples := DOUBLE
Fraction of samples per base estimator. Β· default 1.0
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_estimators := BIGINT
Number of base estimators. Β· default 10
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a bagging_classifier with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_bagging_classifier((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', n_estimators := 10, max_samples := 1.0);
Link
fit_bagging_regressor (data TABLE, id := VARCHAR, max_features := DOUBLE, max_samples := DOUBLE, model_name := VARCHAR, n_estimators := BIGINT, random_state := BIGINT, target := VARCHAR) 1 example

Fit a bagging_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
max_features := DOUBLE
Fraction of features per base estimator. Β· default 1.0
max_samples := DOUBLE
Fraction of samples per base estimator. Β· default 1.0
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_estimators := BIGINT
Number of base estimators. Β· default 10
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a bagging_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_bagging_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', n_estimators := 10, max_samples := 1.0);
Link
fit_bayesian_ridge (data TABLE, alpha_1 := DOUBLE, fit_intercept := BOOLEAN, id := VARCHAR, lambda_1 := DOUBLE, model_name := VARCHAR, target := VARCHAR) 1 example

Fit a bayesian_ridge with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha_1 := DOUBLE
Shape parameter for the alpha Gamma prior. Β· default 1e-06
fit_intercept := BOOLEAN
Whether to fit an intercept. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
lambda_1 := DOUBLE
Shape parameter for the lambda Gamma prior. Β· default 1e-06
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a bayesian_ridge with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_bayesian_ridge((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', alpha_1 := 1e-06, lambda_1 := 1e-06);
Link
fit_bernoulli_nb (data TABLE, alpha := DOUBLE, binarize := DOUBLE, fit_prior := BOOLEAN, id := VARCHAR, model_name := VARCHAR, target := VARCHAR) 1 example

Fit a bernoulli_nb with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
Additive (Laplace) smoothing. Β· default 1.0
binarize := DOUBLE
Threshold for binarizing features. Β· default 0.0
fit_prior := BOOLEAN
Whether to learn class prior probabilities. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a bernoulli_nb with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_bernoulli_nb((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', alpha := 1.0, binarize := 0.0);
Link
fit_complement_nb (data TABLE, alpha := DOUBLE, fit_prior := BOOLEAN, id := VARCHAR, model_name := VARCHAR, norm := BOOLEAN, target := VARCHAR) 1 example

Fit a complement_nb with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
Additive (Laplace) smoothing. Β· default 1.0
fit_prior := BOOLEAN
Whether to learn class prior probabilities. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
norm := BOOLEAN
Whether to normalize the weights. Β· default false
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a complement_nb with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_complement_nb((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', alpha := 1.0, norm := False);
Link
fit_decision_tree_classifier (data TABLE, criterion := VARCHAR, id := VARCHAR, max_depth := BIGINT, min_samples_split := BIGINT, model_name := VARCHAR, random_state := BIGINT, target := VARCHAR) 1 example

Fit a decision_tree_classifier with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
criterion := VARCHAR
Split quality criterion. Β· default "gini"
id := VARCHAR
Optional id passthrough column. Β· default ""
max_depth := BIGINT
Max tree depth; 0 = unlimited. Β· default 0
min_samples_split := BIGINT
Min samples to split an internal node. Β· default 2
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a decision_tree_classifier with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_decision_tree_classifier((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', max_depth := 0, min_samples_split := 2);
Link
fit_decision_tree_regressor (data TABLE, criterion := VARCHAR, id := VARCHAR, max_depth := BIGINT, min_samples_split := BIGINT, model_name := VARCHAR, random_state := BIGINT, target := VARCHAR) 1 example

Fit a decision_tree_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
criterion := VARCHAR
Split quality criterion. Β· default "squared_error"
id := VARCHAR
Optional id passthrough column. Β· default ""
max_depth := BIGINT
Max tree depth; 0 = unlimited. Β· default 0
min_samples_split := BIGINT
Min samples to split an internal node. Β· default 2
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a decision_tree_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_decision_tree_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', max_depth := 0, min_samples_split := 2);
Link
fit_elastic_net (data TABLE, alpha := DOUBLE, fit_intercept := BOOLEAN, id := VARCHAR, l1_ratio := DOUBLE, max_iter := BIGINT, model_name := VARCHAR, target := VARCHAR) 1 example

Fit a elastic_net with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
Regularization strength. Β· default 1.0
fit_intercept := BOOLEAN
Whether to fit an intercept. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
l1_ratio := DOUBLE
Mix of L1/L2 (0=ridge, 1=lasso). Β· default 0.5
max_iter := BIGINT
Max iterations. Β· default 1000
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a elastic_net with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_elastic_net((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', alpha := 1.0, l1_ratio := 0.5);
Link
fit_extra_trees_classifier (data TABLE, id := VARCHAR, max_depth := BIGINT, max_features := VARCHAR, min_samples_split := BIGINT, model_name := VARCHAR, n_estimators := BIGINT, random_state := BIGINT, target := VARCHAR) 1 example

Fit a extra_trees_classifier with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
max_depth := BIGINT
Max tree depth; 0 = unlimited. Β· default 0
max_features := VARCHAR
Features considered per split. Β· default "sqrt"
min_samples_split := BIGINT
Min samples to split an internal node. Β· default 2
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_estimators := BIGINT
Number of trees. Β· default 100
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a extra_trees_classifier with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_extra_trees_classifier((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', n_estimators := 100, max_depth := 0);
Link
fit_extra_trees_regressor (data TABLE, id := VARCHAR, max_depth := BIGINT, max_features := VARCHAR, min_samples_split := BIGINT, model_name := VARCHAR, n_estimators := BIGINT, random_state := BIGINT, target := VARCHAR) 1 example

Fit a extra_trees_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
max_depth := BIGINT
Max tree depth; 0 = unlimited. Β· default 0
max_features := VARCHAR
Features considered per split. Β· default "sqrt"
min_samples_split := BIGINT
Min samples to split an internal node. Β· default 2
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_estimators := BIGINT
Number of trees. Β· default 100
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a extra_trees_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_extra_trees_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', n_estimators := 100, max_depth := 0);
Link
fit_gamma_regressor (data TABLE, alpha := DOUBLE, fit_intercept := BOOLEAN, id := VARCHAR, max_iter := BIGINT, model_name := VARCHAR, target := VARCHAR) 1 example

Fit a gamma_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
L2 regularization strength. Β· default 1.0
fit_intercept := BOOLEAN
Whether to fit an intercept. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
max_iter := BIGINT
Max solver iterations. Β· default 100
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a gamma_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_gamma_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', alpha := 1.0, max_iter := 100);
Link
fit_gaussian_nb (data TABLE, id := VARCHAR, model_name := VARCHAR, target := VARCHAR, var_smoothing := DOUBLE) 1 example

Fit a gaussian_nb with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
var_smoothing := DOUBLE
Variance smoothing added for stability. Β· default 1e-09
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a gaussian_nb with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_gaussian_nb((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', var_smoothing := 1e-09);
Link
fit_gradient_boosting_classifier (data TABLE, id := VARCHAR, learning_rate := DOUBLE, max_depth := BIGINT, model_name := VARCHAR, n_estimators := BIGINT, random_state := BIGINT, subsample := DOUBLE, target := VARCHAR) 1 example

Fit a gradient_boosting_classifier with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
learning_rate := DOUBLE
Shrinkage applied to each tree. Β· default 0.1
max_depth := BIGINT
Max depth of each tree. Β· default 3
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_estimators := BIGINT
Number of boosting stages. Β· default 100
random_state := BIGINT
Random seed. Β· default 0
subsample := DOUBLE
Fraction of samples per stage. Β· default 1.0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a gradient_boosting_classifier with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_gradient_boosting_classifier((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', n_estimators := 100, learning_rate := 0.1);
Link
fit_gradient_boosting_regressor (data TABLE, id := VARCHAR, learning_rate := DOUBLE, max_depth := BIGINT, model_name := VARCHAR, n_estimators := BIGINT, random_state := BIGINT, subsample := DOUBLE, target := VARCHAR) 1 example

Fit a gradient_boosting_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
learning_rate := DOUBLE
Shrinkage applied to each tree. Β· default 0.1
max_depth := BIGINT
Max depth of each tree. Β· default 3
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_estimators := BIGINT
Number of boosting stages. Β· default 100
random_state := BIGINT
Random seed. Β· default 0
subsample := DOUBLE
Fraction of samples per stage. Β· default 1.0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a gradient_boosting_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_gradient_boosting_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', n_estimators := 100, learning_rate := 0.1);
Link
fit_hist_gradient_boosting_classifier (data TABLE, id := VARCHAR, l2_regularization := DOUBLE, learning_rate := DOUBLE, max_depth := BIGINT, max_iter := BIGINT, model_name := VARCHAR, random_state := BIGINT, target := VARCHAR) 1 example

Fit a hist_gradient_boosting_classifier with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
l2_regularization := DOUBLE
L2 regularization. Β· default 0.0
learning_rate := DOUBLE
Shrinkage applied to each iteration. Β· default 0.1
max_depth := BIGINT
Max tree depth; 0 = unlimited. Β· default 0
max_iter := BIGINT
Number of boosting iterations. Β· default 100
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a hist_gradient_boosting_classifier with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_hist_gradient_boosting_classifier((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', max_iter := 100, learning_rate := 0.1);
Link
fit_hist_gradient_boosting_regressor (data TABLE, id := VARCHAR, l2_regularization := DOUBLE, learning_rate := DOUBLE, max_depth := BIGINT, max_iter := BIGINT, model_name := VARCHAR, random_state := BIGINT, target := VARCHAR) 1 example

Fit a hist_gradient_boosting_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
l2_regularization := DOUBLE
L2 regularization. Β· default 0.0
learning_rate := DOUBLE
Shrinkage applied to each iteration. Β· default 0.1
max_depth := BIGINT
Max tree depth; 0 = unlimited. Β· default 0
max_iter := BIGINT
Number of boosting iterations. Β· default 100
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a hist_gradient_boosting_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_hist_gradient_boosting_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', max_iter := 100, learning_rate := 0.1);
Link
fit_huber_regressor (data TABLE, alpha := DOUBLE, epsilon := DOUBLE, id := VARCHAR, max_iter := BIGINT, model_name := VARCHAR, target := VARCHAR) 1 example

Fit a huber_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
L2 regularization strength. Β· default 0.0001
epsilon := DOUBLE
Threshold above which samples are treated as outliers. Β· default 1.35
id := VARCHAR
Optional id passthrough column. Β· default ""
max_iter := BIGINT
Max iterations. Β· default 100
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a huber_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_huber_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', epsilon := 1.35, alpha := 0.0001);
Link
fit_knn_classifier (data TABLE, id := VARCHAR, model_name := VARCHAR, n_neighbors := BIGINT, p := BIGINT, target := VARCHAR, weights := VARCHAR) 1 example

Fit a knn_classifier with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_neighbors := BIGINT
Number of neighbours. Β· default 5
p := BIGINT
Minkowski power (1=manhattan, 2=euclidean). Β· default 2
target := VARCHAR
Label column name (required). Β· default ""
weights := VARCHAR
Neighbour weighting ('uniform' or 'distance'). Β· default "uniform"
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a knn_classifier with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_knn_classifier((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', n_neighbors := 5, weights := 'uniform');
Link
fit_knn_regressor (data TABLE, id := VARCHAR, model_name := VARCHAR, n_neighbors := BIGINT, p := BIGINT, target := VARCHAR, weights := VARCHAR) 1 example

Fit a knn_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_neighbors := BIGINT
Number of neighbours. Β· default 5
p := BIGINT
Minkowski power (1=manhattan, 2=euclidean). Β· default 2
target := VARCHAR
Label column name (required). Β· default ""
weights := VARCHAR
Neighbour weighting ('uniform' or 'distance'). Β· default "uniform"
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a knn_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_knn_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', n_neighbors := 5, weights := 'uniform');
Link
fit_lasso (data TABLE, alpha := DOUBLE, fit_intercept := BOOLEAN, id := VARCHAR, max_iter := BIGINT, model_name := VARCHAR, target := VARCHAR) 1 example

Fit a lasso with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
Regularization strength. Β· default 1.0
fit_intercept := BOOLEAN
Whether to fit an intercept. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
max_iter := BIGINT
Max iterations. Β· default 1000
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a lasso with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_lasso((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', alpha := 1.0, max_iter := 1000);
Link
fit_lda (data TABLE, id := VARCHAR, model_name := VARCHAR, solver := VARCHAR, target := VARCHAR, tol := DOUBLE) 1 example

Fit a lda with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
solver := VARCHAR
Solver. Β· default "svd"
target := VARCHAR
Label column name (required). Β· default ""
tol := DOUBLE
Threshold for rank estimation (svd). Β· default 0.0001
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a lda with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_lda((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', solver := 'svd', tol := 0.0001);
Link
fit_linear_regression (data TABLE, fit_intercept := BOOLEAN, id := VARCHAR, model_name := VARCHAR, target := VARCHAR) 1 example

Fit a linear_regression with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
fit_intercept := BOOLEAN
Whether to fit an intercept. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a linear_regression with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_linear_regression((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', fit_intercept := True);
Link
fit_linear_svc (data TABLE, C := DOUBLE, id := VARCHAR, loss := VARCHAR, max_iter := BIGINT, model_name := VARCHAR, random_state := BIGINT, target := VARCHAR) 1 example

Fit a linear_svc with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
C := DOUBLE
Regularization strength. Β· default 1.0
id := VARCHAR
Optional id passthrough column. Β· default ""
loss := VARCHAR
Loss function. Β· default "squared_hinge"
max_iter := BIGINT
Max iterations. Β· default 1000
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a linear_svc with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_linear_svc((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', C := 1.0, loss := 'squared_hinge');
Link
fit_linear_svr (data TABLE, C := DOUBLE, epsilon := DOUBLE, id := VARCHAR, max_iter := BIGINT, model_name := VARCHAR, random_state := BIGINT, target := VARCHAR) 1 example

Fit a linear_svr with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
C := DOUBLE
Regularization strength. Β· default 1.0
epsilon := DOUBLE
Epsilon in the epsilon-insensitive loss. Β· default 0.0
id := VARCHAR
Optional id passthrough column. Β· default ""
max_iter := BIGINT
Max iterations. Β· default 1000
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a linear_svr with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_linear_svr((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', C := 1.0, epsilon := 0.0);
Link
fit_logistic_regression (data TABLE, C := DOUBLE, id := VARCHAR, max_iter := BIGINT, model_name := VARCHAR, penalty := VARCHAR, solver := VARCHAR, target := VARCHAR) 1 example

Fit a logistic_regression with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
C := DOUBLE
Inverse regularization strength. Β· default 1.0
id := VARCHAR
Optional id passthrough column. Β· default ""
max_iter := BIGINT
Max solver iterations. Β· default 1000
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
penalty := VARCHAR
Regularization penalty. Β· default "l2"
solver := VARCHAR
Optimization solver. Β· default "lbfgs"
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a logistic_regression with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_logistic_regression((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', C := 1.0, max_iter := 1000);
Link
fit_mlp_classifier (data TABLE, alpha := DOUBLE, hidden_units := BIGINT, id := VARCHAR, learning_rate_init := DOUBLE, max_iter := BIGINT, model_name := VARCHAR, random_state := BIGINT, target := VARCHAR) 1 example

Fit a mlp_classifier with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
L2 penalty. Β· default 0.0001
hidden_units := BIGINT
Units in the single hidden layer. Β· default 100
id := VARCHAR
Optional id passthrough column. Β· default ""
learning_rate_init := DOUBLE
Initial learning rate. Β· default 0.001
max_iter := BIGINT
Max training iterations. Β· default 500
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a mlp_classifier with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_mlp_classifier((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', hidden_units := 100, alpha := 0.0001);
Link
fit_mlp_regressor (data TABLE, alpha := DOUBLE, hidden_units := BIGINT, id := VARCHAR, learning_rate_init := DOUBLE, max_iter := BIGINT, model_name := VARCHAR, random_state := BIGINT, target := VARCHAR) 1 example

Fit a mlp_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
L2 penalty. Β· default 0.0001
hidden_units := BIGINT
Units in the single hidden layer. Β· default 100
id := VARCHAR
Optional id passthrough column. Β· default ""
learning_rate_init := DOUBLE
Initial learning rate. Β· default 0.001
max_iter := BIGINT
Max training iterations. Β· default 500
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a mlp_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_mlp_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', hidden_units := 100, alpha := 0.0001);
Link
fit_multinomial_nb (data TABLE, alpha := DOUBLE, fit_prior := BOOLEAN, id := VARCHAR, model_name := VARCHAR, target := VARCHAR) 1 example

Fit a multinomial_nb with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
Additive (Laplace) smoothing. Β· default 1.0
fit_prior := BOOLEAN
Whether to learn class prior probabilities. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a multinomial_nb with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_multinomial_nb((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', alpha := 1.0, fit_prior := True);
Link
fit_poisson_regressor (data TABLE, alpha := DOUBLE, fit_intercept := BOOLEAN, id := VARCHAR, max_iter := BIGINT, model_name := VARCHAR, target := VARCHAR) 1 example

Fit a poisson_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
L2 regularization strength. Β· default 1.0
fit_intercept := BOOLEAN
Whether to fit an intercept. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
max_iter := BIGINT
Max solver iterations. Β· default 100
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a poisson_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_poisson_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', alpha := 1.0, max_iter := 100);
Link
fit_qda (data TABLE, id := VARCHAR, model_name := VARCHAR, reg_param := DOUBLE, target := VARCHAR, tol := DOUBLE) 1 example

Fit a qda with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
reg_param := DOUBLE
Regularization of the per-class covariance. Β· default 0.0
target := VARCHAR
Label column name (required). Β· default ""
tol := DOUBLE
Threshold for rank estimation. Β· default 0.0001
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a qda with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_qda((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', reg_param := 0.0, tol := 0.0001);
Link
fit_quantile_regressor (data TABLE, alpha := DOUBLE, fit_intercept := BOOLEAN, id := VARCHAR, model_name := VARCHAR, quantile := DOUBLE, target := VARCHAR) 1 example

Fit a quantile_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
L1 regularization strength. Β· default 1.0
fit_intercept := BOOLEAN
Whether to fit an intercept. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
quantile := DOUBLE
Quantile to predict, strictly between 0 and 1. Β· default 0.5
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a quantile_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_quantile_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', quantile := 0.5, alpha := 1.0);
Link
fit_random_forest_classifier (data TABLE, id := VARCHAR, max_depth := BIGINT, max_features := VARCHAR, min_samples_split := BIGINT, model_name := VARCHAR, n_estimators := BIGINT, random_state := BIGINT, target := VARCHAR) 1 example

Fit a random_forest_classifier with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
max_depth := BIGINT
Max tree depth; 0 = unlimited. Β· default 0
max_features := VARCHAR
Features considered per split. Β· default "sqrt"
min_samples_split := BIGINT
Min samples to split an internal node. Β· default 2
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_estimators := BIGINT
Number of trees. Β· default 100
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a random_forest_classifier with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_random_forest_classifier((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', n_estimators := 100, max_depth := 0);
Link
fit_random_forest_regressor (data TABLE, id := VARCHAR, max_depth := BIGINT, max_features := VARCHAR, min_samples_split := BIGINT, model_name := VARCHAR, n_estimators := BIGINT, random_state := BIGINT, target := VARCHAR) 1 example

Fit a random_forest_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
id := VARCHAR
Optional id passthrough column. Β· default ""
max_depth := BIGINT
Max tree depth; 0 = unlimited. Β· default 0
max_features := VARCHAR
Features considered per split. Β· default "sqrt"
min_samples_split := BIGINT
Min samples to split an internal node. Β· default 2
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
n_estimators := BIGINT
Number of trees. Β· default 100
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a random_forest_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_random_forest_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', n_estimators := 100, max_depth := 0);
Link
fit_ridge (data TABLE, alpha := DOUBLE, fit_intercept := BOOLEAN, id := VARCHAR, model_name := VARCHAR, solver := VARCHAR, target := VARCHAR) 1 example

Fit a ridge with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
Regularization strength. Β· default 1.0
fit_intercept := BOOLEAN
Whether to fit an intercept. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
solver := VARCHAR
Solver to use. Β· default "auto"
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a ridge with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_ridge((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', alpha := 1.0, fit_intercept := True);
Link
fit_ridge_classifier (data TABLE, alpha := DOUBLE, fit_intercept := BOOLEAN, id := VARCHAR, model_name := VARCHAR, solver := VARCHAR, target := VARCHAR) 1 example

Fit a ridge_classifier with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
Regularization strength. Β· default 1.0
fit_intercept := BOOLEAN
Whether to fit an intercept. Β· default true
id := VARCHAR
Optional id passthrough column. Β· default ""
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
solver := VARCHAR
Solver to use. Β· default "auto"
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a ridge_classifier with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_ridge_classifier((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', alpha := 1.0, fit_intercept := True);
Link
fit_sgd_classifier (data TABLE, alpha := DOUBLE, id := VARCHAR, loss := VARCHAR, max_iter := BIGINT, model_name := VARCHAR, penalty := VARCHAR, random_state := BIGINT, target := VARCHAR) 1 example

Fit a sgd_classifier with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
Regularization strength. Β· default 0.0001
id := VARCHAR
Optional id passthrough column. Β· default ""
loss := VARCHAR
Loss function. Β· default "hinge"
max_iter := BIGINT
Max passes over the training data. Β· default 1000
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
penalty := VARCHAR
Regularization penalty. Β· default "l2"
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a sgd_classifier with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_sgd_classifier((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', loss := 'hinge', alpha := 0.0001);
Link
fit_sgd_regressor (data TABLE, alpha := DOUBLE, id := VARCHAR, loss := VARCHAR, max_iter := BIGINT, model_name := VARCHAR, penalty := VARCHAR, random_state := BIGINT, target := VARCHAR) 1 example

Fit a sgd_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
Regularization strength. Β· default 0.0001
id := VARCHAR
Optional id passthrough column. Β· default ""
loss := VARCHAR
Loss function. Β· default "squared_error"
max_iter := BIGINT
Max passes over the training data. Β· default 1000
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
penalty := VARCHAR
Regularization penalty. Β· default "l2"
random_state := BIGINT
Random seed. Β· default 0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a sgd_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_sgd_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', loss := 'squared_error', alpha := 0.0001);
Link
fit_svc (data TABLE, C := DOUBLE, degree := BIGINT, gamma := VARCHAR, id := VARCHAR, kernel := VARCHAR, model_name := VARCHAR, target := VARCHAR) 1 example

Fit a svc with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
C := DOUBLE
Regularization strength. Β· default 1.0
degree := BIGINT
Degree for the 'poly' kernel. Β· default 3
gamma := VARCHAR
Kernel coefficient. Β· default "scale"
id := VARCHAR
Optional id passthrough column. Β· default ""
kernel := VARCHAR
Kernel function. Β· default "rbf"
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a svc with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_svc((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', id := 'sample_id', C := 1.0, kernel := 'rbf');
Link
fit_svr (data TABLE, C := DOUBLE, epsilon := DOUBLE, gamma := VARCHAR, id := VARCHAR, kernel := VARCHAR, model_name := VARCHAR, target := VARCHAR) 1 example

Fit a svr with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
C := DOUBLE
Regularization strength. Β· default 1.0
epsilon := DOUBLE
Epsilon-tube within which no penalty is given. Β· default 0.1
gamma := VARCHAR
Kernel coefficient. Β· default "scale"
id := VARCHAR
Optional id passthrough column. Β· default ""
kernel := VARCHAR
Kernel function. Β· default "rbf"
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a svr with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_svr((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', C := 1.0, kernel := 'rbf');
Link
fit_tweedie_regressor (data TABLE, alpha := DOUBLE, id := VARCHAR, max_iter := BIGINT, model_name := VARCHAR, power := DOUBLE, target := VARCHAR) 1 example

Fit a tweedie_regressor with typed hyperparameters; returns/stores the model

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
alpha := DOUBLE
L2 regularization strength. Β· default 1.0
id := VARCHAR
Optional id passthrough column. Β· default ""
max_iter := BIGINT
Max solver iterations. Β· default 100
model_name := VARCHAR
Optional registry name; the model is always returned regardless. Β· default ""
power := DOUBLE
Tweedie power (0=normal, 1=Poisson, 2=Gamma, 3=inverse-Gaussian). Β· default 0.0
target := VARCHAR
Label column name (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a tweedie_regressor with named hyperparameters

SELECT estimator, task, n_samples, n_features, train_score
FROM sklearn.estimators.fit_tweedie_regressor((SELECT * FROM sklearn.datasets.diabetes()), target := 'target', id := 'sample_id', power := 0.0, alpha := 1.0);
Link
metrics 36 functions

Regression, classification, and clustering metrics as SQL aggregates.

Schema examples (3)
Examples (3)

R^2 over inline (actual, predicted) pairs

SELECT sklearn.metrics.r2_score(actual, predicted)
FROM (VALUES (3.0, 2.5), (5.0, 5.1)) AS t(actual, predicted);

Confusion matrix of 5-fold out-of-fold logistic-regression predictions on iris: each prediction joined back to its true species, one row per (actual, predicted) species code with its count

SELECT actual, predicted, count
FROM sklearn.metrics.confusion_matrix((SELECT i.target AS species, p.prediction AS predicted_species FROM sklearn.models.cross_val_predict((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), estimator := 'logistic_regression', target := 'target', id := 'sample_id') AS p JOIN sklearn.datasets.iris AS i USING (sample_id)), actual := 'species', predicted := 'predicted_species')
ORDER BY actual, predicted;

Silhouette score of a 3-cluster k-means on the iris measurements: the cluster labels joined back to the feature columns they were computed from (one row)

SELECT round(silhouette_score, 3) AS silhouette
FROM sklearn.metrics.silhouette_score((SELECT f.*, k.cluster FROM sklearn.preprocessing.kmeans((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id := 'sample_id', n_clusters := 3) AS k JOIN (SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()) AS f USING (sample_id)), label := 'cluster', id := 'sample_id');
Aggregate functions
accuracy_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Classification accuracy

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

accuracy_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.accuracy_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
adjusted_mutual_info_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Adjusted mutual information between two clusterings

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

adjusted_mutual_info_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.adjusted_mutual_info_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
adjusted_rand_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Adjusted Rand index between two clusterings

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

adjusted_rand_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.adjusted_rand_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
average_precision_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Average precision (y_pred = score/probability)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

average_precision_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.average_precision_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
balanced_accuracy_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Balanced accuracy

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

balanced_accuracy_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.balanced_accuracy_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
brier_score_loss (y_true DOUBLE, y_pred DOUBLE) 1 example

Brier score loss (calibration of binary probabilities; y_pred = P(class 1))

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

brier_score_loss over inline (actual, predicted) pairs

SELECT sklearn.metrics.brier_score_loss(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
cohen_kappa_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Cohen's kappa (inter-rater agreement)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

cohen_kappa_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.cohen_kappa_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
completeness_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Completeness of a clustering vs. ground truth

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

completeness_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.completeness_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
explained_variance_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Explained variance regression score

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

explained_variance_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.explained_variance_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
f1_score (y_true DOUBLE, y_pred DOUBLE) 1 example

F1 score (macro-averaged for multiclass)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

f1_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.f1_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
fowlkes_mallows_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Fowlkes-Mallows index between two clusterings

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

fowlkes_mallows_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.fowlkes_mallows_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
hamming_loss (y_true DOUBLE, y_pred DOUBLE) 1 example

Hamming loss (fraction of labels predicted incorrectly)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

hamming_loss over inline (actual, predicted) pairs

SELECT sklearn.metrics.hamming_loss(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
homogeneity_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Homogeneity of a clustering vs. ground truth

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

homogeneity_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.homogeneity_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
jaccard_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Jaccard similarity coefficient (macro-averaged for multiclass)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

jaccard_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.jaccard_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
log_loss (y_true DOUBLE, y_pred DOUBLE) 1 example

Logistic / cross-entropy loss (y_pred = P(class 1))

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

log_loss over inline (actual, predicted) pairs

SELECT sklearn.metrics.log_loss(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
matthews_corrcoef (y_true DOUBLE, y_pred DOUBLE) 1 example

Matthews correlation coefficient

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

matthews_corrcoef over inline (actual, predicted) pairs

SELECT sklearn.metrics.matthews_corrcoef(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
max_error (y_true DOUBLE, y_pred DOUBLE) 1 example

Maximum residual error (regression)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

max_error over inline (actual, predicted) pairs

SELECT sklearn.metrics.max_error(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
mean_absolute_error (y_true DOUBLE, y_pred DOUBLE) 1 example

Mean absolute error (regression)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

mean_absolute_error over inline (actual, predicted) pairs

SELECT sklearn.metrics.mean_absolute_error(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
mean_absolute_percentage_error (y_true DOUBLE, y_pred DOUBLE) 1 example

Mean absolute percentage error (regression)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

mean_absolute_percentage_error over inline (actual, predicted) pairs

SELECT sklearn.metrics.mean_absolute_percentage_error(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
mean_pinball_loss (y_true DOUBLE, y_pred DOUBLE) 1 example

Mean pinball loss for the median quantile (regression)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

mean_pinball_loss over inline (actual, predicted) pairs

SELECT sklearn.metrics.mean_pinball_loss(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
mean_squared_error (y_true DOUBLE, y_pred DOUBLE) 1 example

Mean squared error (regression)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

mean_squared_error over inline (actual, predicted) pairs

SELECT sklearn.metrics.mean_squared_error(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
mean_squared_log_error (y_true DOUBLE, y_pred DOUBLE) 1 example

Mean squared logarithmic error (regression; non-negative values)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

mean_squared_log_error over inline (actual, predicted) pairs

SELECT sklearn.metrics.mean_squared_log_error(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
median_absolute_error (y_true DOUBLE, y_pred DOUBLE) 1 example

Median absolute error (regression)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

median_absolute_error over inline (actual, predicted) pairs

SELECT sklearn.metrics.median_absolute_error(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
normalized_mutual_info_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Normalized mutual information between two clusterings

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

normalized_mutual_info_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.normalized_mutual_info_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
precision_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Precision (macro-averaged for multiclass)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

precision_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.precision_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
r2_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Coefficient of determination R^2 (regression)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

r2_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.r2_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
recall_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Recall (macro-averaged for multiclass)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

recall_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.recall_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
roc_auc_score (y_true DOUBLE, y_pred DOUBLE) 1 example

Area under the ROC curve (y_pred = score/probability)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

roc_auc_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.roc_auc_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
root_mean_squared_error (y_true DOUBLE, y_pred DOUBLE) 1 example

Root mean squared error (regression)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

root_mean_squared_error over inline (actual, predicted) pairs

SELECT sklearn.metrics.root_mean_squared_error(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
v_measure_score (y_true DOUBLE, y_pred DOUBLE) 1 example

V-measure (harmonic mean of homogeneity and completeness)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

v_measure_score over inline (actual, predicted) pairs

SELECT sklearn.metrics.v_measure_score(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
zero_one_loss (y_true DOUBLE, y_pred DOUBLE) 1 example

Zero-one classification loss (fraction of misclassifications)

Arguments
y_true DOUBLE
True (or label) values
y_pred DOUBLE
The prediction for each row (a positive-class score for ranking metrics)
ReturnsDOUBLE
Example

zero_one_loss over inline (actual, predicted) pairs

SELECT sklearn.metrics.zero_one_loss(actual, predicted)
FROM (VALUES (1.0, 0.9), (0.0, 0.2), (1.0, 0.8), (0.0, 0.1)) AS t(actual, predicted);
Link
Table in-out functions
calibration_curve (data TABLE, n_bins := BIGINT, y_score := VARCHAR, y_true := VARCHAR) 1 example

Reliability (calibration) curve: predicted vs. observed probability per bin

Positional arguments
data TABLE
The true-label and probability columns.
Named arguments
n_bins := BIGINT
Number of bins to group predicted probabilities into. Β· default 10
y_score := VARCHAR
Name of the predicted-probability column. Β· default "y_score"
y_true := VARCHAR
Name of the true binary-label column (0/1). Β· default "y_true"
Returns columns
prob_pred DOUBLE
Mean predicted probability in the bin.
prob_true DOUBLE
Observed fraction of positives in the bin.
Example

Calibration curve points

SELECT prob_pred, prob_true
FROM sklearn.metrics.calibration_curve((SELECT * FROM (VALUES (0, 0.1), (1, 0.9), (0, 0.2), (1, 0.8)) AS preds(y, p)), y_true := 'y', y_score := 'p', n_bins := 10)
ORDER BY prob_pred;
Link
confusion_matrix (data TABLE, actual := VARCHAR, predicted := VARCHAR) 2 examples

Confusion matrix in long format: (actual, predicted, count)

Positional arguments
data TABLE
The actual and predicted label columns.
Named arguments
actual := VARCHAR
Name of the true-label column. Β· default "actual"
predicted := VARCHAR
Name of the predicted-label column. Β· default "predicted"
Returns columns
actual BIGINT
True class label.
predicted BIGINT
Predicted class label.
count BIGINT
Number of rows with this (actual, predicted) pair.
Examples (2)

Long-format confusion matrix

SELECT actual, predicted, count
FROM sklearn.metrics.confusion_matrix((SELECT * FROM (VALUES (0, 0), (1, 1), (0, 1), (1, 0)) AS preds(y, yhat)), actual := 'y', predicted := 'yhat');

Confusion matrix of 5-fold out-of-fold logistic-regression predictions on iris: each prediction joined back to its true species, one row per (actual, predicted) species code with its count

SELECT actual, predicted, count
FROM sklearn.metrics.confusion_matrix((SELECT i.target AS species, p.prediction AS predicted_species FROM sklearn.models.cross_val_predict((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), estimator := 'logistic_regression', target := 'target', id := 'sample_id') AS p JOIN sklearn.datasets.iris AS i USING (sample_id)), actual := 'species', predicted := 'predicted_species')
ORDER BY actual, predicted;
Link
precision_recall_curve (data TABLE, y_score := VARCHAR, y_true := VARCHAR) 1 example

Precision-recall curve points (threshold, precision, recall) for a binary classifier

Positional arguments
data TABLE
The true-label and score columns.
Named arguments
y_score := VARCHAR
Name of the score/probability column. Β· default "y_score"
y_true := VARCHAR
Name of the true binary-label column (0/1). Β· default "y_true"
Returns columns
threshold DOUBLE
Decision threshold (NULL for the final point).
precision DOUBLE
Precision at this threshold.
recall DOUBLE
Recall at this threshold.
Example

Precision-recall curve points

SELECT recall, precision
FROM sklearn.metrics.precision_recall_curve((SELECT * FROM (VALUES (0, 0.1), (1, 0.9), (0, 0.2), (1, 0.8)) AS preds(y, p)), y_true := 'y', y_score := 'p')
ORDER BY recall;
Link
roc_curve (data TABLE, y_score := VARCHAR, y_true := VARCHAR) 1 example

ROC curve points (threshold, fpr, tpr) for a binary classifier

Positional arguments
data TABLE
The true-label and score columns.
Named arguments
y_score := VARCHAR
Name of the score/probability column. Β· default "y_score"
y_true := VARCHAR
Name of the true binary-label column (0/1). Β· default "y_true"
Returns columns
threshold DOUBLE
Decision threshold for this point.
fpr DOUBLE
False positive rate.
tpr DOUBLE
True positive rate.
Example

ROC curve points

SELECT fpr, tpr, threshold
FROM sklearn.metrics.roc_curve((SELECT * FROM (VALUES (0, 0.1), (1, 0.9), (0, 0.2), (1, 0.8)) AS preds(y, p)), y_true := 'y', y_score := 'p')
ORDER BY fpr;
Link
silhouette_score (data TABLE, id := VARCHAR, label := VARCHAR) 2 examples

Mean silhouette coefficient of a clustering (features + label column)

Positional arguments
data TABLE
Feature columns plus a cluster-label column.
Named arguments
id := VARCHAR
Optional id column to exclude from features. Β· default ""
label := VARCHAR
Name of the cluster-label column. Β· default "cluster"
Returns columns
silhouette_score DOUBLE
Mean silhouette coefficient over all samples (NULL if undefined).
Examples (2)

Silhouette score of a clustering

SELECT silhouette_score
FROM sklearn.metrics.silhouette_score((SELECT * FROM (VALUES (1, 0.1::DOUBLE, 0.2::DOUBLE, 0), (2, 0.2, 0.1, 0), (3, 5.0, 5.1, 1), (4, 5.1, 5.0, 1)) AS clustered(id, x1, x2, cluster)), label => 'cluster', id => 'id');

Silhouette score of a 3-cluster k-means on the iris measurements: the cluster labels joined back to the feature columns they were computed from (one row)

SELECT round(silhouette_score, 3) AS silhouette
FROM sklearn.metrics.silhouette_score((SELECT f.*, k.cluster FROM sklearn.preprocessing.kmeans((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id := 'sample_id', n_clusters := 3) AS k JOIN (SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()) AS f USING (sample_id)), label := 'cluster', id := 'sample_id');
Link
models 1 table Β· 19 functions

Train/predict model registry, cross-validation, inspection, and search.

Schema examples (2)
Examples (2)

3-fold cross-validated accuracy on iris

SELECT fold, score
FROM sklearn.models.cross_val_score((SELECT * FROM sklearn.datasets.iris()), estimator := 'logistic_regression', target := 'target', cv := 3);

Confusion matrix of 5-fold out-of-fold logistic-regression predictions on iris: each prediction joined back to its true species, one row per (actual, predicted) species code with its count

SELECT actual, predicted, count
FROM sklearn.metrics.confusion_matrix((SELECT i.target AS species, p.prediction AS predicted_species FROM sklearn.models.cross_val_predict((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), estimator := 'logistic_regression', target := 'target', id := 'sample_id') AS p JOIN sklearn.datasets.iris AS i USING (sample_id)), actual := 'species', predicted := 'predicted_species')
ORDER BY actual, predicted;
Tables
list_models 2 examples11 cols

One row per model persisted in the registry, with its estimator, task, shape, and score.

Columns
model_namenot null VARCHAR
Stored model name.
estimatornot null VARCHAR
Estimator type.
tasknot null VARCHAR
classification or regression.
targetnot null VARCHAR
Target column the model was trained on.
n_featuresnot null INTEGER
Number of features.
n_samplesnot null INTEGER
Number of training rows.
n_classes INTEGER
Number of classes (NULL for regression).
train_score DOUBLE
In-sample training score.
sklearn_version VARCHAR
scikit-learn version used to fit.
created_at VARCHAR
UTC timestamp the model was stored.
featuresnot null VARCHAR[]
Ordered feature column names.
ConstraintsPRIMARY KEY (model_name)
Examples (2)

How many models are saved

SELECT count(*) AS model_count FROM sklearn.models.list_models;
SELECT model_name, estimator, train_score
FROM sklearn.models.list_models()
ORDER BY created_at DESC;
Link
Scalar functions
predict_class_one (model BLOB, features ANY) 1 example

Score a row through a classifier BLOB; returns the class label as text

Arguments
model BLOB
A fitted classifier model
features ANY
Feature values, one field per feature
ReturnsVARCHAR
Example

Predict each customer's class label with their group's classifier

SELECT sklearn.models.predict_class_one(m.m.model, {'tenure': c.tenure, 'spend': c.spend})
FROM customers c
JOIN models m USING (region);
Link
predict_one (model BLOB, features ANY) 1 example

Score a row through a model BLOB; returns a numeric prediction

Arguments
model BLOB
A fitted model (from fit_model / fit)
features ANY
Feature values, one field per feature
ReturnsDOUBLE
Example

Score each customer with their group's regression model

SELECT sklearn.models.predict_one(m.m.model, {'tenure': c.tenure, 'spend': c.spend})
FROM customers c
JOIN models m USING (region);
Link
predict_proba_one (model BLOB, features ANY) 1 example

Class probabilities for a row through a classifier BLOB (DOUBLE[])

Arguments
model BLOB
A fitted classifier model
features ANY
Feature values, one field per feature
ReturnsDOUBLE[]
Example

Per-class probabilities from each customer's group classifier

SELECT sklearn.models.predict_proba_one(m.m.model, {'tenure': c.tenure, 'spend': c.spend})
FROM customers c
JOIN models m USING (region);
Link
Table functions
drop_model (model_name VARCHAR) 1 example

Delete a model from the registry

Arguments
model_name VARCHAR
Name of the model to delete.
Returns columns
model_name VARCHAR
Name of the model.
dropped BOOLEAN
True if a model was deleted, False if it did not exist.
Example

Delete a stored model

SELECT dropped FROM sklearn.models.drop_model('iris_rf');
Link
model_info (model_name VARCHAR) 1 example

Describe a single stored model (one row, empty if absent)

Arguments
model_name VARCHAR
Name of a stored model.
Returns columns
model_name VARCHAR
Stored model name.
estimator VARCHAR
Estimator type.
task VARCHAR
classification or regression.
target VARCHAR
Target column the model was trained on.
n_features INTEGER
Number of features.
n_samples INTEGER
Number of training rows.
n_classes INTEGER
Number of classes (NULL for regression).
train_score DOUBLE
In-sample training score.
sklearn_version VARCHAR
scikit-learn version used to fit.
created_at VARCHAR
UTC timestamp the model was stored.
features VARCHAR[]
Ordered feature column names.
Example

Show one model's metadata

SELECT estimator, task, n_features, train_score
FROM sklearn.models.model_info('iris_rf');
Link
Aggregate functions
fit_model (features ANY, target ANY, estimator VARCHAR, hyperparams VARCHAR) 1 example

Fit one model per group (aggregate); returns the model BLOB + diagnostics

Arguments
features ANY
Feature values, one field per feature, e.g. {'a': a, 'b': b}
target ANY
Target column (continuous values, or string class labels)
estimator VARCHAR
Estimator name, e.g. 'random_forest_classifier'
hyperparams VARCHAR
JSON hyperparameters; '{}' for defaults
ReturnsSTRUCT of 7 fields
STRUCT 7 fields
  • modelBLOB
  • estimatorVARCHAR
  • taskVARCHAR
  • n_samplesBIGINT
  • n_featuresBIGINT
  • n_classesBIGINT
  • train_scoreDOUBLE
Example

One churn model per region

SELECT region,
  sklearn.models.fit_model({'tenure': tenure, 'spend': spend}, churned, 'gradient_boosting_classifier', '{}') AS m
FROM (VALUES ('east', 12, 30.0, 0), ('east', 3, 80.0, 1), ('west', 24, 20.0, 0), ('west', 1, 90.0, 1)) AS customers(region, tenure, spend, churned)
GROUP BY region;
Link
Table in-out functions
cross_val_predict (data TABLE, cv := BIGINT, estimator := VARCHAR, id := VARCHAR, params := VARCHAR, target := VARCHAR) 2 examples

Out-of-fold cross-validated predictions (no model is stored)

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
cv := BIGINT
Number of cross-validation folds. Β· default 5
estimator := VARCHAR
Estimator name. Β· default "random_forest_classifier"
id := VARCHAR
Optional id column to carry through. Β· default ""
params := VARCHAR
JSON object of hyperparameters. Β· default ""
target := VARCHAR
Name of the target/label column (required). Β· default ""
Returns columns
prediction BIGINT
Out-of-fold predicted class label.
prediction DOUBLE
Out-of-fold predicted value.
Returns columns Β· depends on the arguments
Classifier
prediction BIGINT
Out-of-fold predicted class label.
Regressor
prediction DOUBLE
Out-of-fold predicted value.
Examples (2)

5-fold out-of-fold predictions on iris

SELECT sample_id, prediction
FROM sklearn.models.cross_val_predict((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), estimator => 'logistic_regression', target => 'target', id => 'sample_id');

Confusion matrix of 5-fold out-of-fold logistic-regression predictions on iris: each prediction joined back to its true species, one row per (actual, predicted) species code with its count

SELECT actual, predicted, count
FROM sklearn.metrics.confusion_matrix((SELECT i.target AS species, p.prediction AS predicted_species FROM sklearn.models.cross_val_predict((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), estimator := 'logistic_regression', target := 'target', id := 'sample_id') AS p JOIN sklearn.datasets.iris AS i USING (sample_id)), actual := 'species', predicted := 'predicted_species')
ORDER BY actual, predicted;
Link
cross_val_score (data TABLE, cv := BIGINT, estimator := VARCHAR, id := VARCHAR, params := VARCHAR, scoring := VARCHAR, target := VARCHAR) 1 example

Cross-validated held-out scores, one row per fold (no model is stored)

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
cv := BIGINT
Number of cross-validation folds. Β· default 5
estimator := VARCHAR
Estimator name. Β· default "random_forest_classifier"
id := VARCHAR
Optional id column to exclude from features. Β· default ""
params := VARCHAR
JSON object of hyperparameters. Β· default ""
scoring := VARCHAR
Scorer name (default: the estimator's own scorer). Β· default ""
target := VARCHAR
Name of the target/label column (required). Β· default ""
Returns columns
fold BIGINT
Cross-validation fold index (0-based).
score DOUBLE
Held-out score for this fold.
Example

5-fold accuracy of a logistic regression on iris

SELECT fold, score
FROM sklearn.models.cross_val_score((SELECT sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), estimator => 'logistic_regression', target => 'target');
Link
fit (data TABLE, estimator := VARCHAR, id := VARCHAR, model_name := VARCHAR, params := VARCHAR, target := VARCHAR) 1 example

Fit a supervised estimator and store it in the model registry

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
estimator := VARCHAR
Estimator name. Β· default "random_forest_classifier"
id := VARCHAR
Optional id column to exclude from features. Β· default ""
model_name := VARCHAR
Name to store the fitted model under (required). Β· default ""
params := VARCHAR
JSON object of hyperparameters. Β· default ""
target := VARCHAR
Name of the target/label column (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Train a random forest on iris and store it as 'iris_rf'

SELECT model_name, estimator, n_samples, train_score
FROM sklearn.models.fit((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), model_name => 'iris_rf', estimator => 'random_forest_classifier', target => 'target', id => 'sample_id');
Link
fit_pipeline (data TABLE, estimator := VARCHAR, id := VARCHAR, model_name := VARCHAR, params := VARCHAR, steps := VARCHAR, target := VARCHAR) 1 example

Fit preprocessing steps + an estimator as one model; predict with the usual 'predict'

Positional arguments
data TABLE
Training rows: features + target [+ id].
Named arguments
estimator := VARCHAR
Final estimator name. Β· default "random_forest_classifier"
id := VARCHAR
Optional id column to exclude from features. Β· default ""
model_name := VARCHAR
Name to store the fitted pipeline under (optional). Β· default ""
params := VARCHAR
JSON object of estimator hyperparameters. Β· default ""
steps := VARCHAR
JSON array of preprocessing steps, e.g. [{"kind":"standard_scaler"}]. Β· default ""
target := VARCHAR
Name of the target/label column (required). Β· default ""
Returns columns
model_name VARCHAR
Name the model was stored under ('' if not persisted).
estimator VARCHAR
Estimator type used.
task VARCHAR
classification or regression.
n_samples BIGINT
Number of training rows.
n_features BIGINT
Number of features.
n_classes BIGINT
Number of classes (NULL for regression).
train_score DOUBLE
In-sample score (accuracy or R^2).
features VARCHAR[]
Ordered feature column names.
model BLOB
The fitted model as a self-contained `BLOB` (estimator + metadata).
Example

Scale -> PCA -> logistic regression, stored as one model

SELECT model_name, estimator, n_features
FROM sklearn.models.fit_pipeline((SELECT * FROM sklearn.datasets.iris()), steps := '[{"kind": "standard_scaler"}, {"kind": "pca", "params": {"n_components": 3}}]', estimator := 'logistic_regression', target := 'target', id := 'sample_id', model_name := 'iris_pipe');
Link
group_kfold (data TABLE, group_col := VARCHAR, id := VARCHAR, n_splits := BIGINT) 1 example

K-fold that keeps all rows of a group in the same fold (id, fold)

Positional arguments
data TABLE
Rows to split (id + the group column).
Named arguments
group_col := VARCHAR
Group column; rows of a group stay in the same fold (required). Β· default ""
id := VARCHAR
Column carried onto each row (required). Β· default ""
n_splits := BIGINT
Number of folds. Β· default 5
Returns columns
fold BIGINT
Test fold this row belongs to.
Returns columns Β· depends on the arguments
fold BIGINT
Test fold this row belongs to.
Example

Group-aware 3-fold (no group spans folds)

SELECT sample_id, fold
FROM sklearn.models.group_kfold((SELECT sample_id, target AS grp FROM sklearn.datasets.iris()), id := 'sample_id', group_col := 'grp', n_splits := 3);
Link
kfold (data TABLE, id := VARCHAR, n_splits := BIGINT, random_state := BIGINT, shuffle := BOOLEAN) 1 example

Assign each row a K-fold test fold (id, fold)

Positional arguments
data TABLE
Rows to split (only the id column is used).
Named arguments
id := VARCHAR
Column carried onto each row (required). Β· default ""
n_splits := BIGINT
Number of folds. Β· default 5
random_state := BIGINT
Random seed (used when shuffle is true). Β· default 0
shuffle := BOOLEAN
Shuffle rows before splitting. Β· default false
Returns columns
fold BIGINT
Test fold this row belongs to.
Returns columns Β· depends on the arguments
fold BIGINT
Test fold this row belongs to.
Example

Rows per fold in a 5-fold split of iris

SELECT fold, count(*) AS n_rows
FROM sklearn.models.kfold((SELECT sample_id FROM sklearn.datasets.iris()), id := 'sample_id', n_splits := 5)
GROUP BY fold;
Link
partial_dependence (data TABLE, feature := VARCHAR, grid_resolution := BIGINT, model := BLOB, model_name := VARCHAR) 1 example

How a stored model's average prediction changes as one feature varies over a grid

Positional arguments
data TABLE
Background rows: the model's feature columns.
Named arguments
feature := VARCHAR
Feature column to vary (required). Β· default ""
grid_resolution := BIGINT
Number of grid points along the feature. Β· default 100
model := BLOB
A fitted model. Provide this OR model_name. Β· default "b''"
model_name := VARCHAR
Name of a model in the registry. Provide this OR model. Β· default ""
Returns columns
feature_value DOUBLE
Value the feature was set to.
class BIGINT
Class label (NULL for regression / the single binary curve).
partial_dependence DOUBLE
Average model output at this feature value.
Example

Partial dependence of 'iris_rf' on petal length

SELECT feature_value, class, partial_dependence
FROM sklearn.models.partial_dependence((SELECT * FROM sklearn.datasets.iris()), model_name := 'iris_rf', feature := 'petal_length_cm')
ORDER BY feature_value;
Link
permutation_importance (data TABLE, model := BLOB, model_name := VARCHAR, n_repeats := BIGINT, random_state := BIGINT, scoring := VARCHAR, target := VARCHAR) 1 example

Model-agnostic feature importance: the drop in score when each feature is shuffled

Positional arguments
data TABLE
Evaluation rows: the model's features + the target column.
Named arguments
model := BLOB
A fitted model, as returned by fit. Provide this OR model_name. Β· default "b''"
model_name := VARCHAR
Name of a model in the registry. Provide this OR model. Β· default ""
n_repeats := BIGINT
Number of times each feature is shuffled. Β· default 5
random_state := BIGINT
Random seed. Β· default 0
scoring := VARCHAR
Scorer name (default: the estimator's own scorer). Β· default ""
target := VARCHAR
Name of the target/label column (required). Β· default ""
Returns columns
feature VARCHAR
Feature column name.
importance_mean DOUBLE
Mean drop in score when the feature is shuffled.
importance_std DOUBLE
Std-dev of the importance across repeats.
Example

Rank iris features by permutation importance for the stored 'iris_rf' model

SELECT feature, importance_mean
FROM sklearn.models.permutation_importance((SELECT * FROM sklearn.datasets.iris()), model_name := 'iris_rf', target := 'target')
ORDER BY importance_mean DESC;
Link
predict (data TABLE, id := VARCHAR, model := BLOB, model_name := VARCHAR, with_proba := BOOLEAN) 1 example

Score a table through a stored model, emitting predictions

Positional arguments
data TABLE
Rows to score (must contain the model's feature columns).
Named arguments
id := VARCHAR
Optional id column to carry through. Β· default ""
model := BLOB
A fitted model, as returned by fit. Provide this OR model_name. Β· default "b''"
model_name := VARCHAR
Name of a model in the registry. Provide this OR model. Β· default ""
with_proba := BOOLEAN
Also emit per-class probabilities (classifiers). Β· default false
Returns columns
prediction BIGINT
Predicted class label.
prediction DOUBLE
Predicted value.
Returns columns Β· depends on the arguments
Classifier
prediction BIGINT
Predicted class label.
Regressor
prediction DOUBLE
Predicted value.
Example

Predict with the stored 'iris_rf' model

SELECT sample_id, prediction
FROM sklearn.models.predict((SELECT * FROM sklearn.datasets.iris()), model_name := 'iris_rf', id := 'sample_id');
Link
stratified_kfold (data TABLE, id := VARCHAR, label := VARCHAR, n_splits := BIGINT, random_state := BIGINT, shuffle := BOOLEAN) 1 example

K-fold that preserves each class's proportion per fold (id, fold)

Positional arguments
data TABLE
Rows to split (id + the stratify label column).
Named arguments
id := VARCHAR
Column carried onto each row (required). Β· default ""
label := VARCHAR
Label column to stratify on (required). Β· default ""
n_splits := BIGINT
Number of folds. Β· default 5
random_state := BIGINT
Random seed (used when shuffle is true). Β· default 0
shuffle := BOOLEAN
Shuffle rows before splitting. Β· default false
Returns columns
fold BIGINT
Test fold this row belongs to.
Returns columns Β· depends on the arguments
fold BIGINT
Test fold this row belongs to.
Example

Class-balanced 5-fold for iris

SELECT sample_id, fold
FROM sklearn.models.stratified_kfold((SELECT sample_id, target FROM sklearn.datasets.iris()), id := 'sample_id', label := 'target', n_splits := 5);
Link
timeseries_split (data TABLE, id := VARCHAR, n_splits := BIGINT) 1 example

Expanding-window splits for ordered data: (split, id, role) in {train, test}

Positional arguments
data TABLE
Rows to split, in time order (only the id column is used).
Named arguments
id := VARCHAR
Column carried onto each row (required). Β· default ""
n_splits := BIGINT
Number of expanding-window splits. Β· default 5
Returns columns
split BIGINT
Split index (0-based).
role VARCHAR
'train' or 'test' for this row in this split.
Returns columns Β· depends on the arguments
split BIGINT
Split index (0-based).
role VARCHAR
'train' or 'test' for this row in this split.
Example

Forward-chaining train/test splits over ordered rows

SELECT split, role, count(*) AS n_rows
FROM sklearn.models.timeseries_split((SELECT sample_id FROM sklearn.datasets.iris() ORDER BY sample_id), id := 'sample_id', n_splits := 5)
GROUP BY split, role
ORDER BY split, role;
Link
preprocessing 1 table Β· 40 functions

Transforms, encoders, decomposition, clustering, and stored transformers.

Schema examples (3)
Examples (3)

Standard-scale the iris features

SELECT *
FROM sklearn.preprocessing.standard_scaler((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id := 'sample_id')
LIMIT 5;

Standardize the iris measurements, project them onto 2 principal components, and average each component per species (the first component separates the species)

SELECT i.target_name, round(avg(p.component_1), 2) AS mean_pc1,
  round(avg(p.component_2), 2) AS mean_pc2
FROM sklearn.preprocessing.pca((SELECT * FROM sklearn.preprocessing.standard_scaler((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id := 'sample_id')), id := 'sample_id', n_components := 2) AS p
JOIN sklearn.datasets.iris AS i USING (sample_id)
GROUP BY i.target_name
ORDER BY mean_pc1;

Score 3-cluster k-means on the iris measurements against the true species: adjusted Rand index, homogeneity, and completeness of the clusters (one row)

SELECT round(sklearn.metrics.adjusted_rand_score(i.target, k.cluster), 3) AS adjusted_rand,
  round(sklearn.metrics.homogeneity_score(i.target, k.cluster), 3) AS homogeneity,
  round(sklearn.metrics.completeness_score(i.target, k.cluster), 3) AS completeness
FROM sklearn.preprocessing.kmeans((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id := 'sample_id', n_clusters := 3) AS k
JOIN sklearn.datasets.iris AS i USING (sample_id);
Tables
list_transformers 2 examples7 cols

One row per fitted transformer persisted in the registry, with its kind and shape.

Columns
transformer_namenot null VARCHAR
Stored transformer name.
kindnot null VARCHAR
Transformer kind.
n_featuresnot null INTEGER
Number of input features.
n_outputnot null INTEGER
Number of output columns.
featuresnot null VARCHAR[]
Ordered input feature names.
sklearn_version VARCHAR
scikit-learn version used to fit.
created_at VARCHAR
UTC timestamp the transformer was stored.
ConstraintsPRIMARY KEY (transformer_name)
Examples (2)

How many transformers are saved

SELECT count(*) AS transformer_count
FROM sklearn.preprocessing.list_transformers;
SELECT transformer_name, kind, n_output
FROM sklearn.preprocessing.list_transformers();
Link
Table functions
drop_transformer (transformer_name VARCHAR) 1 example

Delete a transformer from the registry

Arguments
transformer_name VARCHAR
Name of the transformer to delete.
Returns columns
transformer_name VARCHAR
Name of the transformer.
dropped BOOLEAN
True if a transformer was deleted, False if it did not exist.
Example

Delete a stored transformer

SELECT dropped FROM sklearn.preprocessing.drop_transformer('sc');
Link
Table in-out functions
agglomerative_clustering (data TABLE, id := VARCHAR, linkage := VARCHAR, n_clusters := BIGINT) 1 example

Hierarchical (agglomerative) clustering; emits a cluster label per row

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
linkage := VARCHAR
Cluster linkage criterion. Β· default "ward"
n_clusters := BIGINT
Number of clusters. Β· default 2
Returns columns
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Returns columns Β· depends on the arguments
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Example

Apply agglomerative_clustering to the iris features

SELECT cluster, count(*) AS n_samples
FROM sklearn.preprocessing.agglomerative_clustering((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_clusters => 3)
GROUP BY cluster
ORDER BY cluster;
Link
apply_transform (data TABLE, id := VARCHAR, transformer := BLOB, transformer_name := VARCHAR) 1 example

Stream a table through a stored, already-fitted transformer

Positional arguments
data TABLE
Rows to transform (must contain the transformer's feature columns).
Named arguments
id := VARCHAR
Optional id column to carry through. Β· default ""
transformer := BLOB
A fitted transformer (from fit_transformer). Provide this OR name. Β· default "b''"
transformer_name := VARCHAR
Name of a stored transformer. Provide this OR transformer. Β· default ""
Returns columns
<output> DOUBLE
One column per transformer output, named as at fit time: the input feature names when width is preserved, else `component_1..k`.
<feature> BIGINT
One bin-index column per input feature.
Returns columns Β· depends on the arguments
Scalers, imputers, decompositions
<output> DOUBLE
One column per transformer output, named as at fit time: the input feature names when width is preserved, else `component_1..k`.
kbins_discretizer
<feature> BIGINT
One bin-index column per input feature.
Example

Apply the stored 'sc' transformer to new data

SELECT sample_id, sepal_length_cm, sepal_width_cm
FROM sklearn.preprocessing.apply_transform((SELECT * FROM sklearn.datasets.iris()), transformer_name := 'sc', id := 'sample_id');
Link
binarizer (data TABLE, id := VARCHAR, threshold := DOUBLE) 1 example

Threshold features to 0/1

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
threshold := DOUBLE
Values above this map to 1, else 0. Β· default 0.0
Returns columns
<feature> DOUBLE
One column per input feature (same name as the input): the 0/1 thresholded value.
Returns columns Β· depends on the arguments
<feature> DOUBLE
One column per input feature (same name as the input): the 0/1 thresholded value.
Example

Apply binarizer to the iris features

SELECT sample_id, sepal_length_cm, petal_length_cm
FROM sklearn.preprocessing.binarizer((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', threshold => 0.0);
Link
birch (data TABLE, id := VARCHAR, n_clusters := BIGINT, threshold := DOUBLE) 1 example

BIRCH clustering (memory-efficient for large datasets)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_clusters := BIGINT
Number of clusters for the final step. Β· default 3
threshold := DOUBLE
Radius of a subcluster to absorb a sample. Β· default 0.5
Returns columns
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Returns columns Β· depends on the arguments
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Example

Apply birch to the iris features

SELECT cluster, count(*) AS n_samples
FROM sklearn.preprocessing.birch((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_clusters => 3)
GROUP BY cluster
ORDER BY cluster;
Link
count_vectorizer (data TABLE, id := VARCHAR, lowercase := BOOLEAN, max_df := DOUBLE, max_features := BIGINT, min_df := BIGINT, ngram_max := BIGINT, stop_words := VARCHAR, text := VARCHAR) 1 example

Tokenize a text column into a document-term count matrix (long format)

Positional arguments
data TABLE
An id column and a text column.
Named arguments
id := VARCHAR
Optional id column to carry onto each emitted row. Β· default ""
lowercase := BOOLEAN
Lowercase before tokenizing. Β· default true
max_df := DOUBLE
Ignore terms in more than this fraction of documents. Β· default 1.0
max_features := BIGINT
Keep only the top-N terms by frequency; 0 = all. Β· default 0
min_df := BIGINT
Ignore terms in fewer than this many documents. Β· default 1
ngram_max := BIGINT
Max n-gram size (uses ngram_range=(1, ngram_max)). Β· default 1
stop_words := VARCHAR
'english' to drop English stop words; '' for none. Β· default ""
text := VARCHAR
Text column to vectorize (defaults to the single non-id column). Β· default ""
Returns columns
term VARCHAR
Vocabulary term (or n-gram).
value BIGINT
Term count in the document.
Returns columns Β· depends on the arguments
term VARCHAR
Vocabulary term (or n-gram).
value BIGINT
Term count in the document.
Example

Corpus-wide term counts

SELECT term, sum(value) AS n
FROM sklearn.preprocessing.count_vectorizer((SELECT * FROM (VALUES (1, 'the cat sat on the mat'), (2, 'a quick brown dog')) AS docs(id, body)), id := 'id', text := 'body')
GROUP BY term
ORDER BY n DESC, term;
Link
dbscan (data TABLE, eps := DOUBLE, id := VARCHAR, min_samples := BIGINT) 1 example

DBSCAN density clustering; emits a cluster label per row (-1 = noise)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
eps := DOUBLE
Max neighbourhood distance. Β· default 0.5
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
min_samples := BIGINT
Min samples to form a dense region. Β· default 5
Returns columns
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Returns columns Β· depends on the arguments
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Example

Apply dbscan to the iris features

SELECT cluster, count(*) AS n_samples
FROM sklearn.preprocessing.dbscan((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', eps => 0.5)
GROUP BY cluster
ORDER BY cluster;
Link
elliptic_envelope (data TABLE, contamination := DOUBLE, id := VARCHAR, random_state := BIGINT) 1 example

Elliptic Envelope (Gaussian) outlier detection; emits an anomaly score and flag per row

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
contamination := DOUBLE
Expected proportion of outliers. Β· default 0.1
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
random_state := BIGINT
Random seed. Β· default 0
Returns columns
anomaly_score DOUBLE
Anomaly score; higher = more anomalous.
is_outlier INTEGER
1 if flagged as an outlier, else 0.
Returns columns Β· depends on the arguments
anomaly_score DOUBLE
Anomaly score; higher = more anomalous.
is_outlier INTEGER
1 if flagged as an outlier, else 0.
Example

Apply elliptic_envelope to the iris features

SELECT sample_id, anomaly_score
FROM sklearn.preprocessing.elliptic_envelope((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', contamination => 0.1)
WHERE is_outlier = 1
ORDER BY anomaly_score DESC;
Link
fit_transformer (data TABLE, id := VARCHAR, kind := VARCHAR, params := VARCHAR, transformer_name := VARCHAR) 1 example

Fit a transformer (scaler/PCA/imputer/...) and return it as a BLOB; persist if named

Positional arguments
data TABLE
Training rows: feature columns [+ id].
Named arguments
id := VARCHAR
Optional id column to exclude from features. Β· default ""
kind := VARCHAR
Transformer kind to fit. Β· default "standard_scaler"
params := VARCHAR
JSON object of transformer parameters. Β· default ""
transformer_name := VARCHAR
Name to store the fitted transformer under (optional). Β· default ""
Returns columns
transformer_name VARCHAR
Name it was stored under ('' if not persisted).
kind VARCHAR
Transformer kind.
n_features BIGINT
Number of input features.
n_output BIGINT
Number of output columns.
output_names VARCHAR[]
Ordered output column names.
transformer BLOB
The fitted transformer as a self-contained BLOB.
Example

Fit a StandardScaler and store it as 'sc'

SELECT transformer_name, kind, n_output
FROM sklearn.preprocessing.fit_transformer((SELECT sepal_length_cm, sepal_width_cm FROM sklearn.datasets.iris()), transformer_name := 'sc', kind := 'standard_scaler');
Link
gaussian_mixture (data TABLE, covariance_type := VARCHAR, id := VARCHAR, n_components := BIGINT, random_state := BIGINT) 1 example

Gaussian mixture model clustering; emits the most likely component per row

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
covariance_type := VARCHAR
Shape of each component's covariance matrix. Β· default "full"
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_components := BIGINT
Number of mixture components (clusters). Β· default 2
random_state := BIGINT
Random seed. Β· default 0
Returns columns
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Returns columns Β· depends on the arguments
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Example

Apply gaussian_mixture to the iris features

SELECT cluster, count(*) AS n_samples
FROM sklearn.preprocessing.gaussian_mixture((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_components => 3)
GROUP BY cluster
ORDER BY cluster;
Link
isolation_forest (data TABLE, contamination := DOUBLE, id := VARCHAR, random_state := BIGINT) 1 example

Isolation Forest outlier detection; emits an anomaly score and flag per row

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
contamination := DOUBLE
Expected proportion of outliers. Β· default 0.1
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
random_state := BIGINT
Random seed. Β· default 0
Returns columns
anomaly_score DOUBLE
Anomaly score; higher = more anomalous.
is_outlier INTEGER
1 if flagged as an outlier, else 0.
Returns columns Β· depends on the arguments
anomaly_score DOUBLE
Anomaly score; higher = more anomalous.
is_outlier INTEGER
1 if flagged as an outlier, else 0.
Example

Apply isolation_forest to the iris features

SELECT sample_id, anomaly_score
FROM sklearn.preprocessing.isolation_forest((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', contamination => 0.1)
WHERE is_outlier = 1
ORDER BY anomaly_score DESC;
Link
isomap (data TABLE, id := VARCHAR, n_components := BIGINT, n_neighbors := BIGINT) 1 example

Isomap non-linear embedding (geodesic distance preservation)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_components := BIGINT
Number of components to keep. Β· default 2
n_neighbors := BIGINT
Number of neighbours per point. Β· default 5
Returns columns
component_<i> DOUBLE
Projection onto component i (one per kept component).
Returns columns Β· depends on the arguments
component_<i> DOUBLE
Projection onto component i (one per kept component).
Example

Apply isomap to the iris features

SELECT sample_id, component_1, component_2
FROM sklearn.preprocessing.isomap((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_components => 2);
Link
kbins_discretizer (data TABLE, id := VARCHAR, n_bins := BIGINT, strategy := VARCHAR) 1 example

Discretize continuous features into integer bins (one bin index column per feature)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_bins := BIGINT
Number of bins per feature. Β· default 5
strategy := VARCHAR
How bin edges are placed. Β· default "quantile"
Returns columns
<feature> BIGINT
One column per input feature (same name as the input): the bin index.
Returns columns Β· depends on the arguments
<feature> BIGINT
One column per input feature (same name as the input): the bin index.
Example

Apply kbins_discretizer to the iris features

SELECT sample_id, sepal_length_cm, petal_length_cm
FROM sklearn.preprocessing.kbins_discretizer((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_bins => 5);
Link
kmeans (data TABLE, id := VARCHAR, n_clusters := BIGINT, random_state := BIGINT) 2 examples

K-Means clustering; emits a cluster label per row

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_clusters := BIGINT
Number of clusters. Β· default 8
random_state := BIGINT
Random seed. Β· default 0
Returns columns
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Returns columns Β· depends on the arguments
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Examples (2)

Apply kmeans to the iris features

SELECT cluster, count(*) AS n_samples
FROM sklearn.preprocessing.kmeans((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_clusters => 3)
GROUP BY cluster
ORDER BY cluster;

Score 3-cluster k-means on the iris measurements against the true species: adjusted Rand index, homogeneity, and completeness of the clusters (one row)

SELECT round(sklearn.metrics.adjusted_rand_score(i.target, k.cluster), 3) AS adjusted_rand,
  round(sklearn.metrics.homogeneity_score(i.target, k.cluster), 3) AS homogeneity,
  round(sklearn.metrics.completeness_score(i.target, k.cluster), 3) AS completeness
FROM sklearn.preprocessing.kmeans((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id := 'sample_id', n_clusters := 3) AS k
JOIN sklearn.datasets.iris AS i USING (sample_id);
Link
local_outlier_factor (data TABLE, contamination := DOUBLE, id := VARCHAR, n_neighbors := BIGINT) 1 example

Local Outlier Factor; emits an anomaly score and flag per row

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
contamination := DOUBLE
Expected proportion of outliers. Β· default 0.1
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_neighbors := BIGINT
Number of neighbours to use. Β· default 20
Returns columns
anomaly_score DOUBLE
Anomaly score; higher = more anomalous.
is_outlier INTEGER
1 if flagged as an outlier, else 0.
Returns columns Β· depends on the arguments
anomaly_score DOUBLE
Anomaly score; higher = more anomalous.
is_outlier INTEGER
1 if flagged as an outlier, else 0.
Example

Apply local_outlier_factor to the iris features

SELECT sample_id, anomaly_score
FROM sklearn.preprocessing.local_outlier_factor((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_neighbors => 20)
WHERE is_outlier = 1
ORDER BY anomaly_score DESC;
Link
maxabs_scaler (data TABLE, id := VARCHAR) 1 example

Scale each feature by its maximum absolute value (to [-1, 1])

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
Returns columns
<feature> DOUBLE
One column per input feature (same name as the input): the scaled value.
Returns columns Β· depends on the arguments
<feature> DOUBLE
One column per input feature (same name as the input): the scaled value.
Example

Apply maxabs_scaler to the iris features

SELECT sample_id, sepal_length_cm, petal_length_cm
FROM sklearn.preprocessing.maxabs_scaler((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id');
Link
mds (data TABLE, id := VARCHAR, n_components := BIGINT, random_state := BIGINT) 1 example

Multidimensional scaling embedding (distance preservation)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_components := BIGINT
Number of components to keep. Β· default 2
random_state := BIGINT
Random seed. Β· default 0
Returns columns
component_<i> DOUBLE
Projection onto component i (one per kept component).
Returns columns Β· depends on the arguments
component_<i> DOUBLE
Projection onto component i (one per kept component).
Example

Apply mds to the iris features

SELECT sample_id, component_1, component_2
FROM sklearn.preprocessing.mds((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_components => 2);
Link
mean_shift (data TABLE, bandwidth := DOUBLE, id := VARCHAR) 1 example

Mean-shift clustering (auto-discovers the number of clusters)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
bandwidth := DOUBLE
Kernel bandwidth; 0 = estimate automatically. Β· default 0.0
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
Returns columns
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Returns columns Β· depends on the arguments
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Example

Apply mean_shift to the iris features

SELECT cluster, count(*) AS n_samples
FROM sklearn.preprocessing.mean_shift((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id')
GROUP BY cluster
ORDER BY cluster;
Link
minibatch_kmeans (data TABLE, id := VARCHAR, n_clusters := BIGINT, random_state := BIGINT) 1 example

Mini-batch K-Means clustering (faster on large datasets)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_clusters := BIGINT
Number of clusters. Β· default 8
random_state := BIGINT
Random seed. Β· default 0
Returns columns
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Returns columns Β· depends on the arguments
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Example

Apply minibatch_kmeans to the iris features

SELECT cluster, count(*) AS n_samples
FROM sklearn.preprocessing.minibatch_kmeans((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_clusters => 3)
GROUP BY cluster
ORDER BY cluster;
Link
minmax_scaler (data TABLE, id := VARCHAR) 1 example

Scale features to the [0, 1] range

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
Returns columns
<feature> DOUBLE
One column per input feature (same name as the input): the scaled value.
Returns columns Β· depends on the arguments
<feature> DOUBLE
One column per input feature (same name as the input): the scaled value.
Example

Apply minmax_scaler to the iris features

SELECT sample_id, sepal_length_cm, petal_length_cm
FROM sklearn.preprocessing.minmax_scaler((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id');
Link
normalizer (data TABLE, id := VARCHAR, norm := VARCHAR) 1 example

Scale each sample (row) to unit norm

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
norm := VARCHAR
Norm each row is scaled to. Β· default "l2"
Returns columns
<feature> DOUBLE
One column per input feature (same name as the input): the normalized value.
Returns columns Β· depends on the arguments
<feature> DOUBLE
One column per input feature (same name as the input): the normalized value.
Example

Apply normalizer to the iris features

SELECT sample_id, sepal_length_cm, petal_length_cm
FROM sklearn.preprocessing.normalizer((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', norm => 'l2');
Link
one_class_svm (data TABLE, gamma := VARCHAR, id := VARCHAR, kernel := VARCHAR, nu := DOUBLE) 1 example

One-Class SVM novelty/outlier detection; emits an anomaly score and flag per row

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
gamma := VARCHAR
Kernel coefficient ('scale' or 'auto'). Β· default "scale"
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
kernel := VARCHAR
Kernel function. Β· default "rbf"
nu := DOUBLE
Upper bound on the fraction of outliers. Β· default 0.5
Returns columns
anomaly_score DOUBLE
Anomaly score; higher = more anomalous.
is_outlier INTEGER
1 if flagged as an outlier, else 0.
Returns columns Β· depends on the arguments
anomaly_score DOUBLE
Anomaly score; higher = more anomalous.
is_outlier INTEGER
1 if flagged as an outlier, else 0.
Example

Apply one_class_svm to the iris features

SELECT sample_id, anomaly_score
FROM sklearn.preprocessing.one_class_svm((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', nu => 0.1)
WHERE is_outlier = 1
ORDER BY anomaly_score DESC;
Link
one_hot_encoder (data TABLE, id := VARCHAR) 1 example

One-hot encode categorical (string) columns in long format (id, feature, category, value)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
Returns columns
feature VARCHAR
Source feature column.
category VARCHAR
Category value that is set for this row.
value DOUBLE
Indicator value (always 1.0 for an active cell).
Returns columns Β· depends on the arguments
feature VARCHAR
Source feature column.
category VARCHAR
Category value that is set for this row.
value DOUBLE
Indicator value (always 1.0 for an active cell).
Example

One-hot encode the iris species name (one row per active category)

SELECT category, count(*) AS n
FROM sklearn.preprocessing.one_hot_encoder((SELECT sample_id, target_name FROM sklearn.datasets.iris()), id => 'sample_id')
GROUP BY category;
Link
optics (data TABLE, id := VARCHAR, min_samples := BIGINT) 1 example

OPTICS density clustering; emits a cluster label per row (-1 = noise)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
min_samples := BIGINT
Min samples in a neighbourhood for a core point. Β· default 5
Returns columns
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Returns columns Β· depends on the arguments
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Example

Apply optics to the iris features

SELECT cluster, count(*) AS n_samples
FROM sklearn.preprocessing.optics((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', min_samples => 5)
GROUP BY cluster
ORDER BY cluster;
Link
ordinal_encoder (data TABLE, id := VARCHAR) 1 example

Encode each categorical (string) column as integer codes (one column per feature)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
Returns columns
<feature> BIGINT
One column per input feature (same name as the input): the integer code (-1 = missing/unseen).
Returns columns Β· depends on the arguments
<feature> BIGINT
One column per input feature (same name as the input): the integer code (-1 = missing/unseen).
Example

Encode the iris species name as an integer code

SELECT sample_id, target_name AS species_code
FROM sklearn.preprocessing.ordinal_encoder((SELECT sample_id, target_name FROM sklearn.datasets.iris()), id => 'sample_id');
Link
pca (data TABLE, id := VARCHAR, n_components := BIGINT) 2 examples

Principal component analysis (linear dimensionality reduction)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_components := BIGINT
Number of components to keep. Β· default 2
Returns columns
component_<i> DOUBLE
Projection onto component i (one per kept component).
Returns columns Β· depends on the arguments
component_<i> DOUBLE
Projection onto component i (one per kept component).
Examples (2)

Apply pca to the iris features

SELECT sample_id, component_1, component_2
FROM sklearn.preprocessing.pca((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_components => 2);

Standardize the iris measurements, project them onto 2 principal components, and average each component per species (the first component separates the species)

SELECT i.target_name, round(avg(p.component_1), 2) AS mean_pc1,
  round(avg(p.component_2), 2) AS mean_pc2
FROM sklearn.preprocessing.pca((SELECT * FROM sklearn.preprocessing.standard_scaler((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id := 'sample_id')), id := 'sample_id', n_components := 2) AS p
JOIN sklearn.datasets.iris AS i USING (sample_id)
GROUP BY i.target_name
ORDER BY mean_pc1;
Link
polynomial_features (data TABLE, degree := BIGINT, id := VARCHAR, include_bias := BOOLEAN, interaction_only := BOOLEAN) 1 example

Expand features into polynomial and interaction terms (e.g. a, b -> a, b, a^2, a*b, b^2)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
degree := BIGINT
Maximum degree of the polynomial features. Β· default 2
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
include_bias := BOOLEAN
Include the constant (all-ones) bias column. Β· default false
interaction_only := BOOLEAN
Only products of distinct features. Β· default false
Returns columns
<term> DOUBLE
One column per generated polynomial/interaction term, named from the input features (e.g. `a`, `b`, `a_pow2`, `a_x_b`).
Returns columns Β· depends on the arguments
<term> DOUBLE
One column per generated polynomial/interaction term, named from the input features (e.g. `a`, `b`, `a_pow2`, `a_x_b`).
Example

Apply polynomial_features to the iris features

SELECT sample_id, sepal_length_cm_pow2, sepal_length_cm_x_sepal_width_cm
FROM sklearn.preprocessing.polynomial_features((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', degree => 2);
Link
power_transformer (data TABLE, id := VARCHAR, method := VARCHAR) 1 example

Make features more Gaussian via a power transform (Yeo-Johnson / Box-Cox)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
method := VARCHAR
'yeo-johnson' (any sign) or 'box-cox' (>0). Β· default "yeo-johnson"
Returns columns
<feature> DOUBLE
One column per input feature (same name as the input): the transformed value.
Returns columns Β· depends on the arguments
<feature> DOUBLE
One column per input feature (same name as the input): the transformed value.
Example

Apply power_transformer to the iris features

SELECT sample_id, sepal_length_cm, petal_length_cm
FROM sklearn.preprocessing.power_transformer((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', method => 'yeo-johnson');
Link
quantile_transformer (data TABLE, id := VARCHAR, n_quantiles := BIGINT, output_distribution := VARCHAR) 1 example

Map features to a uniform or normal distribution via quantiles (robust to outliers)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_quantiles := BIGINT
Number of quantiles (capped at n_samples). Β· default 1000
output_distribution := VARCHAR
'uniform' or 'normal'. Β· default "uniform"
Returns columns
<feature> DOUBLE
One column per input feature (same name as the input): the transformed value.
Returns columns Β· depends on the arguments
<feature> DOUBLE
One column per input feature (same name as the input): the transformed value.
Example

Apply quantile_transformer to the iris features

SELECT sample_id, sepal_length_cm, petal_length_cm
FROM sklearn.preprocessing.quantile_transformer((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', output_distribution => 'normal');
Link
robust_scaler (data TABLE, id := VARCHAR) 1 example

Scale features using statistics robust to outliers (median/IQR)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
Returns columns
<feature> DOUBLE
One column per input feature (same name as the input): the scaled value.
Returns columns Β· depends on the arguments
<feature> DOUBLE
One column per input feature (same name as the input): the scaled value.
Example

Apply robust_scaler to the iris features

SELECT sample_id, sepal_length_cm, petal_length_cm
FROM sklearn.preprocessing.robust_scaler((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id');
Link
select_k_best (data TABLE, id := VARCHAR, k := BIGINT, score_func := VARCHAR, target := VARCHAR) 1 example

Univariate feature scores vs. the target, flagging the top k

Positional arguments
data TABLE
Feature columns plus the target column.
Named arguments
id := VARCHAR
Optional id column to exclude from features. Β· default ""
k := BIGINT
Number of top features to flag as selected (capped at n_features). Β· default 10
score_func := VARCHAR
Univariate test used to score each feature. Β· default "f_classif"
target := VARCHAR
Name of the target/label column (required). Β· default ""
Returns columns
feature VARCHAR
Feature column name.
score DOUBLE
Univariate score (higher = more informative).
p_value DOUBLE
p-value of the score (NULL for mutual-information scorers).
selected BOOLEAN
True if among the top-k features.
Example

Rank iris features by ANOVA F against the species label

SELECT feature, score, selected
FROM sklearn.preprocessing.select_k_best((SELECT sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), target := 'target', k := 2)
ORDER BY score DESC;
Link
simple_imputer (data TABLE, id := VARCHAR, strategy := VARCHAR) 1 example

Fill missing (NULL/NaN) feature values using a column statistic

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
strategy := VARCHAR
How missing values are filled. Β· default "mean"
Returns columns
<feature> DOUBLE
One column per input feature (same name as the input): the imputed value.
Returns columns Β· depends on the arguments
<feature> DOUBLE
One column per input feature (same name as the input): the imputed value.
Example

Apply simple_imputer to the iris features

SELECT sample_id, sepal_length_cm, petal_length_cm
FROM sklearn.preprocessing.simple_imputer((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', strategy => 'median');
Link
spectral_clustering (data TABLE, id := VARCHAR, n_clusters := BIGINT, random_state := BIGINT) 1 example

Spectral clustering on the affinity graph; emits a cluster label per row

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_clusters := BIGINT
Number of clusters. Β· default 2
random_state := BIGINT
Random seed. Β· default 0
Returns columns
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Returns columns Β· depends on the arguments
cluster INTEGER
Assigned cluster label (-1 = noise for density methods).
Example

Apply spectral_clustering to the iris features

SELECT cluster, count(*) AS n_samples
FROM sklearn.preprocessing.spectral_clustering((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_clusters => 3)
GROUP BY cluster
ORDER BY cluster;
Link
spectral_embedding (data TABLE, id := VARCHAR, n_components := BIGINT, random_state := BIGINT) 1 example

Spectral (Laplacian eigenmaps) non-linear embedding

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_components := BIGINT
Number of components to keep. Β· default 2
random_state := BIGINT
Random seed. Β· default 0
Returns columns
component_<i> DOUBLE
Projection onto component i (one per kept component).
Returns columns Β· depends on the arguments
component_<i> DOUBLE
Projection onto component i (one per kept component).
Example

Apply spectral_embedding to the iris features

SELECT sample_id, component_1, component_2
FROM sklearn.preprocessing.spectral_embedding((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_components => 2);
Link
standard_scaler (data TABLE, id := VARCHAR) 1 example

Standardize features to zero mean and unit variance

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
Returns columns
<feature> DOUBLE
One column per input feature (same name as the input): the scaled value.
Returns columns Β· depends on the arguments
<feature> DOUBLE
One column per input feature (same name as the input): the scaled value.
Example

Apply standard_scaler to the iris features

SELECT sample_id, sepal_length_cm, petal_length_cm
FROM sklearn.preprocessing.standard_scaler((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id');
Link
target_encoder (data TABLE, id := VARCHAR, target := VARCHAR) 1 example

Encode each categorical column by its (cross-fitted) mean target value

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
target := VARCHAR
Target column to encode against (required). Β· default ""
Returns columns
<feature> DOUBLE
One column per input feature (same name as the input): the target-mean encoding.
Returns columns Β· depends on the arguments
<feature> DOUBLE
One column per input feature (same name as the input): the target-mean encoding.
Example

Encode the species name by its rate of a binary is-setosa target

SELECT sample_id, target_name AS setosa_rate
FROM sklearn.preprocessing.target_encoder((SELECT sample_id, target_name, (target = 0)::INTEGER AS is_setosa FROM sklearn.datasets.iris()), id := 'sample_id', target := 'is_setosa');
Link
tfidf_vectorizer (data TABLE, id := VARCHAR, lowercase := BOOLEAN, max_df := DOUBLE, max_features := BIGINT, min_df := BIGINT, ngram_max := BIGINT, stop_words := VARCHAR, text := VARCHAR) 1 example

Tokenize a text column into a TF-IDF document-term matrix (long format)

Positional arguments
data TABLE
An id column and a text column.
Named arguments
id := VARCHAR
Optional id column to carry onto each emitted row. Β· default ""
lowercase := BOOLEAN
Lowercase before tokenizing. Β· default true
max_df := DOUBLE
Ignore terms in more than this fraction of documents. Β· default 1.0
max_features := BIGINT
Keep only the top-N terms by frequency; 0 = all. Β· default 0
min_df := BIGINT
Ignore terms in fewer than this many documents. Β· default 1
ngram_max := BIGINT
Max n-gram size (uses ngram_range=(1, ngram_max)). Β· default 1
stop_words := VARCHAR
'english' to drop English stop words; '' for none. Β· default ""
text := VARCHAR
Text column to vectorize (defaults to the single non-id column). Β· default ""
Returns columns
term VARCHAR
Vocabulary term (or n-gram).
value DOUBLE
TF-IDF weight of the term in the document.
Returns columns Β· depends on the arguments
term VARCHAR
Vocabulary term (or n-gram).
value DOUBLE
TF-IDF weight of the term in the document.
Example

Heavily weighted TF-IDF terms per document

SELECT id, term, value
FROM sklearn.preprocessing.tfidf_vectorizer((SELECT * FROM (VALUES (1, 'the cat sat on the mat'), (2, 'a quick brown dog')) AS docs(id, body)), id := 'id', text := 'body')
WHERE value > 0.3;
Link
truncated_svd (data TABLE, id := VARCHAR, n_components := BIGINT) 1 example

Truncated SVD (LSA) dimensionality reduction

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_components := BIGINT
Number of components to keep. Β· default 2
Returns columns
component_<i> DOUBLE
Projection onto component i (one per kept component).
Returns columns Β· depends on the arguments
component_<i> DOUBLE
Projection onto component i (one per kept component).
Example

Apply truncated_svd to the iris features

SELECT sample_id, component_1, component_2
FROM sklearn.preprocessing.truncated_svd((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_components => 2);
Link
tsne (data TABLE, id := VARCHAR, n_components := BIGINT, perplexity := DOUBLE, random_state := BIGINT) 1 example

t-SNE non-linear embedding (great for 2-D visualization)

Positional arguments
data TABLE
Input rows; each non-id column is a feature
Named arguments
id := VARCHAR
Optional column to carry through unchanged to the output Β· default ""
n_components := BIGINT
Number of components to keep. Β· default 2
perplexity := DOUBLE
Nearest-neighbour count proxy (< n_samples). Β· default 30.0
random_state := BIGINT
Random seed. Β· default 0
Returns columns
component_<i> DOUBLE
Projection onto component i (one per kept component).
Returns columns Β· depends on the arguments
component_<i> DOUBLE
Projection onto component i (one per kept component).
Example

Apply tsne to the iris features

SELECT sample_id, component_1, component_2
FROM sklearn.preprocessing.tsne((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id => 'sample_id', n_components => 2);
Link
variance_threshold (data TABLE, id := VARCHAR, threshold := DOUBLE) 1 example

Per-feature variance, flagging features above a threshold (unsupervised filter)

Positional arguments
data TABLE
Feature columns.
Named arguments
id := VARCHAR
Optional id column to exclude from features. Β· default ""
threshold := DOUBLE
Keep features with variance strictly above this. Β· default 0.0
Returns columns
feature VARCHAR
Feature column name.
variance DOUBLE
Variance of the feature.
selected BOOLEAN
True if variance exceeds the threshold.
Example

Flag iris features whose variance exceeds 0.5

SELECT feature, variance, selected
FROM sklearn.preprocessing.variance_threshold((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id := 'sample_id', threshold := 0.5)
ORDER BY variance DESC;
Link

Try these queries

Load the built-in iris dataset.

SELECT * FROM sklearn.datasets.iris() LIMIT 5;

Coefficient of determination over inline (actual, predicted) pairs.

SELECT sklearn.metrics.r2_score(actual, predicted)
FROM (VALUES (3.0, 2.5), (5.0, 5.1), (7.0, 6.8)) AS t(actual, predicted);

Uses r2_score

Reduce iris to two principal components (fit-transform).

SELECT *
FROM sklearn.preprocessing.pca((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), n_components := 2, id := 'sample_id')
LIMIT 5;

Uses pca

Three-fold cross-validated accuracy of a logistic-regression classifier on iris.

SELECT fold, score
FROM sklearn.models.cross_val_score((SELECT * FROM sklearn.datasets.iris()), estimator := 'logistic_regression', target := 'target', cv := 3);

Uses cross_val_score

Confusion matrix of 5-fold out-of-fold logistic-regression predictions on iris: each prediction joined back to its true species, one row per (actual, predicted) species code with its count

SELECT actual, predicted, count
FROM sklearn.metrics.confusion_matrix((SELECT i.target AS species, p.prediction AS predicted_species FROM sklearn.models.cross_val_predict((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm, target FROM sklearn.datasets.iris()), estimator := 'logistic_regression', target := 'target', id := 'sample_id') AS p JOIN sklearn.datasets.iris AS i USING (sample_id)), actual := 'species', predicted := 'predicted_species')
ORDER BY actual, predicted;

Uses confusion_matrixcross_val_predictiris

Score 3-cluster k-means on the iris measurements against the true species: adjusted Rand index, homogeneity, and completeness of the clusters (one row)

SELECT round(sklearn.metrics.adjusted_rand_score(i.target, k.cluster), 3) AS adjusted_rand,
  round(sklearn.metrics.homogeneity_score(i.target, k.cluster), 3) AS homogeneity,
  round(sklearn.metrics.completeness_score(i.target, k.cluster), 3) AS completeness
FROM sklearn.preprocessing.kmeans((SELECT sample_id, sepal_length_cm, sepal_width_cm, petal_length_cm, petal_width_cm FROM sklearn.datasets.iris()), id := 'sample_id', n_clusters := 3) AS k
JOIN sklearn.datasets.iris AS i USING (sample_id);

Uses adjusted_rand_scorehomogeneity_scorecompleteness_scorekmeansiris

164 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Using the scikit-learn worker's built-in iris dataset, how many flowers of each species are there? Return one row per species name with its count.
  • Cluster the iris flowers into 3 groups with k-means using only the four flower measurements. Return the size of each cluster, largest first.

scikit-learn is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.