A small but powerful project that answers a simple question:
Can I actually afford to live in this city?
Instead of just showing raw numbers, this project simulates a real monthly lifestyle and uses machine learning to decide whether you'll live comfortably or struggle on a budget.
| Name | Contribution |
|---|---|
| Alae Mouhssine | Backend — data processing, ML pipeline |
| Yasmine Lahlaoi | Backend — data processing, ML pipeline |
| Kawtar Khallady | Frontend — React + Redux dashboard (not included in this repository) |
The frontend, built with React and Redux Toolkit, was developed by another team member and is not included in this repository. This repository contains only the backend REST API.
You give it a city name.
It returns a full breakdown of your expected monthly life:
• Net salary
• Bills and utilities
• Transportation
• Groceries
• Entertainment
• Accommodation
• Final balance
Then it goes one step further.
It predicts your lifestyle mode:
- Comfort → you can live without stress
- Budget → you need to optimize spending
The project uses a real-world cost of living dataset from Kaggle:
https://www.kaggle.com/datasets/mvieira101/global-cost-of-living/data
Before training and prediction, the data is preprocessed by:
- merging the two CSV files,
- removing duplicates and invalid rows,
- filling missing values using:
- the country median,
- the global column median when necessary (fallback for countries with only one city and no data).
Median values are preferred over the mean to reduce the impact of outliers.
Monthly expenses are computed across five categories.
| Category | Logic |
|---|---|
| Bills | Electricity + Heating + Cooling + water + internet + mobile plan |
| Transport | Compares public transportation and car costs, then selects the appropriate option depending on the selected mode |
| Groceries | Monthly basket of common food items |
| Entertainment | Activities vary between Comfort and Budget mode (Tennis, Cinema, Gym...) |
| Accommodation | Comfort uses the average rent, Budget selects the cheapest available option. |
A Random Forest classifier predicts whether the city's average salary supports a Comfort or Budget lifestyle using the five expense categories.
| Metric | Value |
|---|---|
| Accuracy | 0.862 |
| Precision | 0.861 |
| Recall | 0.863 |
| F1-score | 0.862 |
The backend exposes a REST API that returns the complete cost-of-living analysis for a given city.
Example:
GET /city/Paris
Returns a complete JSON response containing all expense categories, salary information, the predicted lifestyle mode, and the total estimated monthly cost.
pip install -r requirements.txt
python train_model.py
python app.py
Open:
http://127.0.0.1:5000/city/Tiznit
project/
│
├── data/
│ ├── cost-of-living.csv
│ └── cost-of-living_v2.csv
│
├── models/ # auto-created by train_mode.py
│ ├── mode_model.pkl # the trained classifier
│ ├── mode_importance.png # feature importance chart
│ └── Mode model_RandomForestClassifier_report.txt # accuracy/F1 report
│
├── data_preprocessing.py
├── train_model.py
├── main.py
├── app.py
├── requirements.txt
└── README.md
• No randomness in decisions → everything is deterministic
• Same logic used in training and prediction → zero mismatch
• Real-life assumptions instead of abstract math
• Graceful fallback to a rule-based prediction if no trained model is available (Budget mode is chosen when expenses exceed salary, otherwise it chooses Comfort).
• The grocery basket and activity frequencies are estimated for a single adult. • Healthcare, insurance, taxes, and education expenses are not included. • Salary values represent city averages and may not reflect individual incomes. • Prices are based on the dataset at the time of collection and may differ from current market prices.
This is not just a calculator.
It’s a small simulation of real life in a city.