Tom-Alexander/regression-js

Possible problem with polynomial regression

mttigg opened this issue · 1 comments

Using a polynomial regression on this data set hard codes the y axis to one value, usually it is around 2.4. Given the same data the other regressions did map properly. I also experimented changing the order with no change. Am I doing something wrong?

import { polynomial } from "regression";

const raw = [
  [500, 2.5],
  [1000, 3],
  [1500, 3],
  [2000, 3.3],
  [3000, 3.6],
  [4000, 4],
  [5500, 4.8],
  [6000, 5],
  [7000, 5],
  [8000, 5.5],
  [9000, 6],
  [12000, 7],
  [14000, 8],
  [15000, 8],
  [18000, 9],
  [20000, 10],
  [21000, 10],
  [24000, 11],
  [28000, 12],
  [30000, 13],
  [50000, 18]
];

const toCoor = ([x, y]) => ({ x, y });

function makeDataSet(data) {
  const { points } = polynomial(data);

  return points.map(toCoor);
}

// polynomial output

// {
//   string: "y = 0x^2 + 0x + 2.47",
//   points: Array(21),
//   predict: ƒ,
//   equation: Array(3),
//   r2: -1.47
// }

const data = makeDataSet(raw);
const markData = raw.map(toCoor);

#73 seems to have this issue covered by adding precision... But I also think that the default precision should be higher to accommodate this.