Transformed Target Regression
Train regressors on log-scaled or otherwise transformed targets in browser and Node.js applications with @kanaries/ml TransformedTargetRegressor.
View as MarkdownAlgorithm 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.
log1p → expm1 playground
Adjust the data and model, then click the chart to add a training observation.
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.
Gaussian and Sparse Random Projection
Reduce high-dimensional data with Johnson-Lindenstrauss Gaussian or sparse random projections in JavaScript and TypeScript.
Manifold Learning
Explore t-SNE, MDS, Spectral Embedding, and Locally Linear Embedding in JavaScript and TypeScript with @kanaries/ml for visualization and neighborhood analysis.