0

I have a dataset and I am running a linear model.

lm_4 = sm.OLS(y_train,X_train).fit()
print(lm_4.summary())

The parameters are let's say as below:

print(lm_4.params)
const              0.001389
area               0.309894
bathrooms          0.314420

Now to predict:

lm_4.predict(X_test_m1.iloc[[1]]) 

Now my doubt is how can I export this model or how can i convert this to an equation so that I can use it independently this model anywhere else. What is the exact equation is generated by the model.

Something like:

y = cont * 0.001389 + area * 0.309894 + bathroom*0.3144 + c

I am new to this. Any lead appreciated.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Dan
  • 3
  • 2
  • Please include explicitly your *imports*; plus, since as it seems you are using `statsmodels`, please remove the `scikit-learn` tag. – desertnaut Feb 28 '19 at 10:44
  • Keep in mind that, by default, statsmodels will **not** include a constant (intercept) term in the model; see answer in [scikit-learn & statsmodels - which R-squared is correct?](https://stackoverflow.com/questions/54614157/scikit-learn-statsmodels-which-r-squared-is-correct/54618898#54618898). – desertnaut Feb 28 '19 at 10:47
  • Your equation is indeed as you say, without the `c` term here; what exactly is your question/requirement? How to get such an equation programmatically? And if yes, in what form? – desertnaut Feb 28 '19 at 10:49
  • @desertnaut I want one final equation.I need to get the liner equation which is generated by the model. – Dan Feb 28 '19 at 10:49
  • In *what form*?? A string would be OK? – desertnaut Feb 28 '19 at 11:02
  • yes .It should be fine.. – Dan Feb 28 '19 at 11:04

1 Answers1

0
y = []

for i in range(len(X_train)):
    y.append(X_train.area[i] * 0.309894 + X_train.bathroom[i] * 0.314420 + 0.001389)

print(y) 

this is your equation

y = X_train.area * 0.309894 + X_train.bathroom * 0.314420 + 0.001389

Aiden Zhao
  • 633
  • 4
  • 15