SLR returns NaN when inputs and outputs are 1-element arrays
I'm reimplementing my algorithm from MLR into SLR (I don't need multiple params anymore) and I see that SLR is returning NaN when inputs & outputs are arrays of 1-element. The old implementation with MLR was producing proper results.
const SLR = require('ml-regression-simple-linear')
const MLR = require('ml-regression-multivariate-linear')
const slr1 = new SLR([ 1 ], [ 2 ])
console.log('SLR for 1 value:', slr1.predict(2))
const mlr1 = new MLR([ [ 1 ] ], [ [ 2 ] ])
console.log('MLR for 1 value:', mlr1.predict([ 2 ]))
const slr2 = new SLR([ 1, 2 ], [ 2, 3 ])
console.log('SLR for 2 values:', slr2.predict(3))
const mlr2 = new MLR([ [ 1 ], [ 2 ] ], [ [ 2 ], [ 3 ] ])
console.log('MLR for 2 values:', mlr2.predict([ 3 ]))
Output:
SLR for 1 value: NaN (should be 3)
MLR for 1 value: [ 2.9999999999999996 ]
SLR for 2 values: 4
MLR for 2 values: [ 3.999999999999991 ]
What do you expect as a result with this edge case? There are infinite solutions that fulfill the input data.
Shouldn't it be just 3, MLR for the same inputs and outputs (just wrapped in array) returns nearly 3?
I think it works in MLR because the intercept option is true by default. Unfortunately, I don't remember exactly what it means and how it could translate to SLR.
Hello @jobo322, do you have an opinion on this issue?
What do you expect as a result with this edge case? There are infinite solutions that fulfill the input data.
I also agree with you, it has no sense to give an answer for this case, maybe both should throw on this cardinality