Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pw-lda

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pw-lda

Linear discriminant analysis

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

pw-lda

Linear discriminant analysis in JavaScript

Installation

npm install pw-lda

Getting Started

Two-dimensions are used in the below example, but any number of dimensions may be used.

LDA support both binary and multiclass classification. For multiclass classification, a pairwise voting system is used to extend the binary classifier to multiclass.

const LDA = require('pw-lda');

// Example with 2 classes

let class1 = [
	[0, 0],
	[1, 2],
	[2, 2],
	[1.5, 0.5]
];

let class2 = [
	[8, 8],
	[9, 10],
	[7, 8],
	[9, 9]
];

let classifier = new LDA(class1, class2);

let unknownPoints = [
	[-1, 0],
	[1.5, 2],
	[3, 3],
	[5, 5],
	[7, 9],
	[10, 12]
];

let predictions = [];

for(let i = 0; i < unknownPoints.length; i++){
	predictions.push(classifier.classify(unknownPoints[i]));
}

console.log(predictions); // [ 0, 0, 0, 1, 1, 1 ]

// Extending to a multiclass example

let class3 = [
	[-1, 10],
	[0, 12],
	[1, 11],
	[0.5, 9]
];

unknownPoints = unknownPoints.concat([
	[0, 11],
	[-1, 8],
	[1, 9]
]);

classifier = new LDA(class1, class2, class3);

predictions = [];

for(let i = 0; i < unknownPoints.length; i++){
	predictions.push(classifier.classify(unknownPoints[i]));
}

console.log(predictions); // [ 0, 0, 0, 1, 1, 1, 2, 2, 2 ]

Documentation

Documentation is available at http://pwstegman.me/pw-lda/

Keywords

FAQs

Package last updated on 17 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc