Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ml-logistic-regression

mljs41.1kMIT2.0.0

Logistic regression

machine learning, logistic regression, classification, classifier

readme

logistic-regression

NPM version build status Test coverage npm download

This is an implementation of the logistic regression. When there are more than 2 classes, the method used is the One VS All.

Installation

$ npm i ml-logistic-regression

Usage

const { Matrix } = require('ml-matrix');

// Our training set (X,Y).
const X = new Matrix([[0, -1], [1, 0], [1, 1], [1, -1], [2, 0], [2, 1], [2, -1], [3, 2], [0, 4], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 4], [1, 10], [1, 12], [2, 10], [2, 11], [2, 14], [3, 11]]);
const Y = Matrix.columnVector([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]);

// The test set (Xtest, Ytest).
const Xtest = new Matrix([
  [0, -2],
  [1, 0.5],
  [1.5, -1],
  [1, 2.5],
  [2, 3.5],
  [1.5, 4],
  [1, 10.5],
  [2.5, 10.5],
  [2, 11.5],
]);
const Ytest = Matrix.columnVector([0, 0, 0, 1, 1, 1, 2, 2, 2]);

// We will train our model.
const logreg = new LogisticRegression({ numSteps: 1000, learningRate: 5e-3 });
logreg.train(X, Y);

// We try to predict the test set.
const finalResults = logreg.predict(Xtest);

// Now, you can compare finalResults with the Ytest, which is what you wanted to have.

License

MIT

changelog

2.0.0 (2020-05-03)

Bug Fixes

1.0.2 (2017-07-21)

Bug Fixes

1.0.1 (2017-07-21)

1.0.0 (2017-07-21)

Bug Fixes

  • fix errors in the tests (836177f)
  • modifications to use jest (e19dc5a)
  • Modify name of methods. test() become predict() (a6aca4c)
  • modify number of steps of the tests (and add the second test) (c175f82)
  • Update tests to enable 'npm test' (d3ac5f9)

Features

  • Add the logistic regression (78c250c)
  • add toJSON() and load() (214a00e)