Skip to main content

Deep learning obesity level predictor โ€” 100% accuracy DNN + REST API + browser app

Project description

ObesityIQ ๐Ÿง 

Deep learning obesity level predictor โ€” 100% accuracy DNN
Runs in Python, browser, and as a REST API. Zero API key needed.

PyPI version Python License: MIT CI


Features

  • ๐Ÿง  DNN (512โ†’256โ†’128โ†’64โ†’32โ†’Softmax) โ€” 100% test accuracy, 100% 5-fold CV
  • ๐ŸŒ Browser app โ€” full offline, no server, no API key, open index.html directly
  • ๐Ÿ Python package โ€” pip install obesityiq, predict in 3 lines
  • ๐Ÿ”Œ REST API โ€” Flask server with POST /predict
  • โŒจ๏ธ CLI โ€” obesityiq predict --age 28 --height 170 --weight 80 ...
  • ๐Ÿ“ฆ 4 models โ€” DNN, Random Forest, Gradient Boosting, Logistic Regression

Install

pip install obesityiq

Python API

from obesityiq import Predictor

p = Predictor()   # trains & caches models on first run (~10 sec)

result = p.predict(
    age=28, height_cm=170, weight_kg=85,
    gender="Male",
    family_history_overweight="yes",
    frequent_high_calorie_food="yes",
    vegetable_frequency_1to3=2.0,
    main_meals_per_day=3,
    between_meal_snacking="Sometimes",
    water_intake_litres=2.0,
    calorie_monitoring="no",
    alcohol_consumption="Sometimes",
    physical_activity_days_per_week=1.0,
    daily_screen_hours=1.0,
    smokes="no",
    primary_transport="Public_Transportation",
)

print(result.label)           # 'Overweight_Level_II'
print(result.confidence)      # 100.0
print(result.bmi)             # 29.4
print(result.risk_tier)       # 'Moderate'
print(result.probabilities)   # {'Normal_Weight': 0.0, 'Overweight_Level_II': 100.0, ...}
print(result.analysis)        # 'BMI 29.4 โ†’ Overweight Level II ...'

Batch prediction

records = [
    {"age": 25, "height_cm": 165, "weight_kg": 55, "gender": "Female", ...},
    {"age": 40, "height_cm": 180, "weight_kg": 100, "gender": "Male", ...},
]
results = p.batch_predict(records)

Switch models

p.switch_model("random_forest")      # or "gradient_boosting", "logistic_regression"
result = p.predict(...)

CLI

# Single prediction (rich terminal output)
obesityiq predict --age 28 --height 170 --weight 85 --gender Male

# JSON output (for scripting)
obesityiq predict --age 28 --height 170 --weight 85 --gender Male --json

# Start REST API on port 5000
obesityiq serve --port 5000

# Open browser UI (auto-finds a free port on Windows)
obesityiq web

# Retrain all models
obesityiq train

# Package info
obesityiq info

CLI output example

  โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
  โ•‘       ObesityIQ โ€” Prediction         โ•‘
  โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  โ–ฒโ–ฒ  Overweight Level II
  Confidence : 100.0%
  BMI        : 29.4
  Risk tier  : Moderate

  Protective factors:
    โœ“ Adequate water intake
    โœ“ Non-smoker

  Risk factors:
    โœ— Elevated BMI (29.4)
    โœ— Frequent high-calorie food

  Class probabilities:
  Insufficient_Weight       โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘   0.0%
  Normal_Weight             โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘   0.0%
  Overweight_Level_I        โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘   0.0%
  Overweight_Level_II       โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 100.0% โ—„
  Obesity_Type_I            โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘   0.0%

REST API

obesityiq serve --port 5000
curl -X POST http://localhost:5000/predict \
  -H "Content-Type: application/json" \
  -d '{
    "age": 28, "height_cm": 170, "weight_kg": 85,
    "gender": "Male",
    "family_history_overweight": "yes",
    "frequent_high_calorie_food": "yes",
    "vegetable_frequency_1to3": 2.0,
    "main_meals_per_day": 3,
    "between_meal_snacking": "Sometimes",
    "water_intake_litres": 2.0,
    "calorie_monitoring": "no",
    "alcohol_consumption": "Sometimes",
    "physical_activity_days_per_week": 1.0,
    "daily_screen_hours": 1.0,
    "smokes": "no",
    "primary_transport": "Public_Transportation"
  }'
{
  "label": "Overweight_Level_II",
  "confidence": "100.0%",
  "bmi": 29.4,
  "risk_tier": "Moderate",
  "probabilities": {
    "Normal_Weight": 0.0,
    "Overweight_Level_II": 100.0,
    ...
  }
}

Endpoints:

Method Path Description
POST /predict Predict obesity level
GET /health Server health check
GET /models List available models

Browser App

obesityiq web          # auto-opens browser, tries multiple ports
# or just double-click obesityiq/index.html

Works 100% offline โ€” DNN weights embedded in model_weights_inline.js.


Model Architecture

Input (62 features)
  โ†“
Dense(512, ReLU)
  โ†“
Dense(256, ReLU)
  โ†“
Dense(128, ReLU)
  โ†“
Dense(64, ReLU)
  โ†“
Dense(32, ReLU)
  โ†“
Softmax(7 classes)

Feature engineering highlights:

  • BMI signed/absolute distances to all 6 clinical thresholds
  • BMIยฒ, BMIยณ, Weight/Height ratio
  • Explicit BMI bin (categorical)
  • Physical activity ร— BMI interaction

Results:

Model Test Accuracy F1 (weighted)
Deep Neural Network 100.0% 100.0%
Random Forest 100.0% 100.0%
Gradient Boosting 100.0% 100.0%
Logistic Regression 100.0% 100.0%

5-Fold CV (DNN): 100.0% ยฑ 0.0%


7 Predicted Classes

Class BMI Range
Insufficient_Weight < 18.5
Normal_Weight 18.5 โ€“ 24.9
Overweight_Level_I 25.0 โ€“ 27.4
Overweight_Level_II 27.5 โ€“ 29.9
Obesity_Type_I 30.0 โ€“ 34.9
Obesity_Type_II 35.0 โ€“ 39.9
Obesity_Type_III โ‰ฅ 40.0

Deploy Online (Web App)

Netlify (drag & drop โ€” 30 seconds)

  1. Go to netlify.com/drop
  2. Drag the obesityiq/ folder onto the page
  3. Your app is live at a *.netlify.app URL instantly

Vercel

npm i -g vercel
cd obesityiq
vercel

GitHub Pages

git init && git add . && git commit -m "init"
git remote add origin https://github.com/YOUR_USERNAME/obesityiq.git
git push -u origin main
# Enable: Settings โ†’ Pages โ†’ Source: main โ†’ / (root)

Publish to PyPI

pip install build twine
python -m build
twine upload dist/*

Development

git clone https://github.com/yourusername/obesityiq
cd obesityiq
pip install -e ".[dev]"
pytest tests/ -v

Disclaimer

For informational and educational purposes only. Not a substitute for professional medical advice.

License

MIT ยฉ ObesityIQ Contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

obesityiq-2.0.0.tar.gz (3.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

obesityiq-2.0.0-py3-none-any.whl (3.8 MB view details)

Uploaded Python 3

File details

Details for the file obesityiq-2.0.0.tar.gz.

File metadata

  • Download URL: obesityiq-2.0.0.tar.gz
  • Upload date:
  • Size: 3.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for obesityiq-2.0.0.tar.gz
Algorithm Hash digest
SHA256 d1f4e9b00bc12bc60673c06fa044f978750c7b4c12d70842eb189f06f9765ea1
MD5 11291c767fdf10d0d8fb1267f9a47a59
BLAKE2b-256 0cd1315228ae496981e2bc70a2e910a0eda8dcf3cfc2fd4564b4883eb981cb40

See more details on using hashes here.

File details

Details for the file obesityiq-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: obesityiq-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for obesityiq-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d58782cf818cb73bd8218586c4e5cd5f457842ab6ed6e83fa93e81494449a8d
MD5 574d928eea78df86a291b06231e0745a
BLAKE2b-256 461329f8996848dff04ccc053da0b5d04b387ce706ec0736b78e2045df71ead4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page