-1

I recently finished training a linear regression algorithm but I don't know how to save it so that in the future, I can use it to make relevant predictions without having to retrain it whenever I want to use it.

Do I save the .py file and call it whenever I need it or create a class or what?

I just want to know how I can save a model I trained so I can use it in the future.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • 1
    Please provide more details (whether you are wrote your own model code from scratch or whether you are using a specific machine learning library), including the relevant code in the question. Please also demonstrate that you have researched this issue in other SO posts and elsewhere online and have tried recommended solutions. If you google 'save trained model` and the ML library you are using, you will get many hits. – AlexK Aug 04 '22 at 21:07
  • 1
    This is impossible to answer unless you give details of your model/framework implementation. – Dr. Snoopy Aug 04 '22 at 21:14

1 Answers1

-1

Depending on how you make the linear regression, you should be able to obtain the equation of the regression, as well as the values of the coefficients, most likely by inspecting the workspace.

If you explain what module, function, or code you use to do the regression, it will be easier to give a specific solution.

Furthermore, you can probably use the dill package: https://pypi.org/project/dill/

I saw the solution here: https://askdatascience.com/441/anyone-knows-workspace-jupyter-python-variables-functions

The steps proposed for using dill are:

  1. Install dill. If you use conda, the code would be conda install -c anaconda dill
  2. To save workspace using dill:
import dill
dill.dump_session('notebook_session.db')
  1. To restore sesion:
import dill
dill.load_session('notebook_session.db')

I saw the same package discussed here: How to save all the variables in the current python session? and I tested it using a model created with the interpretML package, and it worked for me.

EnTekker
  • 62
  • 10