Machine Learning Model

Model Architecture

Linear Regression with One-Hot Encoding — interpretable, fast, and achieving 84% R²

Algorithm

Linear Regression

Encoding

One-Hot Encoding

Scaler

StandardScaler

Train/Test Split

67% / 33%

Why Linear Regression?

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.

Advantages

  • Interpretable — coefficients show feature impact
  • Fast — trains in < 100ms
  • Stable — no hyperparameter tuning needed
  • Proven — well-understood, reliable baseline
  • Scalable — inference in < 1ms per prediction

Performance

  • R² of 0.840 on test set
  • RMSE of £1,900
  • Explains 84% of price variance
  • CV std deviation < 0.01
  • No overfitting detected
Preprocessing

Feature Engineering

One-Hot Encoding

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).

StandardScaler

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.

One-Hot vs Label Encoding

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

Conclusion

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.

Pipeline

Training Process

1

Data Loading

Load ford.csv with pandas (17,966 rows × 9 columns)

2

Feature/Target Split

Separate X (8 features) from y (price target variable)

3

One-Hot Encoding

pd.get_dummies() converts categorical → binary flags (8 → 37 cols)

4

Numerical Scaling

StandardScaler() normalizes year, mileage, tax, mpg, engineSize

5

Train/Test Split

train_test_split() with test_size=0.33, random_state=42

6

Model Training

LinearRegression().fit(X_train, y_train) — completes in < 100ms

7

Model Saving

joblib.dump(model, 'ford_price_model.pkl') for reproducibility

Model Interpretability

One of the key strengths of Linear Regression is interpretability. Each coefficient directly shows how much that feature impacts the predicted price.

How to Read Coefficients

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.

Explore Model Performance

See how the model performs on the test set with detailed metrics and visualizations