A user-friendly, offline-compatible web application built with Streamlit to help you track, manage, and visualize your personal expenses. Leveraging an XGBoost machine learning model, this tool not only provides insights into your historical spending habits but also forecasts your total expenses for the upcoming monthβempowering you to budget proactively.
- Live Demo
- Features
- Tech Stack
- Project Structure
- Installation
- Usage Guide
- How It Works
- Contributing
- License
πClick here to view demo
Example of the main dashboard showing key metrics, charts, and forecast.

A clean, intuitive interface that serves as your financial control center, surfacing:
- Key Metrics: Total accumulated expenses and average monthly spending.
- Budget vs. Forecast: Set a monthly budget and see a clear warning if your forecasted expenses are projected to exceed it.
- Intelligent Forecasting: A data-driven prediction of your total expenses for the upcoming month, powered by an XGBoost model.
Complete control over your financial data.
- Create: Add new expense transactions through a simple form.
- Read: View all expense records in a clean, interactive table.
- Update: Edit any detail of a past transaction directly within the data table.
- Delete: Remove records that are no longer needed.
- Bulk CSV Upload: Quickly populate your data by uploading an
expenses.csvfile.
- Monthly Forecast Chart: A bar chart comparing historical monthly spending against the predicted amount for the next month.
- Category Breakdown Pie Chart: A pie chart showing where your money is going by expense category.
- Daily Spending Trend: A line chart that plots daily expenses over time to reveal trends and spending spikes.
The machine learning model automatically retrains in the background whenever you add, edit, or delete data, ensuring your forecasts are always based on the most up-to-date information.
- Language: Python 3.8+
- Web Framework: Streamlit
- ML Libraries: XGBoost, scikit-learn
- Data Handling: pandas
- Visualization: Matplotlib & Seaborn
smart-expense-predictor/
βββ assets/
β βββ screenshot.png # screenshots for README
βββ data/
β βββ expenses.csv # User data (auto-generated if not present)
βββ models/
β βββ model.pkl # Serialized XGBoost model (auto-generate)
βββ src/
β βββ __init__.py
β βββ data_processor.py # Loads, saves, and preprocesses data
β βββ ml_model.py # Trains, predicts, and persists the XGBoost model
β βββ utils.py # Helper functions (e.g., budget checks)
β βββ visualizer.py # Generates all Matplotlib/Seaborn plots
βββ app.py # Main Streamlit application entrypoint
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
git clone https://github.com/udhay8005/smart-expense-predictor.git
cd smart-expense-predictor- Windows
python -m venv venv .\venv\Scripts\activate
- macOS / Linux
python3 -m venv venv source venv/bin/activate
pip install -r requirements.txtstreamlit run app.pyOpen your browser and navigate to http://localhost:8501.
-
Launch the App: Follow the installation steps to start the Streamlit server.
-
Add Expenses:
- Manual Entry: On the main dashboard, use the "Add Expense" form to enter the date, amount, category, and a description. Click "Save Expense".
- Bulk Upload: In the sidebar, use the "Upload CSV" feature to import a file with the columns:
Date,Amount,Category,Description.
-
Set Your Monthly Budget:
- Enter your target monthly spending limit in the sidebar input box. The dashboard will automatically compare this budget against the forecasted expense.
-
Interact with the Dashboard:
- View your key metrics, forecast, and budget status at the top.
- Hover over the charts to see detailed values for monthly, categorical, or daily spending.
-
Manage Existing Transactions:
- Navigate to the "Manage Expenses" page from the sidebar.
- Here, you can edit data directly in the table or select rows to delete.
- Click "Save Changes" to update your
expenses.csvfile and retrain the model.
- Storage: All expense data is read from and saved to
data/expenses.csv. - Preprocessing: The module converts
Datestrings into datetime objects, sorts records chronologically, and aggregates daily expenses into monthly totals to prepare the data for the model.
- Feature Engineering: A simple but effective time-series feature,
Month_Num(a unique, sequential integer for each month), is created. - Model: An
XGBoost Regressoris trained to learn the relationship betweenMonth_NumandTotalMonthlyExpense. - Prediction: To forecast the next month's spending, the model is fed the last known
Month_Num + 1. - Persistence: The trained model is saved as
models/model.pkland is reloaded on startup. It is automatically retrained whenever the underlying expense data is modified.
- This module uses Matplotlib and Seaborn to generate all the plots displayed on the dashboard, creating a rich, visual experience for the user.
This project is licensed under the MIT License. See the LICENSE file for details.
This PowerShell script is a safe and smart setup utility you can run before installing your Python project dependencies. It solves common issues that happen during pip install, especially on Windows systems.
- 𧨠Corrupt
.whlfiles - π« Temp folder lock errors like
WinError 32 - β
--userissues inside virtual environments - π Stuck or repeated install failures
- π Slow installs due to cache or antivirus
- π§± Heavy packages like
xgboost,scipy,pandas, etc.
-
pip cache purge
Removes old cached.whlfiles that may be corrupted. -
Delete
pip-unpack-*from temp folder
Cleans temporary folders in%TEMP%that can block file access during installs. -
Activate virtual environment
Ensurespipinstalls packages inside your.venv, not globally. -
Install
xgboostlocally (optional)
Installs heavy wheels manually (likexgboost) if a local.whlis present. -
Edit
requirements.txt
Temporarily removesxgboostto avoid redundant installation. -
Install all dependencies
Installs everything usingpip install -r requirements.txt --no-cache-dirfor a clean, reliable setup.
Use this script before running pip install in the following situations:
-
𧨠You get
WinError 32errors
This script clears locked temp files that cause this issue. -
π
pip installkeeps failing repeatedly
Likely due to broken wheel files or cache β this script cleans it up. -
π Installations are very slow or stuck
Avoids delays caused by pip bugs or antivirus by installing fresh. -
π₯
pip installcrashes halfway
Removes partial downloads so they donβt block future installs. -
β You accidentally used
--userin a virtual environment
This script ensures you're installing in the correct.venv. -
π¦ You already have a local
.whlforxgboost
Saves bandwidth and avoids heavy downloads again. -
π You recently rebuilt or recreated your
.venv
Starts with a clean setup, avoiding leftover conflicts.
Include this script in your project repo. After cloning, users can just run:
.\install_clean.ps1To set up everything without error.
[CLEAN] Removing pip temporary unpack files...
[ENV] Activating virtual environment...
[OK] Virtual environment activated.
[INSTALL] Found xgboost wheel. Installing locally...
[EDIT] Removing xgboost from requirements.txt temporarily...
[INSTALL] Installing other requirements from requirements.txt...
[FINISHED] β
All steps completed successfully.
π File: install_clean.ps1
π Place this script in your project root (same location as requirements.txt).
@udhayachandra