How do I call a function from the npm package?

Hi, these were the instructions I got to run an npm package on runkit. But import is not recognized, and if I remove it, MLR is not found. How do I make this work?

var mlRegressionMultivariateLinear = require(“ml-regression-multivariate-linear”)

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 + X1
const 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]));
// [6, 6, 6]

Here you go. That should work for you.

1 Like