Signature
LinearRegression(*, fit_intercept=True)What it does
LinearRegression finds coefficients that minimize squared error between predictions and targets. Call fit on training data, then predict on new rows. The learned coefficients are available after fitting.
Parameters
fit_interceptbool, optionaloptional- Whether to estimate an intercept term.
Returns
LinearRegression
Example
pythonLinearRegression example
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print(model.coef_)Watch out for
- Scaling features can make coefficients easier to compare but changes their units.
- A high training score does not prove the model generalizes; evaluate on held-out data.