New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mse-ts

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mse-ts

Typed mean squared error estimator

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Mean Squared Error

Mean Squared Error estimation function + type definitions.

Build

Installing

$ npm install mse-ts

Importing the package

Using import
import mse from 'mse-ts';
Using require
const mse = require('mse-ts');

Usage

Calculating MSE - Example 1
import mse from 'mse-ts';

const y_true = [3, -0.5, 2, 7];
const y_pred = [2.5, 0.0, 2, 8];

const meanSquaredError = mse(y_true, y_pred);
console.log(meanSquaredError);

output

0.375
Calculating MSE - Example 2
import mse from 'mse-ts';


const y_true = [
  188, 100, 114, 171, 171, 173, 230, 149,
  191,  81,  61,  62, 127, 217,  62,  81,
  178, 159, 245,  18,   9,  86, 201, 166,
  122, 210,   4, 182,  15,  18, 135, 203,
  222, 134, 154,  21,  71, 217,  48, 153,
  113, 234, 207, 119,  51,  61, 149, 222,
  186,  38, 158,  79, 185,   1, 118, 222,
  22, 137, 110, 206,  94, 120, 163, 241
];
const y_pred = [
  188, 100, 114, 171, 171, 173, 230, 149,
  191,  81,  61,  62, 123, 217,  62,  81,
  178, 159, 245,  18,   9,  86, 201, 166,
  122, 210,   4, 200,  15,  18, 135, 203,
  222, 134, 154,  21,  71, 217,  48, 153,
  113, 234, 207, 119,  51,  61, 149, 222,
  186,  38, 158,  79, 185,   1, 118, 222,
  22, 137, 110, 206,  94, 120, 163, 241
];
const meanSquaredError = mse(y_true, y_pred);

if (meanSquaredError <> 0) {
    console.log('data sets are different by ' + meanSquaredError);
}

output

'data sets are different by 5.3125'
Steps

You may provide a custom step value

import mse from 'mse-ts';

const y_true = [3, -0.5, 2, 7];
const y_pred = [2.5, 0.0, 2, 8];

const meanSquaredError = mse(y_true, y_pred, { step: 2 });
console.log(meanSquaredError);

output

0.0625

Caveats

  • The length of y_true should always be higher than or equal to y_pred. Non-compliance will result in an yPred at index i is undefined error
  • Passing in empty arrays will return NaN

More info

Find out more about the applications of MSE over on Wikipedia: https://en.wikipedia.org/wiki/Mean_squared_error

license

MIT

Keywords

FAQs

Package last updated on 21 Feb 2021

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