Model Pipeline - Linear regression with scikit-learn
This pipeline uses linear regression to find a straight line that best fits the relationship between input features and a target value. It learns from data to predict new values.
This pipeline uses linear regression to find a straight line that best fits the relationship between input features and a target value. It learns from data to predict new values.
Loss
2500 |*****
2300 |****
2100 |***
1900 |
1700 |
1 2 3 4 5 Epochs
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 2500 | Initial fit with high error | |
| 2 | 2200 | Loss decreased, model improving | |
| 3 | 2100 | Better fit, R² rising | |
| 4 | 2050 | Loss stabilizing, good fit | |
| 5 | 2000 | Final model with good R² |
from sklearn.linear_model import LinearRegression import numpy as np X = np.array([[1], [2], [3], [4], [5]]) y = np.array([2, 4, 6, 8, 10]) model = LinearRegression() model.fit(X, y) print(round(model.coef_[0], 1))
from sklearn.linear_model import LinearRegression X = [[1], [2], [3]] y = [2, 4, 6] model = LinearRegression() model.fit(X, y) print(model.predict([4]))
Pass the test and this pattern moves unknown