decomposition.PCA

Principal component analysis (PCA) Linear dimensionality reduction using Singular Value Decomposition of the data to project it to a lower dimensional space.

  • It uses the LAPACK implementation of the full SVD
  • or randomized a randomised truncated SVD by the method of Halko et al. 2009, depending on the shape of the input data and the number of components to extract. (Will be implemented)

Usage

import { PCA } from 'machinelearn/decomposition';

const pca = new PCA();
const X = [[1, 2], [3, 4], [5, 6]];
pca.fit(X);
console.log(pca.components); // result: [ [ 0.7071067811865476, 0.7071067811865474 ], [ 0.7071067811865474, -0.7071067811865476 ] ]
console.log(pca.explained_variance); // result: [ [ -0.3535533905932736, 0 ], [ 0, 0.5 ], [ 0.35355339059327373, 0 ] ]

Properties

Methods

Properties


▸ components

Principal axes in feature space, representing the directions of maximum variance in the data. The components are sorted by explained_variance_.

Defined in decomposition/pca.ts:31

▸ explained_variance

The amount of variance explained by each of the selected components.

Equal to n_components largest eigenvalues of the covariance matrix of X.

Defined in decomposition/pca.ts:38

Methods


λ fit

Fit the model with X. At the moment it does not take n_components into consideration so it will only calculate Singular value decomposition

Defined in decomposition/pca.ts:46

Parameters:

ParamTypeDefaultDescription
Xnumber[][]

Returns:

void

λ fromJSON

Restores the model from given states

Defined in decomposition/pca.ts:91

Parameters:

ParamTypeDefaultDescription
options.componentsnumber[][]nullPrincipal axes in feature space, representing the directions of maximum variance in the data.
options.explainedvariancenumber[][]nullThe amount of variance explained by each of the selected components.

Returns:

void

λ predict

Predict does nothing in PCA

Defined in decomposition/pca.ts:68

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullA 2D matrix

Returns:

number[][]

λ toJSON

Saves the model's states

Defined in decomposition/pca.ts:76

Returns:

ParamTypeDescription
componentsnumber[][]undefined
explained_variancenumber[][]undefined