|
Download README.md from varshagoswami01/sleep-lifecycle-predictor: direct link, hf CLI and curl.
- Browser
- Download file 6.71 kB
-
https://huggingface.co/varshagoswami01/sleep-lifecycle-predictor/resolve/main/README.md
- Command line
-
hf download hf://varshagoswami01/sleep-lifecycle-predictor/README.md
-
curl -L -o README.md https://huggingface.co/varshagoswami01/sleep-lifecycle-predictor/resolve/main/README.md
6.71 kB
| language: | |
| - en | |
| license: mit | |
| library_name: scikit-learn | |
| tags: | |
| - tabular-classification | |
| - random-forest | |
| - health | |
| - lifestyle | |
| - sleep-health | |
| - healthcare | |
| metrics: | |
| - accuracy | |
| - precision | |
| - recall | |
| - f1 | |
| model-index: | |
| - name: sleep-health-lifestyle-classifier | |
| results: | |
| - task: | |
| type: tabular-classification | |
| name: Tabular Classification | |
| metrics: | |
| - name: Accuracy | |
| type: accuracy | |
| value: 1.00 | |
| - name: F1 Score | |
| type: f1 | |
| value: 1.00 | |
| # Sleep Health & Lifestyle AI Classifier | |
| A Scikit-Learn **Random Forest Classifier** wrapped in a self-contained pipeline to evaluate whether an individual maintains a **Healthy** (`1`) or **Unhealthy** (`0`) lifestyle based on sleep parameters, physical activity, stress levels, biometric vitals, and demographic factors. | |
| Trained on the **Sleep Health and Lifestyle Dataset** and packaged for direct deployment and inference via Hugging Face Models. | |
| --- | |
| ## π― Target Definition (`Is_Healthy`) | |
| The model classifies individuals into two lifestyle health categories: | |
| | Target Value | Class Label | Definition / Health Criteria | | |
| | :---: | :---: | :--- | | |
| | **`1`** | **Healthy Lifestyle** | Meets all baseline physiological lifestyle criteria:<br>β’ **Sleep Duration**: $\ge 7.0$ hours/night<br>β’ **Quality of Sleep**: $\ge 7$ (scale 1β10)<br>β’ **Physical Activity Level**: $\ge 60$ minutes/day<br>β’ **Stress Level**: $\le 5$ (scale 1β10) | | |
| | **`0`** | **Unhealthy Lifestyle** | Fails to meet one or more healthy lifestyle criteria | | |
| --- | |
| ## π Dataset & Feature Information | |
| The dataset contains comprehensive lifestyle and physiological measurements. Identifiers (`Person ID`) and medical outcome diagnoses (`Sleep Disorder`) are omitted from model features, and `BMI Category` is excluded to avoid confounding subjective categories. Blood Pressure (`Blood Pressure`) is decomposed into numerical systolic and diastolic components. | |
| ### Input Features | |
| | Feature | Data Type | Description | Example Values | | |
| | :--- | :---: | :--- | :---: | | |
| | **`Gender`** | Categorical | Biological sex | `Male`, `Female` | | |
| | **`Age`** | Numerical (int) | Age in years | `30`, `45` | | |
| | **`Occupation`** | Categorical | Primary profession | `Doctor`, `Engineer`, `Nurse`, `Teacher` | | |
| | **`Sleep Duration`** | Numerical (float) | Average sleep duration in hours | `7.8`, `6.1` | | |
| | **`Quality of Sleep`** | Numerical (int) | Subjective sleep rating (scale 1β10) | `8`, `4` | | |
| | **`Physical Activity Level`** | Numerical (int) | Daily exercise / activity in minutes | `75`, `30` | | |
| | **`Stress Level`** | Numerical (int) | Self-reported stress (scale 1β10) | `4`, `8` | | |
| | **`Heart Rate`** | Numerical (int) | Resting heart rate in beats per minute (bpm) | `68`, `85` | | |
| | **`Daily Steps`** | Numerical (int) | Number of steps walked daily | `8500`, `3200` | | |
| | **`Systolic_BP`** | Numerical (int) | Systolic blood pressure (mmHg) | `120`, `140` | | |
| | **`Diastolic_BP`** | Numerical (int) | Diastolic blood pressure (mmHg) | `80`, `90` | | |
| --- | |
| ## π Model Performance & Evaluation | |
| The model was trained and evaluated using a **stratified 80/20 train-test split** (`random_state=42`) with class balancing: | |
| - **Accuracy Score**: `100.00%` | |
| - **Balanced Class Distribution**: | |
| - Unhealthy (`0`): 228 samples (61.0%) | |
| - Healthy (`1`): 146 samples (39.0%) | |
| ### Classification Report (Holdout Test Set) | |
| | Class | Precision | Recall | F1-Score | Support | | |
| | :--- | :---: | :---: | :---: | :---: | | |
| | **`0` (Unhealthy)** | 1.00 | 1.00 | 1.00 | 46 | | |
| | **`1` (Healthy)** | 1.00 | 1.00 | 1.00 | 29 | | |
| | **Overall Accuracy** | β | β | **1.00** | **75** | | |
| | **Macro Average** | 1.00 | 1.00 | 1.00 | 75 | | |
| | **Weighted Average** | 1.00 | 1.00 | 1.00 | 75 | | |
| ### Confusion Matrix | |
| ``` | |
| Predicted Unhealthy (0) Predicted Healthy (1) | |
| Actual Unhealthy (0) 46 0 | |
| Actual Healthy (1) 0 29 | |
| ``` | |
| --- | |
| ## π Quickstart & Usage | |
| ### 1. Requirements | |
| Install required dependencies: | |
| ```bash | |
| pip install -r requirements.txt | |
| ``` | |
| *(or install directly: `pip install scikit-learn pandas joblib numpy`)* | |
| ### 2. Inference using `predict.py` | |
| Run the included test script to verify predictions on diverse sample profiles: | |
| ```bash | |
| python predict.py | |
| ``` | |
| ### 3. Python Code Snippet | |
| Load `lifestyle_model.pkl` and predict directly: | |
| ```python | |
| import joblib | |
| import pandas as pd | |
| # Load the trained pipeline | |
| model = joblib.load("lifestyle_model.pkl") | |
| # Define input data (supports raw string categories) | |
| sample_data = pd.DataFrame([ | |
| { | |
| "Gender": "Male", | |
| "Age": 30, | |
| "Occupation": "Doctor", | |
| "Sleep Duration": 7.8, | |
| "Quality of Sleep": 8, | |
| "Physical Activity Level": 75, | |
| "Stress Level": 4, | |
| "Heart Rate": 68, | |
| "Daily Steps": 8500, | |
| "Systolic_BP": 120, | |
| "Diastolic_BP": 80, | |
| }, | |
| { | |
| "Gender": "Male", | |
| "Age": 28, | |
| "Occupation": "Sales Representative", | |
| "Sleep Duration": 5.9, | |
| "Quality of Sleep": 4, | |
| "Physical Activity Level": 30, | |
| "Stress Level": 8, | |
| "Heart Rate": 85, | |
| "Daily Steps": 3000, | |
| "Systolic_BP": 140, | |
| "Diastolic_BP": 90, | |
| } | |
| ]) | |
| # Predict class (0 = Unhealthy, 1 = Healthy) | |
| predictions = model.predict(sample_data) | |
| probabilities = model.predict_proba(sample_data) | |
| labels = {0: "Unhealthy Lifestyle", 1: "Healthy Lifestyle"} | |
| for i, pred in enumerate(predictions): | |
| print(f"Sample {i + 1}: {labels[pred]} (Confidence: {probabilities[i][pred] * 100:.1f}%)") | |
| ``` | |
| ### 4. Downloading from Hugging Face Hub | |
| If hosting on Hugging Face Model Hub, download the model file directly with `huggingface_hub`: | |
| ```python | |
| from huggingface_hub import hf_hub_download | |
| import joblib | |
| model_path = hf_hub_download(repo_id="<YOUR_USERNAME>/<YOUR_MODEL_REPO>", filename="lifestyle_model.pkl") | |
| model = joblib.load(model_path) | |
| ``` | |
| --- | |
| ## π¦ Uploading to Hugging Face Model Hub | |
| To upload this model repository to the Hugging Face Model Hub (under **Models**): | |
| ```bash | |
| # 1. Install Hugging Face Hub CLI and authenticate | |
| pip install huggingface_hub | |
| huggingface-cli login | |
| # 2. Create the Model repository (under Models, NOT Spaces) | |
| # Example via CLI or create directly at https://huggingface.co/new | |
| # 3. Clone and copy files, or push directly via git: | |
| git clone https://huggingface.co/<YOUR_USERNAME>/sleep-lifestyle-classifier | |
| cd sleep-lifestyle-classifier | |
| # Copy lifestyle_model.pkl, README.md, requirements.txt, predict.py, and train_model.py | |
| git add . | |
| git commit -m "Initial commit of Sleep Health & Lifestyle Classifier" | |
| git push | |
| ``` | |
| --- | |
| ## π License | |
| This project is licensed under the MIT License. | |