Skip to content
Principal component analysis
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs doc: rebuild docs [ci skip] Oct 19, 2019
src chore: add regression testcase Oct 19, 2019
.babelrc
.eslintrc.yml refactor: upgrade to ml-matrix v6 Apr 18, 2019
.gitignore
.npmrc refactor: upgrade to ml-matrix v6 Apr 18, 2019
.travis.yml chore: update dependencies and test on Node 12 Jul 20, 2019
History.md 4.0.1 Oct 19, 2019
LICENSE Initial commit Oct 24, 2014
README.md refactor: upgrade to ml-matrix v6 Apr 18, 2019
package.json 4.0.1 Oct 19, 2019
pca.d.ts feat: add invert method Jul 21, 2019
rollup.config.js refactor: upgrade to ml-matrix v6 Apr 18, 2019

README.md

ml-pca

NPM version build status David deps npm download

Principal component analysis (PCA).

Installation

$ npm install ml-pca

Usage

const { PCA } = require('ml-pca');
const dataset = require('ml-dataset-iris').getNumbers();
// dataset is a two-dimensional array where rows represent the samples and columns the features
const pca = new PCA(dataset);
console.log(pca.getExplainedVariance());
/*
[ 0.9246187232017269,
  0.05306648311706785,
  0.017102609807929704,
  0.005212183873275558 ]
*/
const newPoints = [[4.9, 3.2, 1.2, 0.4], [5.4, 3.3, 1.4, 0.9]];
console.log(pca.predict(newPoints)); // project new points into the PCA space
/*
[
  [ -2.830722471866897,
    0.01139060953209596,
    0.0030369648815961603,
    -0.2817812120420965 ],
  [ -2.308002707614927,
    -0.3175048770719249,
    0.059976053412802766,
    -0.688413413360567 ]]
*/

API Documentation

License

MIT

You can’t perform that action at this time.