Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

Compass: Cost of Living Intelligence 🌍

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.


Team

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.


🧠 What this project does

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

⚙️ How it works

1. Data

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:
    1. the country median,
    2. 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.


2. Expense Calculation

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.

3. Machine Learning

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

4. REST API

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.


🚀 How to run

1. Install dependencies

pip install -r requirements.txt

2. Train the model

python train_model.py

3. Run the API

python app.py

4. Test

Open:

http://127.0.0.1:5000/city/Tiznit


📁 Project structure

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

🤔 Design choices

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


📌 Limitations

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


✨ Final thought

This is not just a calculator.

It’s a small simulation of real life in a city.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages