简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM