1

I have fitted a model given a Poly-3 function and extracted the found parameters

model = smf.ols(formula='A ~ B + I(B ** 2.0) + I(B ** 3.0)', data=sp)
poly_3 = model.fit()
params = poly_3.params.values

I want to save the params for later use since I don't want to train the model each time. Params would e.g. be [ 0.09525563, 0.09655527, -0.00946222, 0.00056942]

How can I then, given the formula, the params and some x-values get fitted values? I am thinking of sth. like this:

OLS.predict(x=range(20), params=params, formula='A ~ B + I(B ** 2.0) + I(B ** 3.0)')

I obviously could write the formula in Python itself, but I feel that I don't have to re-invent the wheel here!

Thanks!

TomTom101
  • 6,581
  • 2
  • 20
  • 31

1 Answers1

0

please refer to this Python statsmodels OLS: how to save learned model to file you can save your model results to a pickle file, then load the model from the pickle file and use it to predict.

Let me know if you have any questions.

Community
  • 1
  • 1
marwan
  • 504
  • 4
  • 14