Needlessly Promiscuous, Modularize!

    mse-ts
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.2 • Public • Published

    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

    Install

    npm i mse-ts

    DownloadsWeekly Downloads

    7

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    7.34 kB

    Total Files

    10

    Last publish

    Collaborators

    • deim