Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export a linear regression formula out of sklearn LinearRegression

I want to have the formula of the model in order to use it in other languages/projects. Is there a way to export the formula from the model?

I will use sklearn linear regression model.

What I want to do eventually: given a formula f(), and data set 'd', I will have java script code that will give me predictions on d based on f().

like image 438
MichaelLo Avatar asked Nov 16 '15 10:11

MichaelLo


1 Answers

The formula can be described essentially by the learned coefficients. The coefficients can be obtained using the attributes coef_ and intercept_. The dot product between the coefficients and the input vector plus the intercept gives the output of the model.

The actual code that implements this "formula" in scikit-learn is something like:

return safe_sparse_dot(X, self.coef_.T,
                       dense_output=True) + self.intercept_

which should not be too difficult for you to port over to your other project.

like image 147
YS-L Avatar answered Sep 18 '22 09:09

YS-L