How to get slope of variables and intercept from a stored(serialized using python pickle) ML model

I am a newbie to machine learning and python.

I have a Python code snippet which loads stored ml model and predict with new inputs.

 mlModel = pickle.load(open('linear_model4.pickle','rb'))
request_body = request.body.decode('utf-8')

parsed_request = makePredictionInput(json.loads(request_body))

result = mlModel.predict(parsed_request)

It uses 5 inputs for prediction.

Is there a way to get the slopes and intercept from above loaded model sothat i can form the equation as y = intercept + slope1variable1+ slope2variable2+ slope3*variable4+…..


I assume that your model is a linear model given the equation you want to reconstruct. mlModel.coef_ should be what you want. See this for example.

Leave a Reply

Your email address will not be published. Required fields are marked *