🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

ml-distance

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-distance

Distance and similarity functions to compare vectors

4.0.1
latest
Version published
Weekly downloads
133K
-23.25%
Maintainers
8
Weekly downloads
 
Created

What is ml-distance?

The ml-distance npm package provides a collection of functions to calculate various types of distances between vectors. It is useful for tasks in machine learning, data analysis, and other fields where measuring similarity or dissimilarity between data points is important.

What are ml-distance's main functionalities?

Euclidean Distance

Calculates the Euclidean distance between two vectors. This is the straight-line distance in Euclidean space.

const distance = require('ml-distance');
const euclidean = distance.euclidean([1, 2], [4, 6]);
console.log(euclidean); // Output: 5

Manhattan Distance

Calculates the Manhattan distance between two vectors. This is the sum of the absolute differences of their Cartesian coordinates.

const distance = require('ml-distance');
const manhattan = distance.manhattan([1, 2], [4, 6]);
console.log(manhattan); // Output: 7

Cosine Similarity

Calculates the cosine similarity between two vectors. This measures the cosine of the angle between them, which is useful for determining how similar two vectors are.

const distance = require('ml-distance');
const cosine = distance.cosine([1, 2], [4, 6]);
console.log(cosine); // Output: 0.9838699100999074

Jaccard Index

Calculates the Jaccard index between two sets. This is the size of the intersection divided by the size of the union of the sets.

const distance = require('ml-distance');
const jaccard = distance.jaccard([1, 2, 3], [2, 3, 4]);
console.log(jaccard); // Output: 0.5

Other packages similar to ml-distance

FAQs

Package last updated on 01 Jun 2023

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