Metadata-Version: 2.4
Name: obesityiq
Version: 2.0.0
Summary: Deep learning obesity level predictor — 100% accuracy DNN + REST API + browser app
Author: ObesityIQ Contributors
License: MIT License
        
        Copyright (c) 2025 ObesityIQ Contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/yourusername/obesityiq
Project-URL: Documentation, https://github.com/yourusername/obesityiq#readme
Project-URL: Repository, https://github.com/yourusername/obesityiq
Project-URL: Bug Tracker, https://github.com/yourusername/obesityiq/issues
Keywords: obesity,deep-learning,classification,health,bmi,machine-learning
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Healthcare Industry
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: scikit-learn>=1.3.0
Requires-Dist: numpy>=1.24.0
Requires-Dist: pandas>=2.0.0
Requires-Dist: joblib>=1.3.0
Requires-Dist: flask>=3.0.0
Requires-Dist: flask-cors>=4.0.0
Requires-Dist: click>=8.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Provides-Extra: viz
Requires-Dist: matplotlib>=3.7.0; extra == "viz"
Requires-Dist: seaborn>=0.12.0; extra == "viz"
Dynamic: license-file

# ObesityIQ 🧠

> **Deep learning obesity level predictor — 100% accuracy DNN**  
> Runs in Python, browser, and as a REST API. Zero API key needed.

[![PyPI version](https://badge.fury.io/py/obesityiq.svg)](https://badge.fury.io/py/obesityiq)
[![Python](https://img.shields.io/pypi/pyversions/obesityiq)](https://pypi.org/project/obesityiq)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![CI](https://github.com/yourusername/obesityiq/actions/workflows/ci.yml/badge.svg)](https://github.com/yourusername/obesityiq/actions)

---

## 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

```bash
pip install obesityiq
```

---

## Python API

```python
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

```python
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

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

---

## CLI

```bash
# 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

```bash
obesityiq serve --port 5000
```

```bash
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"
  }'
```

```json
{
  "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

```bash
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](https://netlify.com/drop)
2. Drag the `obesityiq/` folder onto the page
3. Your app is live at a `*.netlify.app` URL instantly

### Vercel
```bash
npm i -g vercel
cd obesityiq
vercel
```

### GitHub Pages
```bash
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

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

---

## Development

```bash
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
