@kanaries/ml
API Reference/Compose

Transformed Target Regression

Train regressors on log-scaled or otherwise transformed targets in browser and Node.js applications with @kanaries/ml TransformedTargetRegressor.

View as Markdown

Algorithm overview

Regression targets are often skewed, strictly positive, or easier to model after a monotonic transformation. TransformedTargetRegressor applies that transformation during training and automatically maps predictions back to the original units.

JavaScript implementation

@kanaries/ml composes any serializable regressor with a transformer that implements fit, transform, and inverseTransform. Both components are cloned before fitting, work in browser or Node.js, and survive model serialization.

Interactive transformed-target regression playground

Compare identity and log-transformed targets on positive data, then add observations directly to the chart. Compose.TransformedTargetRegressor handles transformation, fitting, and inverse prediction live.

Live browser model

log1p → expm1 playground

Adjust the data and model, then click the chart to add a training observation.

Fitted with @kanaries/ml
-3-2-10123-0.41.22.74.25.8feature xtarget y
prediction training holdout your points
Train RMSE0.230
Holdout RMSE0.581
Holdout R²0.812
Custom points0

Quick start

import { Compose, Linear, utils } from '@kanaries/ml';

const model = new Compose.TransformedTargetRegressor({
  regressor: new Linear.LinearRegression(),
  transformer: new utils.Preprocessing.FunctionTransformer({
    func: 'log1p',
    inverseFunc: 'expm1',
  }),
});

model.fit([[0], [1], [2]], [1, 3, 7]);
model.predict([[3]]); // approximately [15]

Detailed API reference

new TransformedTargetRegressor({ regressor?, transformer?, func?, inverseFunc? }) defaults to linear regression and an identity transform. Pass either a transformer or a func/inverseFunc pair; the two forms are mutually exclusive. fit(X, y) trains cloned components, predict(X) returns inverse-transformed values, and score(X, y) reports R² in the original target space. Nested parameters use regressor__param and transformer__param in setParams.