Spaces:
Running
Running
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,206 +1,47 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
```
|
| 8 |
-
project/
|
| 9 |
-
β
|
| 10 |
-
βββ app.py # Main Flask application
|
| 11 |
-
βββ requirements.txt # Python dependencies
|
| 12 |
-
βββ README.md # This file
|
| 13 |
-
β
|
| 14 |
-
βββ templates/
|
| 15 |
-
β βββ index.html # Main web interface
|
| 16 |
-
β
|
| 17 |
-
βββ static/
|
| 18 |
-
β βββ Car Images/ # Background images
|
| 19 |
-
β βββ 1.png
|
| 20 |
-
β βββ 2.png
|
| 21 |
-
β βββ 3.png
|
| 22 |
-
β βββ 4.png
|
| 23 |
-
β βββ 5.png
|
| 24 |
-
β
|
| 25 |
-
βββ embeddings/
|
| 26 |
-
β βββ car_names_list.txt # List of car names from training
|
| 27 |
-
β βββ car_name_embeddings.npy # Pre-computed embeddings
|
| 28 |
-
β βββ categorical_features_map.pkl # Categorical encoding mapping
|
| 29 |
-
β βββ all_mpnet_base_v2/ # Sentence transformer model
|
| 30 |
-
β βββ config.json
|
| 31 |
-
β βββ model.safetensors
|
| 32 |
-
β βββ ...
|
| 33 |
-
β
|
| 34 |
-
βββ model/
|
| 35 |
-
βββ lightgbm_used_car_model.pkl # Trained LightGBM model
|
| 36 |
-
βββ model_metrics.json # Model performance metrics
|
| 37 |
-
βββ model_parameters.json # Model hyperparameters
|
| 38 |
-
```
|
| 39 |
-
|
| 40 |
-
## Setup Instructions
|
| 41 |
-
|
| 42 |
-
### 1. Move Files to Correct Locations
|
| 43 |
-
|
| 44 |
-
Since your `Car Images` folder is currently in the root, you need to move it to the `static` folder:
|
| 45 |
-
|
| 46 |
-
```bash
|
| 47 |
-
# Create static directory
|
| 48 |
-
mkdir static
|
| 49 |
-
|
| 50 |
-
# Move Car Images to static
|
| 51 |
-
mv "Car Images" static/
|
| 52 |
-
```
|
| 53 |
-
|
| 54 |
-
### 2. Install Dependencies
|
| 55 |
-
|
| 56 |
-
```bash
|
| 57 |
-
# Create virtual environment (recommended)
|
| 58 |
-
python -m venv venv
|
| 59 |
-
|
| 60 |
-
# Activate virtual environment
|
| 61 |
-
# On Windows:
|
| 62 |
-
venv\Scripts\activate
|
| 63 |
-
# On Mac/Linux:
|
| 64 |
-
source venv/bin/activate
|
| 65 |
-
|
| 66 |
-
# Install dependencies
|
| 67 |
-
pip install -r requirements.txt
|
| 68 |
-
```
|
| 69 |
-
|
| 70 |
-
### 3. Run the Application
|
| 71 |
-
|
| 72 |
-
```bash
|
| 73 |
-
python app.py
|
| 74 |
-
```
|
| 75 |
-
|
| 76 |
-
The app will be available at: `http://localhost:5000`
|
| 77 |
-
|
| 78 |
-
## How It Works
|
| 79 |
-
|
| 80 |
-
### 1. **User Input**
|
| 81 |
-
Users provide:
|
| 82 |
-
- Car name/model (e.g., "Toyota Camry 2015")
|
| 83 |
-
- Origin (Local/Foreign)
|
| 84 |
-
- Transmission (Automatic/Manual)
|
| 85 |
-
- Fuel Type (Petrol/Diesel/Hybrid/Electric)
|
| 86 |
-
- Interior Color
|
| 87 |
-
- Exterior Color
|
| 88 |
-
|
| 89 |
-
### 2. **Feature Engineering**
|
| 90 |
-
The app processes inputs through several steps:
|
| 91 |
-
|
| 92 |
-
**a. Name Embeddings:**
|
| 93 |
-
- Uses the pre-trained `all-mpnet-base-v2` sentence transformer
|
| 94 |
-
- Converts car name into 768-dimensional embedding vector
|
| 95 |
-
- Extracts specific dimensions used by the model (e.g., `name_emb_307`, `name_emb_741`)
|
| 96 |
-
|
| 97 |
-
**b. Categorical Encoding:**
|
| 98 |
-
- Applies one-hot encoding to categorical features
|
| 99 |
-
- Uses the same encoding schema from training (saved in `categorical_features_map.pkl`)
|
| 100 |
-
- Creates binary columns like `origin_local`, `interior_color_coffee brown`, etc.
|
| 101 |
-
|
| 102 |
-
### 3. **Feature Selection**
|
| 103 |
-
The model uses only 12 specific features:
|
| 104 |
-
- 10 name embedding dimensions
|
| 105 |
-
- 2 categorical features (origin_local, interior/exterior colors)
|
| 106 |
-
|
| 107 |
-
### 4. **Prediction**
|
| 108 |
-
- LightGBM model predicts the price
|
| 109 |
-
- Result is formatted and displayed in Nigerian Naira (β¦)
|
| 110 |
-
|
| 111 |
-
## Model Features
|
| 112 |
-
|
| 113 |
-
The trained model uses these 12 features:
|
| 114 |
-
```python
|
| 115 |
-
[
|
| 116 |
-
'name_emb_307', 'name_emb_741', 'origin_local', 'name_emb_559',
|
| 117 |
-
'name_emb_618', 'name_emb_207', 'name_emb_661', 'name_emb_766',
|
| 118 |
-
'name_emb_541', 'name_emb_518', 'interior_color_coffee brown',
|
| 119 |
-
'exterior_color_dark silver'
|
| 120 |
-
]
|
| 121 |
-
```
|
| 122 |
-
|
| 123 |
-
## API Endpoints
|
| 124 |
-
|
| 125 |
-
### `GET /`
|
| 126 |
-
Returns the main HTML interface
|
| 127 |
-
|
| 128 |
-
### `POST /predict`
|
| 129 |
-
Predicts car price based on input features
|
| 130 |
-
|
| 131 |
-
**Request Body:**
|
| 132 |
-
```json
|
| 133 |
-
{
|
| 134 |
-
"car_name": "Toyota Camry 2015",
|
| 135 |
-
"origin": "local",
|
| 136 |
-
"transmission": "automatic",
|
| 137 |
-
"fuel_type": "petrol",
|
| 138 |
-
"interior_color": "coffee brown",
|
| 139 |
-
"exterior_color": "dark silver"
|
| 140 |
-
}
|
| 141 |
-
```
|
| 142 |
-
|
| 143 |
-
**Response:**
|
| 144 |
-
```json
|
| 145 |
-
{
|
| 146 |
-
"success": true,
|
| 147 |
-
"predicted_price": 4500000.0,
|
| 148 |
-
"formatted_price": "β¦4,500,000.00"
|
| 149 |
-
}
|
| 150 |
-
```
|
| 151 |
-
|
| 152 |
-
### `GET /health`
|
| 153 |
-
Health check endpoint
|
| 154 |
|
| 155 |
## Features
|
| 156 |
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
β
**Loading States:** Visual feedback during prediction
|
| 163 |
-
|
| 164 |
-
## Troubleshooting
|
| 165 |
-
|
| 166 |
-
### Issue: "Model not found"
|
| 167 |
-
**Solution:** Ensure all files are in the correct directories as shown in the project structure.
|
| 168 |
-
|
| 169 |
-
### Issue: "Categorical encoding error"
|
| 170 |
-
**Solution:** Make sure you're using the exact same categorical values as during training. Check the `categorical_features_map.pkl` for valid options.
|
| 171 |
-
|
| 172 |
-
### Issue: "Import error for sentence_transformers"
|
| 173 |
-
**Solution:** Reinstall with: `pip install sentence-transformers==2.2.2`
|
| 174 |
-
|
| 175 |
-
### Issue: Background images not showing
|
| 176 |
-
**Solution:**
|
| 177 |
-
1. Ensure images are in `static/Car Images/`
|
| 178 |
-
2. Check file permissions
|
| 179 |
-
3. Restart the Flask server
|
| 180 |
-
|
| 181 |
-
## Production Deployment
|
| 182 |
-
|
| 183 |
-
For production use with Gunicorn:
|
| 184 |
|
| 185 |
-
|
| 186 |
-
gunicorn -w 4 -b 0.0.0.0:5000 app:app
|
| 187 |
-
```
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
-
|
| 192 |
-
- RMSE (Root Mean Squared Error)
|
| 193 |
-
- MAPE (Mean Absolute Percentage Error)
|
| 194 |
-
- RΒ² Score
|
| 195 |
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
-
|
| 199 |
-
- Prices are in Nigerian Naira (β¦)
|
| 200 |
-
- The sentence transformer uses 768-dimensional embeddings
|
| 201 |
-
- Only 12 features are used for final predictions (selected via stepwise selection)
|
| 202 |
-
- The app handles unseen categorical values by setting them to 0
|
| 203 |
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
-
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Nigerian Used Car Price Predictor
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
|
| 11 |
+
# Nigerian Used Car Price Predictor
|
| 12 |
|
| 13 |
+
A machine learning web application that predicts used car prices in Nigeria using LightGBM and sentence embeddings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
## Features
|
| 16 |
|
| 17 |
+
- π Predict car prices based on multiple attributes
|
| 18 |
+
- π€ Uses advanced sentence embeddings for car name processing
|
| 19 |
+
- β‘ Fast predictions with LightGBM model
|
| 20 |
+
- π¨ Modern, responsive UI with dynamic backgrounds
|
| 21 |
+
- π° Prices displayed in Nigerian Naira (β¦)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
## How to Use
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
1. Enter the car name/model (e.g., "Toyota Camry 2015")
|
| 26 |
+
2. Select the origin (Local/Foreign)
|
| 27 |
+
3. Choose transmission type
|
| 28 |
+
4. Select fuel type
|
| 29 |
+
5. Pick interior and exterior colors
|
| 30 |
+
6. Click "Predict Price" to get instant estimate
|
| 31 |
|
| 32 |
+
## Tech Stack
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
- **Backend:** Flask + Gunicorn
|
| 35 |
+
- **ML Model:** LightGBM
|
| 36 |
+
- **Embeddings:** Sentence Transformers (all-mpnet-base-v2)
|
| 37 |
+
- **Frontend:** HTML, CSS, JavaScript
|
| 38 |
+
- **Deployment:** Docker
|
| 39 |
|
| 40 |
+
## Model Details
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
The model uses:
|
| 43 |
+
- 10 sentence embedding dimensions from car names
|
| 44 |
+
- 2 categorical features (origin and color combinations)
|
| 45 |
+
- Trained on Nigerian used car market data
|
| 46 |
|
| 47 |
+
---
|