A complete Django web application that uses machine learning to predict tip amounts based on various dining factors.
- AI-Powered Predictions: Uses XGBoost machine learning algorithm
- Beautiful UI: Modern Bootstrap-based responsive design with animations
- Multiple Factors: Considers 6 key features for accurate predictions:
- Total bill amount
- Party size
- Gender
- Smoking status
- Day of the week
- Time of day (lunch/dinner)
ML_Django/
βββ ml_project/ # Machine learning model development
β βββ 01_ml.ipynb # Jupyter notebook with model training
β βββ data/
β β βββ tips.csv # Training dataset
β βββ model/
β βββ xgb_model.pkl # Trained XGBoost model
βββ tip_predictor/ # Django web application
βββ manage.py
βββ predictor/ # Main app
β βββ forms.py # Django forms with Bootstrap styling
β βββ views.py # Business logic and ML predictions
β βββ urls.py # URL routing
β βββ templates/ # HTML templates with modern design
βββ tip_predictor/ # Project settings
βββ settings.py
βββ urls.py
python -m venv .venv
.venv\Scripts\activate # On Windows
# or
source .venv/bin/activate # On Linux/Macpip install django
pip install pandas numpy scikit-learn matplotlib seaborn
pip install joblib xgboost
pip install ipykernel # for Jupyter notebookThe ML model has already been trained and saved. You can see the complete process in the notebook which includes:
- Data loading from seaborn tips dataset
- Feature encoding (categorical to numerical)
- Model training with XGBoost
- Model evaluation and comparison
- Saving the model as
xgb_model.pkl
The Django project has been created with the following structure:
# Project was created with:
django-admin startproject tip_predictor
cd tip_predictor
python manage.py startapp predictor- Enhanced with Bootstrap styling and form validation
- Includes all 6 required features with proper field types
- User-friendly labels and placeholders
- Handles form processing and ML predictions
- Implements proper feature encoding as per the ML model
- Error handling for model loading and predictions
- Base template: Modern responsive design with Bootstrap 5
- Home page: Interactive prediction form with real-time validation
- About page: Information about the model and technology stack
- Features: Gradient backgrounds, animations, and modern UI components
- Clean URL routing with app namespacing
- Integrated with main project URLs
-
Navigate to the Django project:
cd tip_predictor -
Run migrations:
python manage.py migrate
-
Start the development server:
python manage.py runserver
-
Open your browser and visit:
http://127.0.0.1:8000/
- Fill out the prediction form with dining details
- Click "Predict Tip Amount"
- View the AI-generated tip prediction
- Explore the About page for more information
- Algorithm: XGBoost Regressor
- Training Data: Restaurant tips dataset from Seaborn
- Accuracy: High performance with low MAE and good RΒ² score
- Features: 6 input features with categorical encoding:
- Sex: Male=1, Female=0
- Smoker: Yes=1, No=0
- Day: Fri=0, Sat=1, Sun=2, Thur=3
- Time: Dinner=0, Lunch=1
- Backend: Django 5.2.5
- Frontend: Bootstrap 5.1.3, Font Awesome 6.0
- Machine Learning: XGBoost, Scikit-learn
- Database: SQLite
- Python: 3.8+
The application features:
- Modern gradient backgrounds
- Responsive card-based layout
- Interactive form elements
- Animated prediction results
- Professional navigation
- Information-rich about page
- User authentication and prediction history
- Data visualization of predictions
- Model performance metrics dashboard
- Batch prediction capabilities
- API endpoints for external integration