Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nyan-left/mse-ts
Node package for a mean squared error estimation function + type definitions.
https://github.com/nyan-left/mse-ts
Last synced: 21 days ago
JSON representation
Node package for a mean squared error estimation function + type definitions.
- Host: GitHub
- URL: https://github.com/nyan-left/mse-ts
- Owner: nyan-left
- License: mit
- Created: 2021-02-21T04:42:19.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-21T09:01:14.000Z (almost 4 years ago)
- Last Synced: 2024-10-31T14:43:23.181Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 134 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Mean Squared Error
Mean Squared Error estimation function + type definitions.
[![Build](https://github.com/nyan-left/mse-ts/actions/workflows/test.yml/badge.svg)](https://github.com/nyan-left/mse-ts/actions/workflows/test.yml)
## Installing
```bash
$ npm install mse-ts
```## Importing the package
#### Using import
```ts
import mse from 'mse-ts';
```#### Using require
```js
const mse = require('mse-ts');
```## Usage
#### Calculating MSE - Example 1
```ts
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
```shell
0.375
```#### Calculating MSE - Example 2
```ts
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
```shell
'data sets are different by 5.3125'
```#### Steps
You may provide a custom step value
```ts
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
```shell
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