Spaces:
Sleeping
Sleeping
Upload 11 files
Browse files- README.md +82 -38
- sample_submission.csv +0 -0
- test.csv +0 -0
- train.csv +0 -0
README.md
CHANGED
|
@@ -8,62 +8,106 @@ app_file: app.py
|
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
-
# Stroke Prediction Model
|
| 12 |
|
| 13 |
-
This
|
| 14 |
|
| 15 |
-
## Model
|
| 16 |
|
| 17 |
-
- **
|
| 18 |
-
- **
|
| 19 |
-
- **
|
| 20 |
-
- **
|
| 21 |
|
| 22 |
-
##
|
| 23 |
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
| 27 |
-
import requests
|
| 28 |
|
| 29 |
-
|
| 30 |
-
headers = {"Content-Type": "application/json"}
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
"avg_glucose_level": 228.69,
|
| 45 |
-
"bmi": 36.6,
|
| 46 |
-
"smoking_status": "formerly smoked"
|
| 47 |
}
|
| 48 |
-
|
| 49 |
-
output = query(data)
|
| 50 |
-
print(output)
|
| 51 |
```
|
| 52 |
|
| 53 |
-
## Response Format
|
| 54 |
|
| 55 |
```json
|
| 56 |
{
|
| 57 |
"probability": 0.72,
|
| 58 |
"prediction": "High Risk",
|
| 59 |
-
"stroke_prediction": 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
}
|
| 61 |
```
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
## Risk Categories
|
| 64 |
|
| 65 |
-
- Very Low Risk:
|
| 66 |
-
- Low Risk:
|
| 67 |
-
- Moderate Risk:
|
| 68 |
-
- High Risk:
|
| 69 |
-
- Very High Risk:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Stroke Risk Prediction Model
|
| 12 |
|
| 13 |
+
This Hugging Face Space hosts a machine learning model for stroke risk prediction based on various health and demographic factors.
|
| 14 |
|
| 15 |
+
## Model Overview
|
| 16 |
|
| 17 |
+
- **Type**: Random Forest Classifier
|
| 18 |
+
- **Target**: Binary classification (stroke risk)
|
| 19 |
+
- **Output**: Probability of stroke risk + risk category
|
| 20 |
+
- **Features**: Age, gender, hypertension, heart disease, BMI, glucose levels, and more
|
| 21 |
|
| 22 |
+
## API Endpoints
|
| 23 |
|
| 24 |
+
### POST `/api/predict`
|
| 25 |
|
| 26 |
+
Predicts stroke risk based on patient health data.
|
|
|
|
| 27 |
|
| 28 |
+
#### Request Format
|
|
|
|
| 29 |
|
| 30 |
+
```json
|
| 31 |
+
{
|
| 32 |
+
"gender": "Male",
|
| 33 |
+
"age": 67,
|
| 34 |
+
"hypertension": 1,
|
| 35 |
+
"heart_disease": 0,
|
| 36 |
+
"ever_married": "Yes",
|
| 37 |
+
"work_type": "Private",
|
| 38 |
+
"Residence_type": "Urban",
|
| 39 |
+
"avg_glucose_level": 228.69,
|
| 40 |
+
"bmi": 36.6,
|
| 41 |
+
"smoking_status": "formerly smoked"
|
|
|
|
|
|
|
|
|
|
| 42 |
}
|
|
|
|
|
|
|
|
|
|
| 43 |
```
|
| 44 |
|
| 45 |
+
#### Response Format
|
| 46 |
|
| 47 |
```json
|
| 48 |
{
|
| 49 |
"probability": 0.72,
|
| 50 |
"prediction": "High Risk",
|
| 51 |
+
"stroke_prediction": 1,
|
| 52 |
+
"risk_factors": [
|
| 53 |
+
"Advanced Age (>65)",
|
| 54 |
+
"Very High Blood Glucose (>200)",
|
| 55 |
+
"Obesity (BMI > 30)",
|
| 56 |
+
"Former Smoker"
|
| 57 |
+
],
|
| 58 |
+
"important_features": [
|
| 59 |
+
{"feature": "avg_glucose_level", "importance": 0.31},
|
| 60 |
+
{"feature": "age", "importance": 0.28},
|
| 61 |
+
{"feature": "bmi", "importance": 0.15}
|
| 62 |
+
],
|
| 63 |
+
"execution_time_ms": 50,
|
| 64 |
+
"using_model": true,
|
| 65 |
+
"model_version": "1.0"
|
| 66 |
}
|
| 67 |
```
|
| 68 |
|
| 69 |
+
### GET `/`
|
| 70 |
+
|
| 71 |
+
Returns information about the model and API usage.
|
| 72 |
+
|
| 73 |
+
## Parameter Details
|
| 74 |
+
|
| 75 |
+
| Parameter | Description | Type | Values |
|
| 76 |
+
|-----------|-------------|------|--------|
|
| 77 |
+
| gender | Gender of the patient | String | "Male", "Female", "Other" |
|
| 78 |
+
| age | Age in years | Number | 0-120 |
|
| 79 |
+
| hypertension | Whether patient has hypertension | Number | 0 (No), 1 (Yes) |
|
| 80 |
+
| heart_disease | Whether patient has heart disease | Number | 0 (No), 1 (Yes) |
|
| 81 |
+
| ever_married | Whether patient has ever been married | String | "Yes", "No" |
|
| 82 |
+
| work_type | Type of work/employment | String | "Private", "Self-employed", "Govt_job", "children", "Never_worked" |
|
| 83 |
+
| Residence_type | Type of residence | String | "Urban", "Rural" |
|
| 84 |
+
| avg_glucose_level | Average glucose level in blood (mg/dL) | Number | 50-300+ |
|
| 85 |
+
| bmi | Body Mass Index | Number | 10-50+ |
|
| 86 |
+
| smoking_status | Smoking status of patient | String | "never smoked", "formerly smoked", "smokes", "Unknown" |
|
| 87 |
+
|
| 88 |
## Risk Categories
|
| 89 |
|
| 90 |
+
- **Very Low Risk**: < 10% probability
|
| 91 |
+
- **Low Risk**: 10-20% probability
|
| 92 |
+
- **Moderate Risk**: 20-40% probability
|
| 93 |
+
- **High Risk**: 40-60% probability
|
| 94 |
+
- **Very High Risk**: > 60% probability
|
| 95 |
+
|
| 96 |
+
## Model Training
|
| 97 |
+
|
| 98 |
+
This model was trained on a dataset of over 5,000 patients with various health metrics and stroke outcomes. It identifies key risk factors like:
|
| 99 |
+
|
| 100 |
+
- Age
|
| 101 |
+
- High blood pressure
|
| 102 |
+
- Heart disease
|
| 103 |
+
- Glucose levels
|
| 104 |
+
- BMI
|
| 105 |
+
- Smoking status
|
| 106 |
+
|
| 107 |
+
## Integration with BrainWise App
|
| 108 |
+
|
| 109 |
+
This model serves as the backend for the BrainWise app's stroke risk calculator, providing users with risk assessments based on their health metrics.
|
| 110 |
+
|
| 111 |
+
## Disclaimer
|
| 112 |
+
|
| 113 |
+
This model is for informational purposes only and should not replace professional medical advice. Always consult with healthcare providers for medical decisions.
|
sample_submission.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
train.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|