---
title: "RegressorChain in JavaScript and TypeScript"
description: "Predict related numeric targets with the @kanaries/ml JavaScript RegressorChain implementation in browser or Node.js."
canonical_url: "https://ml.kanaries.net/docs/apis/multioutput/regressorChain"
markdown_url: "https://ml.kanaries.net/docs/apis/multioutput/regressorChain.md"
---
# RegressorChain in JavaScript

## Algorithm overview

A regressor chain fits one model per target and appends earlier target values or predictions as features for later members. This can capture dependencies that independent multi-output regressors miss.

## JavaScript implementation

`@kanaries/ml` accepts a registered single-output regressor and supports explicit or seeded random chain order. Set `cv` to use out-of-fold predictions while building training extensions.

## Interactive regressor chain playground

Tune the Ridge base estimator and modify the dataset below. A two-output `MultiOutput.RegressorChain` is fitted live; the chart displays its first target while both outputs participate in the chain.

> The HTML version includes an interactive Regressor Chain playground powered by @kanaries/ml. You can change the dataset, noise, and model controls; add observations; and inspect live predictions plus train and holdout metrics. The runnable guide and API reference continue below. [Open the HTML page](https://ml.kanaries.net/docs/apis/multioutput/regressorChain).

## Quick start example

```ts
import { Linear, MultiOutput } from '@kanaries/ml';

const X = [[0], [1], [2], [3]];
const targets = [[0, 1], [1, 3], [2, 5], [3, 7]];
const testX = [[4]];
const chain = new MultiOutput.RegressorChain({
  estimator: new Linear.RidgeRegression({ alpha: 1 }), order: [1, 0],
});
chain.fit(X, targets);
const predictions = chain.predict(testX);
console.log(predictions);
```

## Detailed API reference

Options: `estimator`, `order?: number[] | 'random'`, `cv?: number | null`, and `randomState`. Methods: `fit(X, Y)`, `predict(X)`, and mean-output `score(X, Y)`. Learned `chainOrder` and `estimators` are available as defensive arrays. Ridge regression is a safe base choice when true earlier targets make augmented columns collinear.
