You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

ml-regression-base

Package Overview
Dependencies
Maintainers
7
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-regression-base - npm Package Compare versions

Comparing version

to
3.0.0

lib-esm/checkArrayLength.d.ts

195

lib/index.js

@@ -1,121 +0,90 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isAnyArray = require('is-any-array');
function maybeToPrecision(value, digits) {
if (value < 0) {
value = 0 - value;
if (typeof digits === 'number') {
return `- ${value.toPrecision(digits)}`;
} else {
return `- ${value.toString()}`;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkArrayLength = exports.maybeToPrecision = void 0;
const is_any_array_1 = require("is-any-array");
const checkArrayLength_1 = __importDefault(require("./checkArrayLength"));
exports.checkArrayLength = checkArrayLength_1.default;
var maybeToPrecision_1 = require("./maybeToPrecision");
Object.defineProperty(exports, "maybeToPrecision", { enumerable: true, get: function () { return __importDefault(maybeToPrecision_1).default; } });
class BaseRegression {
constructor() {
if (new.target === BaseRegression) {
throw new Error('BaseRegression must be subclassed');
}
}
} else {
if (typeof digits === 'number') {
return value.toPrecision(digits);
} else {
return value.toString();
predict(x) {
if (typeof x === 'number') {
return this._predict(x);
}
else if ((0, is_any_array_1.isAnyArray)(x)) {
const y = [];
for (const xVal of x) {
y.push(this._predict(xVal));
}
return y;
}
else {
throw new TypeError('x must be a number or array');
}
}
}
}
function checkArraySize(x, y) {
if (!isAnyArray.isAnyArray(x) || !isAnyArray.isAnyArray(y)) {
throw new TypeError('x and y must be arrays');
}
if (x.length !== y.length) {
throw new RangeError('x and y arrays must have the same length');
}
}
class BaseRegression {
constructor() {
if (new.target === BaseRegression) {
throw new Error('BaseRegression must be subclassed');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_predict(x) {
throw new Error('_predict must be implemented');
}
}
predict(x) {
if (typeof x === 'number') {
return this._predict(x);
} else if (isAnyArray.isAnyArray(x)) {
const y = [];
for (let i = 0; i < x.length; i++) {
y.push(this._predict(x[i]));
}
return y;
} else {
throw new TypeError('x must be a number or array');
train() {
// Do nothing for this package
}
}
_predict() {
throw new Error('_predict must be implemented');
}
train() {
// Do nothing for this package
}
toString() {
return '';
}
toLaTeX() {
return '';
}
/**
* Return the correlation coefficient of determination (r) and chi-square.
* @param {Array<number>} x
* @param {Array<number>} y
* @return {object}
*/
score(x, y) {
if (!isAnyArray.isAnyArray(x) || !isAnyArray.isAnyArray(y) || x.length !== y.length) {
throw new Error('x and y must be arrays of the same length');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
toString(precision) {
return '';
}
const n = x.length;
const y2 = new Array(n);
for (let i = 0; i < n; i++) {
y2[i] = this._predict(x[i]);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
toLaTeX(precision) {
return '';
}
let xSum = 0;
let ySum = 0;
let chi2 = 0;
let rmsd = 0;
let xSquared = 0;
let ySquared = 0;
let xY = 0;
for (let i = 0; i < n; i++) {
xSum += y2[i];
ySum += y[i];
xSquared += y2[i] * y2[i];
ySquared += y[i] * y[i];
xY += y2[i] * y[i];
if (y[i] !== 0) {
chi2 += ((y[i] - y2[i]) * (y[i] - y2[i])) / y[i];
}
rmsd += (y[i] - y2[i]) * (y[i] - y2[i]);
/**
* Return the correlation coefficient of determination (r) and chi-square.
* @param x - explanatory variable
* @param y - response variable
* @return - Object with further statistics.
*/
score(x, y) {
(0, checkArrayLength_1.default)(x, y);
const n = x.length;
const y2 = new Array(n);
for (let i = 0; i < n; i++) {
y2[i] = this._predict(x[i]);
}
let xSum = 0;
let ySum = 0;
let chi2 = 0;
let rmsd = 0;
let xSquared = 0;
let ySquared = 0;
let xY = 0;
for (let i = 0; i < n; i++) {
xSum += y2[i];
ySum += y[i];
xSquared += y2[i] * y2[i];
ySquared += y[i] * y[i];
xY += y2[i] * y[i];
if (y[i] !== 0) {
chi2 += ((y[i] - y2[i]) * (y[i] - y2[i])) / y[i];
}
rmsd += (y[i] - y2[i]) * (y[i] - y2[i]);
}
const r = (n * xY - xSum * ySum) /
Math.sqrt((n * xSquared - xSum * xSum) * (n * ySquared - ySum * ySum));
return {
r,
r2: r * r,
chi2,
rmsd: Math.sqrt(rmsd / n),
};
}
const r =
(n * xY - xSum * ySum) /
Math.sqrt((n * xSquared - xSum * xSum) * (n * ySquared - ySum * ySum));
return {
r: r,
r2: r * r,
chi2: chi2,
rmsd: Math.sqrt(rmsd / n),
};
}
}
exports.checkArrayLength = checkArraySize;
exports["default"] = BaseRegression;
exports.maybeToPrecision = maybeToPrecision;
exports.default = BaseRegression;
//# sourceMappingURL=index.js.map
{
"name": "ml-regression-base",
"version": "2.1.6",
"version": "3.0.0",
"description": "Base class for regression modules",
"main": "lib/index.js",
"module": "src/index.js",
"types": "regression-base.d.ts",
"main": "./lib/index.js",
"module": "./lib-esm/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
"files": [
"regression-base.d.ts",
"src",
"lib",
"src"
"lib-esm"
],
"scripts": {
"compile": "rollup -c",
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-esm",
"eslint": "eslint src",
"eslint-fix": "npm run eslint -- --fix",
"prepublishOnly": "npm run compile",
"test": "npm run test-coverage && npm run eslint",
"test-coverage": "jest --coverage",
"test-only": "jest"
"prepack": "npm run tsc",
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
"test-only": "vitest run --coverage",
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
"tsc-cjs": "tsc --project tsconfig.cjs.json",
"tsc-esm": "tsc --project tsconfig.esm.json"
},

@@ -34,16 +39,15 @@ "repository": {

"homepage": "https://github.com/mljs/regression-base#readme",
"jest": {
"testEnvironment": "node"
},
"dependencies": {
"is-any-array": "^2.0.0"
"cheminfo-types": "^1.7.2",
"is-any-array": "^2.0.1"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.16.8",
"eslint": "^8.7.0",
"eslint-config-cheminfo": "^7.2.1",
"jest": "^27.4.7",
"prettier": "^2.5.1",
"rollup": "^2.65.0"
"@vitest/coverage-v8": "^0.34.1",
"eslint": "^8.46.0",
"eslint-config-cheminfo-typescript": "^12.0.4",
"prettier": "^3.0.1",
"rimraf": "^5.0.1",
"typescript": "^5.1.6",
"vitest": "^0.34.1"
}
}

@@ -57,5 +57,5 @@ # regression-base

[codecov-url]: https://codecov.io/gh/mljs/regression-base
[ci-image]: https://github.com/mljs/regression-base/workflows/Node.js%20CI/badge.svg?branch=master
[ci-image]: https://github.com/mljs/regression-base/workflows/Node.js%20CI/badge.svg?branch=main
[ci-url]: https://github.com/mljs/regression-base/actions?query=workflow%3A%22Node.js+CI%22
[download-image]: https://img.shields.io/npm/dm/ml-regression-base.svg
[download-url]: https://npmjs.org/package/ml-regression-base