npm地址:https://www.npmjs.com/package/ml-regression-multivariate-linear
1、安装
npm install ml-regression-multivariate-linear
2、使用
import MLR from "ml-regression-multivariate-linear";const x = [ //自变量[0, 0], //代表两个自变量的每一项[1, 2],[2, 3],[3, 4]];// Y0 = X0 * 2, Y1 = X1 * 2, Y2 = X0 + X1const y = [ //因变量[0, 0, 0], //代表三个因变量的每一项[2, 4, 3],[4, 6, 5],[6, 8, 7]];const mlr = new MLR(x, y);console.log(mlr.predict([3, 3]));
3、new MLR(x, y) 实例如下
//weights: MultivariateLinearRegression{statistics: true,weights: [ //非标准化回归系数[ 0.5357142857141639, 3.608193277309965 ],[ 0.035714285714306016, -1.5829831932769025 ],[ 12.642857142855064, -58.11134453779414 ]],inputs: 2,outputs: 2,intercept: true,stdError: Infinity,stdErrorMatrix: Matrix {[Infinity -Infiniy -Infiniy-Infiniy Infinity Infinity-Infiniy Infinity Infinity]rows: 3columns: 3},stdErrors: [ Infinity, Infinity, Infinity ],tStats: [ 0, 0, 0 ]}
4、计算标准化回归系数
c
标准化回归系数 = 未标准化回归系数 * 该自变量的标准差 / 因变量的标准差
计算标准差方法:math.std(…nums) //其中nums为一组自变量或一组因变量
5、csv
如果数据使用csv引入,可以使用库 csvtojson
