mljs / regression-multivariate-linear

Multivariate linear regression
MIT License
33 stars 13 forks source link

x.addColumn is not a function #9

Closed jefffriesen closed 5 years ago

jefffriesen commented 5 years ago

I'm running into this error using the latest version of this repo and using the examples from the README:

  const x = [[0, 0], [1, 2], [2, 3], [3, 4]]
  // Y0 = X0 * 2, Y1 = X1 * 2, Y2 = X0 + X1
  const y = [[0, 0, 0], [2, 4, 3], [4, 6, 5], [6, 8, 7]]
  const mlr = new MLR(x, y). // => TypeError: x.addColumn is not a function
  console.log(mlr.predict([3, 3]))

I've tried { intercept: false } which skips over the x.addColumn function call, but run into a different error:

  const x = [[0, 0], [1, 2], [2, 3], [3, 4]]
  // Y0 = X0 * 2, Y1 = X1 * 2, Y2 = X0 + X1
  const y = [[0, 0, 0], [2, 4, 3], [4, 6, 5], [6, 8, 7]]
  const mlr = new MLR(x, y, { intercept: false }) // => TypeError: value.clone is not a function
  console.log(mlr.predict([3, 3]))

Putting a breakpoint in the source code right after converting x to a new Matrix():

x = new Matrix(x)
console.log(x) // =>  [Array(2), Array(2), Array(2), Array(2), rows: 4, columns: 2]

So clearly new Matrix is converting it. However, .addColumn is not on the prototype.

I noticed that the dependency for ml-matrix is set up as "ml-matrix": "^5.1.1" and that the version of ml-matrix that got installed was 5.3.0. So I forked it, created a pinned version at 5.1.1 (confirmed that I had 5.1.1) but got the same error.

However, when I fork your repo and run the test all pass. Does anyone have any suggestions?

jefffriesen commented 5 years ago

I just tried this library in simple browser and node apps. It failed in the browser (create-react-app) and worked in node.js (version 11)

It depends on ml-matrix, so the problem may be related to https://github.com/mljs/matrix/issues/69

jefffriesen commented 5 years ago

Also related to this closed ticket: https://github.com/mljs/regression-multivariate-linear/issues/7 The author plans to fix it in the next version and also offers a a way to get it working now: https://github.com/mljs/matrix/issues/69#issuecomment-484700654

targos commented 5 years ago

This will be fixed in the next version with ml-matrix 6.0.0