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

ml-array-variance

Package Overview
Dependencies
Maintainers
5
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-array-variance - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

CHANGELOG.md

31

lib/index.js

@@ -15,21 +15,18 @@ 'use strict';

*/
var index = function (values, options = {}) {
const {
unbiased = true,
mean = arrayMean(values)
} = options;
var sqrError = 0;
function variance(values, options = {}) {
const { unbiased = true, mean = arrayMean(values) } = options;
var sqrError = 0;
for (var i = 0; i < values.length; i++) {
var x = values[i] - mean;
sqrError += x * x;
}
for (var i = 0; i < values.length; i++) {
var x = values[i] - mean;
sqrError += x * x;
}
if (unbiased) {
return sqrError / (values.length - 1);
} else {
return sqrError / values.length;
}
};
if (unbiased) {
return sqrError / (values.length - 1);
} else {
return sqrError / values.length;
}
}
module.exports = index;
module.exports = variance;
{
"name": "ml-array-variance",
"version": "1.0.0",
"version": "1.0.1",
"description": "Get the variance in an array",

@@ -23,4 +23,4 @@ "main": "lib/index.js",

"dependencies": {
"ml-array-mean": "^1.0.1"
"ml-array-mean": "^1.0.2"
}
}

@@ -5,6 +5,6 @@ import variance from '..';

test('variance', () => {
var v = variance(data);
expect(v).toBeCloseTo(18.667, 3);
expect(variance(data, {unbiased: true})).toBe(v);
expect(variance(data, {unbiased: false})).toBe(14);
var v = variance(data);
expect(v).toBeCloseTo(18.667, 3);
expect(variance(data, { unbiased: true })).toBe(v);
expect(variance(data, { unbiased: false })).toBe(14);
});

@@ -11,19 +11,16 @@ import arrayMean from 'ml-array-mean';

*/
export default function (values, options = {}) {
const {
unbiased = true,
mean = arrayMean(values)
} = options;
var sqrError = 0;
export default function variance(values, options = {}) {
const { unbiased = true, mean = arrayMean(values) } = options;
var sqrError = 0;
for (var i = 0; i < values.length; i++) {
var x = values[i] - mean;
sqrError += x * x;
}
for (var i = 0; i < values.length; i++) {
var x = values[i] - mean;
sqrError += x * x;
}
if (unbiased) {
return sqrError / (values.length - 1);
} else {
return sqrError / values.length;
}
if (unbiased) {
return sqrError / (values.length - 1);
} else {
return sqrError / values.length;
}
}
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