Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python/Scikit-learn - Linear Regression - Access to Linear Regression Equation

I've built a few different linear regressions, using the same group of predictor variables, as you can see below:

model=LinearRegression()
model.fit(X=predictor_train,y=target_train)
prediction_train=model.predict(predictor_train)
pred=model.predict(main_frame.iloc[-1:,1:])

To create the predictions of the target variable, I suppose that the Scikit algorithm created an equation with those "predictor variables". My question is: How do I access that equation?

like image 873
aabujamra Avatar asked Mar 13 '23 10:03

aabujamra


1 Answers

You're looking for params = model.coef_. This returns an array with the weight of each model input.

Note that this is a linear equation, so to get the prediction for yourself, you want to form an equation such that your prediction, y = sum([input[i] * params[i]]), if you had some input array called input. This is the dot product, if you're familiar with linear algebra between the parameter vector and the feature vector.

like image 160
Alex Alifimoff Avatar answered Apr 07 '23 01:04

Alex Alifimoff