How to use "regression-js" in angular 2 project

Viewed 1017

I am importing the Regression npm module https://www.npmjs.com/package/regression within my Angular 2 application to use the Linear Regression function. I have install package using "npm install regression" . Now I have tried few things to use that package :

First thing which i have tried:

import regression from 'regression';
const result= regression.linear([0, 1], [32, 67], [12, 79]); // this line is giving error, -- can not use linear on undefined.

Second thing which I have tried:

import {Regression} from "regression";
regresiionvar: Regression;
const result=  this.regresiionvar.linear([0, 1], [32, 67], [12, 79]); // but still undefined error.

third thing which I have tried:

import {Regression} from "regression";
regresiionvar: Regression = new Regression().init({});
const result=  this.regresiionvar.linear([0, 1], [32, 67], [12, 79]);//  but still the same undefined error.

I do not know, which thing I am missing, this is quite popular package(look at the number of downloads daily.)

Can any one please share the working example of regression-js with angular 2.

I found one similar question for this, Import non-core npm Library into Angular 2 App , but it also do not have any correct solution.

Any help will be appreciated.

2 Answers

On version 1.4.0 of regression-js you can import it like this

import * as regression from 'regression';

And then use it like this

const reg = regression('linear', [1, 2, 3, 4, 5]);
Related