decomposition.PCA
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 ] ]
Constructors
Properties
Methods
Constructors
constructor
⊕ PCA()
Defined in
Parameters:
Param | Type | Default | Description |
---|
Returns: PCA
Properties
▸ components
Defined in decomposition/pca.ts:31
▸ explained_variance
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:
Param | Type | Default | Description |
---|---|---|---|
X | number[][] |
Returns:
void
λ fromJSON
Restores the model from given states
Defined in decomposition/pca.ts:91
Parameters:
Param | Type | Default | Description |
---|---|---|---|
components | number[][] | null | |
explained_variance | number[][] | null |
Returns:
void
λ predict
Predict does nothing in PCA
Defined in decomposition/pca.ts:68
Parameters:
Param | Type | Default | Description |
---|---|---|---|
X | number[][] | null | A 2D matrix |
Returns:
number[][]
λ toJSON
Saves the model's states
Defined in decomposition/pca.ts:76
Returns:
Param | Type | Description |
---|---|---|
components | number[][] | undefined |
explained_variance | number[][] | undefined |