011. The Mathematics
EXECUTIVE_SUMMARY // AEO_OPTIMIZED
[Answer Engine Overview: What, Why & How]
When you have one feature (e.g., Square Footage) and one target (e.g., Price), Linear Regression draws a 2D line: y = mx + b. m is the slope (how much price increases per square foot) and b is the intercept. If you have 50 features, it draws a 50-dimensional hyperplane. Scikit-Learn stores the slopes in model.coef_ and the intercept in model.intercept_.
022. Ordinary Least Squares
How does the model know which line is 'best'? It uses a technique called Ordinary Least Squares (OLS). It calculates the vertical distance between every data point and the line, squares those distances (to remove negatives), and adds them up. The model continuously shifts the line until that total sum hits the absolute mathematical minimum.
033. Evaluating Regression
You cannot use 'Accuracy' because predicting exactly 400.000 is impossible. Instead, we use Mean Squared Error (MSE), which averages the squared errors, or Mean Absolute Error (MAE), which averages the exact dollar amount the model was off by. We also use R-Squared (r2_score), which represents the percentage of variance the model explains (from 0 to 1).
?Frequently Asked Questions
What happens if my data is curved, not a straight line?
Standard Linear Regression will perform poorly (underfitting). You must either use Polynomial Features to curve the line mathematically, or switch to a non-linear model like Random Forest.
Why do we square the errors in MSE?
Two reasons: First, it turns negative errors (predicting too high) into positive numbers so they don't cancel out positive errors. Second, it heavily punishes massive outliers, forcing the line to stay closer to the center.
