This is a machine learning web application that predicts obesity levels based on user input using a pre-trained model. The app uses FastAPI for the backend and is designed to take multiple user inputs related to health and lifestyle to classify obesity levels.
- Predicts obesity level based on input such as gender, age, height, family history of obesity, eating habits, physical activity, and more.
- Interactive web form built with HTML.
- FastAPI framework for backend logic and serving the machine learning model.
- Random Forest machine learning model for prediction.
- Deployed on a cloud platform (Render, Heroku, etc.).
├── src
│ ├── main.py # Main FastAPI app
│ ├── data_model.py # Data model definition
│ ├── model.pkl # Pre-trained model
│ ├── CAEC_label_encoder.pkl # Label encoders for categorical features
│ ├── CALC_label_encoder.pkl # Label encoders for categorical features
│ ├── MTRANS_label_encoder.pkl # Label encoders for categorical features
│ ├── templates
│ └── form.html # HTML template for the web form
├── requirements.txt # List of dependencies
└── README.md # Project documentation- The user inputs their personal and lifestyle data (such as age, gender, physical activity, etc.) into a form on the web app.
- The backend receives the data, processes it using a pre-trained machine learning model, and returns a prediction of their obesity level.
- The app provides the result back to the user, displaying it on the same page.
-
Clone the repository:
git clone https://github.com/YourUsername/Obesity_Prediction.git cd Obesity_Prediction -
Set up a virtual environment:
python -m venv myenv source myenv/bin/activate # On Windows use `myenv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the application:
uvicorn src.main:app --reload
-
Open the app in your browser:
Go to
http://127.0.0.1:8000to see the form and predict obesity levels.
- Open the application in your browser.
- Fill in the form with the required information.
- Submit the form, and the app will display your predicted obesity level.
To deploy the application on Render, Heroku, or any cloud service, follow these steps:
-
Add your
Procfile(for Heroku):web: uvicorn src.main:app --host 0.0.0.0 --port $PORT -
Push to GitHub and link your repository to Render/Heroku.
-
Deploy your app, and the platform will automatically detect the
requirements.txtand build the app.
- FastAPI: A modern, fast (high-performance) web framework for building APIs.
- Pandas: Data manipulation and analysis.
- Scikit-learn: For the machine learning model.
- Joblib: To save and load label encoders.
- HTML: Frontend for user interaction.
- Jinja2: Templating engine for HTML in FastAPI.
- The model used is a Random Forest Classifier, trained on a dataset containing lifestyle and personal health information.
- Pre-processing was done to encode categorical variables like
CAEC,CALC,MTRANSusing label encoders.
- Here's the dataset source: Estimation of Obesity Levels Based On Eating Habits and Physical Condition
- Add validation for form inputs.
- Improve UI/UX for better usability.
- Explore deploying on additional cloud platforms.
- Add more classification models for comparison.

