scikit-learn 1 · Training models

Fit a linear regression

Fit a least-squares line for a numeric target, then read the learned coefficients.

from sklearn.linear_model import LinearRegression

reg = LinearRegression().fit(X_train, y_train)
print(reg.intercept_, reg.coef_)

Official scikit-learn 1 documentation

More training models commands

All training models commands · scikit-learn 1 cheatsheet

Was this page helpful?