Git Product home page Git Product logo

maxgfr / similarities Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1.05 MB

This package contains functions to find similarities between arrays

Home Page: https://www.npmjs.com/package/similarities

License: MIT License

JavaScript 2.31% TypeScript 97.69%
array-comparison node pearson-correlation similarities typescript combinatorics pearson pearson-coefficient pearson-correlation-coefficient

similarities's Introduction

similarities

This package contains functions to find similarities between arrays. Three functions are available: findSimilarities and pearsonCorrelationNumber/pearsonCorrelationString.

Installation

yarn add similarities

Find similarities in arrays

The findSimilarities function takes in two arrays, arrayA and arrayB, and returns an array of objects containing all possible combinations of elements from arrayA and the percentage of similarities between each combination and arrayB.

import { findSimilarities } from 'similarities';

const arrayA = ['dog', 'cat', 'bird'];
const arrayB = ['bird', 'horse', 'tiger'];
const result = findSimilarities(arrayA, arrayB);
console.log(result);
// Output:
// [
//   { item: ['bird'], similarities: 33.33333333333333 },
//   { item: ['bird', 'cat'], similarities: 33.33333333333333 },
//   { item: ['cat'], similarities: 0 },
//   { item: ['bird', 'dog'], similarities: 33.33333333333333 },
//   { item: ['bird', 'cat', 'dog'], similarities: 33.33333333333333 },
//   { item: ['cat', 'dog'], similarities: 0 },
//   { item: ['dog'], similarities: 0 },
// ]

Pearson correlation coefficient

The pearsonCorrelationNumber and pearsonCorrelationString functions take in two arrays, arrayA and arrayB, and returns the Pearson correlation coefficient between the two arrays.

import { pearsonCorrelationNumber } from 'similarities';

const arrayA = [1, 2, 3, 4, 5];
const arrayB = [1, 2, 3, 4, 5];
const result1 = pearsonCorrelationNumber(arrayA, arrayB);
console.log(result1);
// Output: 1

const arrayC = [1, 2, 3, 4, 5];
const arrayD = [5, 4, 3, 2, 1];
const result2 = pearsonCorrelationNumber(arrayC, arrayD);
console.log(result2);
// Output: -1

const arrayE = [1, 2, 3, 4, 5];
const arrayF = [1, 2, 3, 4, 6];
const result3 = pearsonCorrelationNumber(arrayE, arrayF);
console.log(result3);
// Output: 0.99498743710662

It also works with strings.

import { pearsonCorrelationString } from 'similarities';

const arrayA = ['a', 'b', 'c'];
const arrayB = ['c', 'b', 'a'];
const result = pearsonCorrelationString(arrayA, arrayB);
console.log(result);
// Output: -1

similarities's People

Contributors

maxgfr avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar

Watchers

 avatar

similarities's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/build.yml
  • actions/checkout v3
.github/workflows/codeql-analysis.yml
  • actions/checkout v3
  • github/codeql-action v2
  • github/codeql-action v2
  • github/codeql-action v2
.github/workflows/lint.yml
  • actions/checkout v3
.github/workflows/publish.yml
  • actions/checkout v3
.github/workflows/test.yml
  • actions/checkout v3
npm
package.json
  • @semantic-release/changelog ^6.0.2
  • @semantic-release/commit-analyzer ^10.0.0
  • @semantic-release/git ^10.0.1
  • @semantic-release/github ^9.0.0
  • @semantic-release/npm ^10.0.0
  • @semantic-release/release-notes-generator ^11.0.0
  • @swc-node/register 1.9.1
  • @swc/cli 0.3.12
  • @swc/core 1.5.7
  • @swc/jest 0.2.36
  • @types/jest 29.5.12
  • @types/node 18.19.33
  • @typescript-eslint/eslint-plugin 5.62.0
  • @typescript-eslint/parser 5.62.0
  • eslint 8.57.0
  • eslint-config-prettier 8.10.0
  • eslint-plugin-jest 27.9.0
  • jest 29.7.0
  • nodemon 3.1.0
  • prettier 3.2.5
  • rimraf 5.0.7
  • semantic-release 21.1.2
  • typescript 5.4.5

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.