# ml-regression-base

> Base class for regression modules

Latest version **4.0.1** (published 2026-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install ml-regression-base
pnpm add ml-regression-base
yarn add ml-regression-base
bun add ml-regression-base
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2026-04-16 |
| First published | 2017-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 29.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Michaël Zasso |
| Maintainers | stropitek, targos, lpatiny, mljs-bot, maasencioh, jeffersonh44, andcastillo |

## Links

- npm: https://www.npmjs.com/package/ml-regression-base
- Repository: https://github.com/mljs/regression-base
- Homepage: https://github.com/mljs/regression-base#readme
- Issues: https://github.com/mljs/regression-base/issues
- npm.io page: https://npm.io/package/ml-regression-base

## Dependencies (2)

- [is-any-array](https://npm.io/package/is-any-array.md) ^3.0.0
- [cheminfo-types](https://npm.io/package/cheminfo-types.md) ^1.15.0

## Recent versions

- 4.0.1 (latest) — 2026-04-16
- 4.0.0 — 2024-05-16
- 3.0.0 — 2023-08-15
- 2.1.6 — 2022-01-21
- 2.1.5 — 2021-11-16
- 2.1.4 — 2021-11-04
- 2.1.3 — 2021-03-24
- 2.1.2 — 2021-03-24
- 2.1.1 — 2020-02-04
- 2.1.0 — 2020-02-04
- 2.0.1 — 2019-04-30
- 2.0.0 — 2019-04-30
- 1.2.1 — 2019-04-15
- 1.2.0 — 2017-04-28
- 1.1.1 — 2017-04-28
- … 2 more at https://npm.io/package/ml-regression-base/versions

## README

# regression-base

[![NPM version][npm-image]][npm-url]
[![build status][ci-image]][ci-url]
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]

Base class for regression modules.  
This package is for ml.js internal use.

## Usage

You only have to implement the `_predict` method. It is always called with a number.

The model should be created in the constructor.

Optional methods that can be implemented: `toString`, `toLaTeX`.

```js
import BaseRegression from 'ml-regression-base';

class MyRegression extends BaseRegression {
  constructor(factor) {
    super();
    this.factor = factor;
  }
  _predict(x) {
    return x * this.factor;
  }
  toString() {
    return `f(x) = x * ${this.factor}`;
  }
}
```

### `maybeToPrecision(value, digits)`

Convenience method to transform numbers to readable strings.

If digits is not specified, "value.toString()" is used. Otherwise "value.toPrecision(digits)" is used.

This method can be used to implement `toString()` or `toLaTeX()`.

### `checkArrayLength(x, y)`

Convenience method to check if the input and output arrays passed to a regression
constructor are effectively arrays with the same length.

## License

[MIT](./LICENSE)

[npm-image]: https://img.shields.io/npm/v/ml-regression-base.svg
[npm-url]: https://npmjs.org/package/ml-regression-base
[codecov-image]: https://img.shields.io/codecov/c/github/mljs/regression-base.svg
[codecov-url]: https://codecov.io/gh/mljs/regression-base
[ci-image]: https://github.com/mljs/regression-base/workflows/Node.js%20CI/badge.svg?branch=main
[ci-url]: https://github.com/mljs/regression-base/actions?query=workflow%3A%22Node.js+CI%22
[download-image]: https://img.shields.io/npm/dm/ml-regression-base.svg
[download-url]: https://npmjs.org/package/ml-regression-base

---
_Source: https://npm.io/package/ml-regression-base · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
