|
1 | 1 | # logistic-regression
|
2 | 2 |
|
3 |
| - [![NPM version][npm-image]][npm-url] |
4 |
| - [![build status][travis-image]][travis-url] |
5 |
| - [![npm download][download-image]][download-url] |
| 3 | +[![NPM version][npm-image]][npm-url] |
| 4 | +[![build status][ci-image]][ci-url] |
| 5 | +[![Test coverage][codecov-image]][codecov-url] |
| 6 | +[![npm download][download-image]][download-url] |
6 | 7 |
|
7 |
| -This is an implementation of the logistic regression. When there are more than 2 classes, the method used is the *One VS All*. |
| 8 | +This is an implementation of the logistic regression. When there are more than 2 classes, the method used is the _One VS All_. |
8 | 9 |
|
9 | 10 | ## Installation
|
10 | 11 |
|
11 |
| -`$ npm install --save ml-logistic-regression` |
| 12 | +`$ npm i ml-logistic-regression` |
12 | 13 |
|
13 | 14 | ## Usage
|
14 | 15 |
|
15 |
| -```javascript |
16 |
| -const {Matrix} = require('ml-matrix'); |
| 16 | +```js |
| 17 | +const { Matrix } = require('ml-matrix'); |
| 18 | + |
| 19 | +// Our training set (X,Y). |
| 20 | +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]]); |
| 21 | +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]); |
| 22 | + |
| 23 | +// The test set (Xtest, Ytest). |
| 24 | +const Xtest = new Matrix([ |
| 25 | + [0, -2], |
| 26 | + [1, 0.5], |
| 27 | + [1.5, -1], |
| 28 | + [1, 2.5], |
| 29 | + [2, 3.5], |
| 30 | + [1.5, 4], |
| 31 | + [1, 10.5], |
| 32 | + [2.5, 10.5], |
| 33 | + [2, 11.5], |
| 34 | +]); |
| 35 | +const Ytest = Matrix.columnVector([0, 0, 0, 1, 1, 1, 2, 2, 2]); |
| 36 | + |
| 37 | +// We will train our model. |
| 38 | +const logreg = new LogisticRegression({ numSteps: 1000, learningRate: 5e-3 }); |
| 39 | +logreg.train(X, Y); |
| 40 | + |
| 41 | +// We try to predict the test set. |
| 42 | +const finalResults = logreg.predict(Xtest); |
17 | 43 |
|
18 |
| -// our training set (X,Y) |
19 |
| -var 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]]); |
20 |
| -var 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]); |
21 |
| - |
22 |
| -// the test set (Xtest, Ytest) |
23 |
| -var 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]]) |
24 |
| -var Ytest = Matrix.columnVector([0, 0, 0, 1, 1, 1, 2, 2, 2]); |
25 |
| - |
26 |
| -// we will train our model |
27 |
| -var logreg = new LogisticRegression({numSteps: 1000, learningRate: 5e-3}); |
28 |
| -logreg.train(X,Y); |
29 |
| - |
30 |
| -// we try to predict the test set |
31 |
| -var finalResults = logreg.predict(Xtest); |
32 | 44 | // Now, you can compare finalResults with the Ytest, which is what you wanted to have.
|
33 | 45 | ```
|
34 | 46 |
|
35 | 47 | ## License
|
36 | 48 |
|
37 |
| - [MIT](./LICENSE) |
| 49 | +[MIT](./LICENSE) |
38 | 50 |
|
39 |
| -[npm-image]: https://img.shields.io/npm/v/ml-logistic-regression.svg?style=flat-square |
| 51 | +[npm-image]: https://img.shields.io/npm/v/ml-logistic-regression.svg |
40 | 52 | [npm-url]: https://npmjs.org/package/ml-logistic-regression
|
41 |
| -[travis-image]: https://img.shields.io/travis/mljs/logistic-regression/master.svg?style=flat-square |
42 |
| -[travis-url]: https://travis-ci.org/mljs/logistic-regression |
43 |
| -[download-image]: https://img.shields.io/npm/dm/ml-logistic-regression.svg?style=flat-square |
| 53 | +[ci-image]: https://github.com/mljs/logistic-regression/workflows/Node.js%20CI/badge.svg?branch=master |
| 54 | +[ci-url]: https://github.com/mljs/logistic-regression/actions?query=workflow%3A%22Node.js+CI%22 |
| 55 | +[codecov-image]: https://img.shields.io/codecov/c/github/mljs/logistic-regression.svg |
| 56 | +[codecov-url]: https://codecov.io/gh/mljs/logistic-regression |
| 57 | +[download-image]: https://img.shields.io/npm/dm/ml-logistic-regression.svg |
44 | 58 | [download-url]: https://npmjs.org/package/ml-logistic-regression
|
0 commit comments