Linear Regression with One-Hot Encoding — interpretable, fast, and achieving 84% R²
Linear Regression
One-Hot Encoding
StandardScaler
67% / 33%
Linear Regression was chosen as the primary algorithm for this project because it offers the perfect balance of interpretability, speed, and accuracy for regression tasks.
Categorical features (model, transmission, fuelType) are converted into binary flags. Each unique category becomes its own column.
Before: 8 columns
After: 37 columns
Result: R² = 0.840
This approach avoids implying false numeric ordering between categories (e.g., Manual ≠1, Automatic ≠2).
Numerical features (year, mileage, tax, mpg, engineSize) are scaled to have mean = 0 and standard deviation = 1.
Formula: (x - mean) / std
Effect: All features contribute equally
Benefit: Prevents large-scale features from dominating
Essential for Linear Regression to ensure all features have equal weight in the model.
We trained two models to compare encoding strategies:
| Metric | One-Hot Encoding | Label Encoding | Winner |
|---|---|---|---|
| MAE | ~£1,400 | ~£1,700 | One-Hot |
| RMSE | ~£1,900 | ~£2,200 | One-Hot |
| R² | 0.840 | 0.731 | One-Hot |
| Features | 37 columns | 8 columns | — |
| Training Time | < 100ms | < 50ms | Label |
One-Hot Encoding wins by ~11 R² percentage points. The model correctly treats each model name, transmission, and fuel type as independent categories without implying numeric ordering. The extra training time (50ms) is negligible.
Load ford.csv with pandas (17,966 rows × 9 columns)
Separate X (8 features) from y (price target variable)
pd.get_dummies() converts categorical → binary flags (8 → 37 cols)
StandardScaler() normalizes year, mileage, tax, mpg, engineSize
train_test_split() with test_size=0.33, random_state=42
LinearRegression().fit(X_train, y_train) — completes in < 100ms
joblib.dump(model, 'ford_price_model.pkl') for reproducibility
One of the key strengths of Linear Regression is interpretability. Each coefficient directly shows how much that feature impacts the predicted price.
Positive coefficient: Increasing this feature increases price
Negative coefficient: Increasing this feature decreases price
Larger magnitude: Stronger impact on price
Feature importance analysis is available on the Performance page, showing the top 20 features by coefficient magnitude and top 15 by permutation importance.
See how the model performs on the test set with detailed metrics and visualizations