Backend AI ''brain'' for car price predictor
# 🚗 Kenya Used Car Price Predictor (Backend ML Engine)
This repository contains the machine learning backend and inference engine for the Kenya Used Car Price application. It serves as the AI "brain" for the overall app, processing vehicle specifications and returning highly accurate, data-driven market valuations in Kenyan Shillings (KES).
## 🧠 The "Brain" Overview
The core of this backend is a **Random Forest Regressor** trained on a curated dataset of used cars in the Kenyan market. It utilizes an integrated Scikit-Learn pipeline to automatically handle feature engineering, scaling, and categorical encoding before passing the data to the prediction model.
### Key Features
* **Automated Preprocessing:** Handles One-Hot Encoding for categorical variables (Make, Fuel Type, Transmission) and Standard Scaling for numerical variables (Mileage, Engine Size).
* **Robust Algorithm:** Uses a tuned Random Forest model to capture the non-linear depreciation curves typical in the automotive market.
* **Serialized Deployment:** The entire pipeline is exported as a `.pkl` file (`kenya_car_price_model.pkl`) for rapid, low-latency inference in production.
## 📊 Model Performance
The model was evaluated against a 20% holdout test set to ensure high accuracy on unseen data:
* **Algorithm:** Random Forest Regressor
* **R² Score (Accuracy):** 0.938 *(The model explains 93.8% of the variance in Kenyan car prices)*
* **Mean Absolute Error (MAE):** KES 207,654.40
### Feature Importance
The engine relies heavily on the following factors to determine a vehicle's value:
1. **Engine Size (cc):** 35.1%
2. **Year of Manufacture:** 23.5%
3. **Fuel Type:** 21.9%
## ⚙️ Repository Structure
* `kenya_used_cars_cleaned.csv`: The training dataset featuring local market data (Toyota, Mazda, Honda, etc.).
* `train_model.py`: The data processing and model training script. Run this to generate or update the AI brain.
* `kenya_car_price_model.pkl`: The serialized machine learning pipeline (The Brain …