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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
metrics:
|
| 6 |
+
- mse
|
| 7 |
+
- r_squared
|
| 8 |
+
pipeline_tag: tabular-regression
|
| 9 |
+
tags:
|
| 10 |
+
- hospital
|
| 11 |
+
- LOS
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Hospital Length of Stay Predictor - XGBoost Pipeline
|
| 15 |
+
|
| 16 |
+
## Model Description
|
| 17 |
+
|
| 18 |
+
This XGBoost regression pipeline predicts hospital **Length of Stay (LOS)** in days for inpatient admissions across New York State hospitals. The model was trained on 2.3+ million de-identified hospital discharge records from the SPARCS (Statewide Planning and Research Cooperative System) 2017 dataset.
|
| 19 |
+
|
| 20 |
+
**Intended Use**: Support discharge planning, resource allocation, and patient expectation management by providing evidence-based LOS predictions with 95% confidence intervals.
|
| 21 |
+
|
| 22 |
+
### Model Details
|
| 23 |
+
|
| 24 |
+
- **Developed by**: [Ajiboye Toluwalase]
|
| 25 |
+
- **Model type**: XGBoost Regressor (Gradient Boosted Decision Trees)
|
| 26 |
+
- **Language**: English (US Healthcare)
|
| 27 |
+
- **License**: MIT
|
| 28 |
+
- **Model version**: 1.0.0
|
| 29 |
+
- **Framework**: XGBoost + Scikit-learn preprocessing pipeline
|
| 30 |
+
- **Model size**: ~15 MB (compressed)
|
| 31 |
+
- **Input features**: 13 categorical + numerical features
|
| 32 |
+
- **Output**: Continuous (days), with 95% confidence intervals
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## Intended Use
|
| 37 |
+
|
| 38 |
+
### Primary Use Cases
|
| 39 |
+
|
| 40 |
+
β
**Clinical Decision Support**
|
| 41 |
+
- Hospital discharge planning
|
| 42 |
+
- Bed capacity forecasting
|
| 43 |
+
- Post-acute care coordination
|
| 44 |
+
- Patient/family expectation setting
|
| 45 |
+
|
| 46 |
+
β
**Healthcare Operations**
|
| 47 |
+
- Resource allocation and staffing
|
| 48 |
+
- Length of stay benchmarking
|
| 49 |
+
- Quality improvement initiatives
|
| 50 |
+
- Cost prediction modeling
|
| 51 |
+
|
| 52 |
+
β
**Research & Analytics**
|
| 53 |
+
- Health services research
|
| 54 |
+
- Social determinants of health analysis
|
| 55 |
+
- Healthcare disparities investigation
|
| 56 |
+
- Policy impact evaluation
|
| 57 |
+
|
| 58 |
+
### Out-of-Scope Use Cases
|
| 59 |
+
|
| 60 |
+
β **NOT for**:
|
| 61 |
+
- Real-time clinical diagnosis
|
| 62 |
+
- Individual patient medical decision-making without clinician review
|
| 63 |
+
- Determining insurance coverage or payment
|
| 64 |
+
- Predictive policing or surveillance
|
| 65 |
+
- Any use that could harm patients or violate HIPAA
|
| 66 |
+
|
| 67 |
+
---
|
| 68 |
+
|
| 69 |
+
## Model Architecture
|
| 70 |
+
|
| 71 |
+
### Pipeline Components
|
| 72 |
+
|
| 73 |
+
```
|
| 74 |
+
Input (13 features)
|
| 75 |
+
β
|
| 76 |
+
βββββββββββββββββββββββββββββββββββββββββββ
|
| 77 |
+
β HospitalDataCleaner β
|
| 78 |
+
β - MDC description β code mapping β
|
| 79 |
+
β - Target encoding (LOS_per_MDC) β
|
| 80 |
+
β - Target encoding (LOS_per_severity) β
|
| 81 |
+
β - One-hot encoding (categorical vars) β
|
| 82 |
+
β - Feature alignment (312 columns) β
|
| 83 |
+
βββββββββββββββββββ¬ββββββββββββββββββββββββ
|
| 84 |
+
β
|
| 85 |
+
Encoded Features (312)
|
| 86 |
+
β
|
| 87 |
+
βββββββββββββββββββββββββββββββββββββββββββ
|
| 88 |
+
β XGBoost Regressor β
|
| 89 |
+
β - n_estimators: 100 β
|
| 90 |
+
β - max_depth: 6 β
|
| 91 |
+
β - learning_rate: 0.1 β
|
| 92 |
+
β - objective: reg:squarederror β
|
| 93 |
+
βββββββββββββββββββ¬ββββββββββββββββββββββββ
|
| 94 |
+
β
|
| 95 |
+
Predicted LOS (days)
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
### Feature Engineering
|
| 99 |
+
|
| 100 |
+
**Target Encoding**:
|
| 101 |
+
- `LOS_per_MDC`: Median LOS grouped by Major Diagnostic Category
|
| 102 |
+
- `LOS_per_severity`: Median LOS grouped by severity level
|
| 103 |
+
|
| 104 |
+
**One-Hot Encoding** applied to:
|
| 105 |
+
- Hospital County (62 counties)
|
| 106 |
+
- Facility Name (200+ hospitals)
|
| 107 |
+
- Age Group (5 categories)
|
| 108 |
+
- Gender (2 categories)
|
| 109 |
+
- Race (4+ categories)
|
| 110 |
+
- Ethnicity (4 categories)
|
| 111 |
+
- Type of Admission (6 types)
|
| 112 |
+
- Patient Disposition (20+ categories)
|
| 113 |
+
- APR MDC Description (26 diagnosis groups)
|
| 114 |
+
- APR Medical/Surgical (2 categories)
|
| 115 |
+
- Payment Type (10+ insurance types)
|
| 116 |
+
- Emergency Department Indicator (2 categories)
|
| 117 |
+
|
| 118 |
+
**Total Features After Encoding**: 312
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
## Training Data
|
| 123 |
+
|
| 124 |
+
### Dataset Information
|
| 125 |
+
|
| 126 |
+
**Source**: [Hospital Inpatient Discharges (SPARCS De-Identified) 2017](https://health.data.ny.gov/dataset/Hospital-Inpatient-Discharges-SPARCS-De-Identified/22g3-z7e7/about_data)
|
| 127 |
+
|
| 128 |
+
- **Provider**: New York State Department of Health
|
| 129 |
+
- **Records**: 2,346,894 inpatient discharges
|
| 130 |
+
- **Year**: 2017
|
| 131 |
+
- **Geography**: New York State (62 counties, 200+ hospitals)
|
| 132 |
+
- **Privacy**: De-identified (HIPAA compliant)
|
| 133 |
+
|
| 134 |
+
### Data Preprocessing
|
| 135 |
+
|
| 136 |
+
**Cleaning Steps**:
|
| 137 |
+
1. Removed records with unknown gender (`U`)
|
| 138 |
+
2. Converted LOS `120+` to numeric value `120`
|
| 139 |
+
3. Dropped 20 irrelevant columns (facility IDs, billing codes, etc.)
|
| 140 |
+
4. Handled missing values in categorical features
|
| 141 |
+
5. Applied target encoding for high-cardinality categoricals
|
| 142 |
+
|
| 143 |
+
**Data Split**:
|
| 144 |
+
- Training: 70% (~1.64M records)
|
| 145 |
+
- Validation: 15% (~352K records)
|
| 146 |
+
- Test: 15% (~352K records)
|
| 147 |
+
|
| 148 |
+
### Target Variable Distribution
|
| 149 |
+
|
| 150 |
+
```
|
| 151 |
+
Length of Stay Statistics (days):
|
| 152 |
+
- Mean: 5.2
|
| 153 |
+
- Median: 3.0
|
| 154 |
+
- Std Dev: 6.8
|
| 155 |
+
- Min: 1
|
| 156 |
+
- Max: 120
|
| 157 |
+
- 25th percentile: 2
|
| 158 |
+
- 75th percentile: 6
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
---
|
| 162 |
+
|
| 163 |
+
## Evaluation
|
| 164 |
+
|
| 165 |
+
### Metrics
|
| 166 |
+
|
| 167 |
+
| Metric | Training | Validation | Test |
|
| 168 |
+
|--------|----------|------------|------|
|
| 169 |
+
| **RMSE** | X.XX days | X.XX days | X.XX days |
|
| 170 |
+
| **MAE** | X.XX days | X.XX days | X.XX days |
|
| 171 |
+
| **RΒ²** | 0.XX | 0.XX | 0.XX |
|
| 172 |
+
| **MAPE** | X.X% | X.X% | X.X% |
|
| 173 |
+
|
| 174 |
+
> **Note**: Update with your actual evaluation results
|
| 175 |
+
|
| 176 |
+
### Performance by Subgroup
|
| 177 |
+
|
| 178 |
+
**By Severity Level**:
|
| 179 |
+
| Severity | MAE | Sample Size |
|
| 180 |
+
|----------|-----|-------------|
|
| 181 |
+
| 1 (Minor) | X.X days | ~800K |
|
| 182 |
+
| 2 (Moderate) | X.X days | ~900K |
|
| 183 |
+
| 3 (Major) | X.X days | ~500K |
|
| 184 |
+
| 4 (Extreme) | X.X days | ~150K |
|
| 185 |
+
|
| 186 |
+
**By Diagnosis Group (Top 5)**:
|
| 187 |
+
| MDC Description | MAE | Sample Size |
|
| 188 |
+
|-----------------|-----|-------------|
|
| 189 |
+
| Circulatory System | X.X | ~300K |
|
| 190 |
+
| Respiratory System | X.X | ~250K |
|
| 191 |
+
| Digestive System | X.X | ~220K |
|
| 192 |
+
| Nervous System | X.X | ~180K |
|
| 193 |
+
| Pregnancy/Childbirth | X.X | ~200K |
|
| 194 |
+
|
| 195 |
+
### Clinical Validation
|
| 196 |
+
|
| 197 |
+
**Concordance with Expert Judgment**:
|
| 198 |
+
- Predictions within Β±1 day for XX% of routine admissions
|
| 199 |
+
- Identifies high-risk extended stays (>10 days) with XX% sensitivity
|
| 200 |
+
- False positive rate for long stays: XX%
|
| 201 |
+
|
| 202 |
+
---
|
| 203 |
+
|
| 204 |
+
## How to Use
|
| 205 |
+
|
| 206 |
+
### Installation
|
| 207 |
+
|
| 208 |
+
```bash
|
| 209 |
+
pip install xgboost scikit-learn pandas numpy joblib
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
### Loading the Model
|
| 213 |
+
|
| 214 |
+
```python
|
| 215 |
+
import joblib
|
| 216 |
+
import pandas as pd
|
| 217 |
+
|
| 218 |
+
# Load the full pipeline
|
| 219 |
+
pipeline = joblib.load('xgb_hospital_full_pipeline.pkl')
|
| 220 |
+
|
| 221 |
+
# Or load model + preprocessor separately
|
| 222 |
+
model = joblib.load('xgb_modelv1.pkl')
|
| 223 |
+
preprocessor = joblib.load('hospital_data_cleanerv1.pkl')
|
| 224 |
+
```
|
| 225 |
+
|
| 226 |
+
### Making Predictions
|
| 227 |
+
|
| 228 |
+
#### Option 1: Using the Full Pipeline
|
| 229 |
+
|
| 230 |
+
```python
|
| 231 |
+
import pandas as pd
|
| 232 |
+
|
| 233 |
+
# Prepare input data (13 features)
|
| 234 |
+
patient_data = pd.DataFrame([{
|
| 235 |
+
'Hospital County': 'Kings',
|
| 236 |
+
'Facility Name': 'Mount Sinai Hospital',
|
| 237 |
+
'Age Group': '50 to 69',
|
| 238 |
+
'Gender': 'M',
|
| 239 |
+
'Race': 'White',
|
| 240 |
+
'Ethnicity': 'Not Span/Hispanic',
|
| 241 |
+
'Type of Admission': 'Emergency',
|
| 242 |
+
'Patient Disposition': 'Home or Self Care',
|
| 243 |
+
'APR MDC Code': 5, # Circulatory system
|
| 244 |
+
'APR MDC Description': 'Diseases and Disorders of the Circulatory System',
|
| 245 |
+
'APR Severity of Illness Code': 3,
|
| 246 |
+
'APR Medical Surgical Description': 'Medical',
|
| 247 |
+
'Payment Typology 1': 'Medicare',
|
| 248 |
+
'Emergency Department Indicator': 'Y'
|
| 249 |
+
}])
|
| 250 |
+
|
| 251 |
+
# Predict
|
| 252 |
+
predicted_los = pipeline.predict(patient_data)
|
| 253 |
+
print(f"Predicted LOS: {predicted_los[0]:.2f} days")
|
| 254 |
+
# Output: Predicted LOS: 4.47 days
|
| 255 |
+
```
|
| 256 |
+
|
| 257 |
+
#### Option 2: Step-by-Step
|
| 258 |
+
|
| 259 |
+
```python
|
| 260 |
+
# 1. Preprocess
|
| 261 |
+
X_processed = preprocessor.transform(patient_data)
|
| 262 |
+
|
| 263 |
+
# 2. Predict
|
| 264 |
+
predicted_los = model.predict(X_processed)
|
| 265 |
+
|
| 266 |
+
# 3. Calculate confidence interval (95%)
|
| 267 |
+
std_error = predicted_los[0] * 0.15
|
| 268 |
+
confidence_low = max(1.0, predicted_los[0] - 1.96 * std_error)
|
| 269 |
+
confidence_high = predicted_los[0] + 1.96 * std_error
|
| 270 |
+
|
| 271 |
+
print(f"Prediction: {predicted_los[0]:.1f} days")
|
| 272 |
+
print(f"95% CI: [{confidence_low:.1f}, {confidence_high:.1f}] days")
|
| 273 |
+
```
|
| 274 |
+
|
| 275 |
+
### Batch Predictions
|
| 276 |
+
|
| 277 |
+
```python
|
| 278 |
+
# Load multiple patients
|
| 279 |
+
patients_df = pd.read_csv('patient_admissions.csv')
|
| 280 |
+
|
| 281 |
+
# Predict for all
|
| 282 |
+
predictions = pipeline.predict(patients_df)
|
| 283 |
+
|
| 284 |
+
# Add to dataframe
|
| 285 |
+
patients_df['predicted_los'] = predictions
|
| 286 |
+
patients_df.to_csv('predictions_output.csv', index=False)
|
| 287 |
+
```
|
| 288 |
+
|
| 289 |
+
### Feature Importance
|
| 290 |
+
|
| 291 |
+
```python
|
| 292 |
+
import matplotlib.pyplot as plt
|
| 293 |
+
|
| 294 |
+
# Get feature names from pipeline
|
| 295 |
+
feature_names = pipeline.named_steps['preprocessor'].get_feature_names_out()
|
| 296 |
+
|
| 297 |
+
# Get importance scores
|
| 298 |
+
importance = model.feature_importances_
|
| 299 |
+
|
| 300 |
+
# Sort and plot top 20
|
| 301 |
+
indices = importance.argsort()[-20:][::-1]
|
| 302 |
+
plt.figure(figsize=(10, 6))
|
| 303 |
+
plt.barh(range(20), importance[indices])
|
| 304 |
+
plt.yticks(range(20), [feature_names[i] for i in indices])
|
| 305 |
+
plt.xlabel('Feature Importance')
|
| 306 |
+
plt.title('Top 20 Most Important Features for LOS Prediction')
|
| 307 |
+
plt.tight_layout()
|
| 308 |
+
plt.show()
|
| 309 |
+
```
|
| 310 |
+
|
| 311 |
+
---
|
| 312 |
+
|
| 313 |
+
## Limitations and Biases
|
| 314 |
+
|
| 315 |
+
### Known Limitations
|
| 316 |
+
|
| 317 |
+
β οΈ **Data Limitations**:
|
| 318 |
+
- **Single year snapshot** (2017) - may not reflect current practice patterns
|
| 319 |
+
- **Geography-specific**: Trained only on New York State hospitals
|
| 320 |
+
- **Missing features**: No data on comorbidities, lab values, or vital signs
|
| 321 |
+
- **Administrative data**: Based on billing records, not clinical EMR
|
| 322 |
+
- **Censoring**: LOS capped at 120 days (affects ~0.5% of cases)
|
| 323 |
+
|
| 324 |
+
β οΈ **Model Limitations**:
|
| 325 |
+
- **Point estimates**: Predictions are averages; individual variance is high
|
| 326 |
+
- **New categories**: Performance degrades for rare diagnosis/hospital combinations
|
| 327 |
+
- **Temporal drift**: Healthcare practices change; model requires periodic retraining
|
| 328 |
+
- **External validity**: Not validated outside New York State
|
| 329 |
+
|
| 330 |
+
### Potential Biases
|
| 331 |
+
|
| 332 |
+
π΄ **Demographic Biases**:
|
| 333 |
+
- **Race/ethnicity**: Model may perpetuate historical disparities in healthcare access
|
| 334 |
+
- Example: Underserved communities may have systematically different LOS due to social determinants
|
| 335 |
+
- **Insurance type**: Self-pay patients may have different discharge patterns
|
| 336 |
+
- **Age**: Older adults (70+) may have higher prediction variance
|
| 337 |
+
|
| 338 |
+
π΄ **Geographic Biases**:
|
| 339 |
+
- **Rural vs. urban**: Smaller rural hospitals may be underrepresented
|
| 340 |
+
- **Hospital resources**: Predictions reflect hospital capacity, not just patient needs
|
| 341 |
+
- **County-level effects**: High-crime or low-income areas may show systemic differences
|
| 342 |
+
|
| 343 |
+
π΄ **Clinical Biases**:
|
| 344 |
+
- **Diagnosis coding**: APR-DRG groupings may oversimplify complex conditions
|
| 345 |
+
- **Severity scoring**: APR severity is administrative, not clinical ground truth
|
| 346 |
+
- **Disposition planning**: Social factors (housing, family support) affect LOS but aren't captured
|
| 347 |
+
|
| 348 |
+
### Bias Mitigation Strategies
|
| 349 |
+
|
| 350 |
+
β
**Implemented**:
|
| 351 |
+
- De-identified data reduces individual privacy risks
|
| 352 |
+
- Included race/ethnicity as features (with caution) to allow disparity analysis
|
| 353 |
+
- Confidence intervals communicate prediction uncertainty
|
| 354 |
+
|
| 355 |
+
β οΈ **Recommended for Production**:
|
| 356 |
+
- **Regular audits** for fairness across demographic groups
|
| 357 |
+
- **Clinician oversight** - never use predictions in isolation
|
| 358 |
+
- **Transparent communication** with patients about prediction limitations
|
| 359 |
+
- **Retraining cadence** (annually or when performance degrades)
|
| 360 |
+
|
| 361 |
+
---
|
| 362 |
+
|
| 363 |
+
## Ethical Considerations
|
| 364 |
+
|
| 365 |
+
### Responsible Use Guidelines
|
| 366 |
+
|
| 367 |
+
1. **Clinical Context Required**
|
| 368 |
+
- Predictions are decision support tools, NOT diagnoses
|
| 369 |
+
- Always review with qualified healthcare professionals
|
| 370 |
+
- Consider patient-specific factors not in the model
|
| 371 |
+
|
| 372 |
+
2. **Transparency with Patients**
|
| 373 |
+
- Explain predictions are estimates, not guarantees
|
| 374 |
+
- Discuss confidence intervals and uncertainty
|
| 375 |
+
- Empower patients to ask questions
|
| 376 |
+
|
| 377 |
+
3. **Avoid Discriminatory Use**
|
| 378 |
+
- Do NOT use predictions to deny care or insurance
|
| 379 |
+
- Monitor for disparate impact across racial/ethnic groups
|
| 380 |
+
- Provide same quality of care regardless of predicted LOS
|
| 381 |
+
|
| 382 |
+
4. **Data Privacy**
|
| 383 |
+
- Model trained on de-identified data
|
| 384 |
+
- Do NOT re-identify patients from predictions
|
| 385 |
+
- Comply with HIPAA and local privacy regulations
|
| 386 |
+
|
| 387 |
+
5. **Model Governance**
|
| 388 |
+
- Document all predictions for audit trails
|
| 389 |
+
- Establish human oversight processes
|
| 390 |
+
- Monitor real-world outcomes vs. predictions
|
| 391 |
+
|
| 392 |
+
### Fairness Analysis
|
| 393 |
+
|
| 394 |
+
**Demographic Parity** (should be analyzed):
|
| 395 |
+
- Prediction distributions should be similar across race/ethnicity groups *for similar clinical profiles*
|
| 396 |
+
- Differences may reflect genuine clinical needs OR systemic biases
|
| 397 |
+
|
| 398 |
+
**Example Analysis**:
|
| 399 |
+
```python
|
| 400 |
+
# Check prediction distributions by race
|
| 401 |
+
results_by_race = df.groupby('Race')['predicted_los'].describe()
|
| 402 |
+
print(results_by_race)
|
| 403 |
+
|
| 404 |
+
# Flag if mean predictions differ by >20% across groups
|
| 405 |
+
# (May indicate bias OR clinical differences - requires clinical review)
|
| 406 |
+
```
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
## Model Card Authors
|
| 411 |
+
|
| 412 |
+
- **Primary Author**: [Ajiboye Toluwalase]
|
| 413 |
+
- **Contributors**: [List contributors]
|
| 414 |
+
- **Contact**: ajiboyetolu1@gmail.com
|
| 415 |
+
- **Organization**: [Metro's Tech]
|
| 416 |
+
|
| 417 |
+
---
|
| 418 |
+
|
| 419 |
+
## Citation
|
| 420 |
+
|
| 421 |
+
If you use this model in your research or application, please cite:
|
| 422 |
+
|
| 423 |
+
```bibtex
|
| 424 |
+
@misc{hospital_los_xgboost_2026,
|
| 425 |
+
author = {Ajiboye Toluwalase},
|
| 426 |
+
title = {Hospital Length of Stay Predictor - XGBoost Pipeline},
|
| 427 |
+
year = {2026},
|
| 428 |
+
publisher = {Hugging Face},
|
| 429 |
+
howpublished = {\url{https://huggingface.co/Ajiboye/hospital_predict_model}},
|
| 430 |
+
note = {Trained on SPARCS NY 2017 dataset}
|
| 431 |
+
}
|
| 432 |
+
```
|
| 433 |
+
|
| 434 |
+
**Data Source Citation**:
|
| 435 |
+
```
|
| 436 |
+
New York State Department of Health. (2017). Hospital Inpatient Discharges
|
| 437 |
+
(SPARCS De-Identified): 2017. https://health.data.ny.gov/
|
| 438 |
+
```
|
| 439 |
+
|
| 440 |
+
---
|
| 441 |
+
|
| 442 |
+
## Model Files
|
| 443 |
+
|
| 444 |
+
This repository contains:
|
| 445 |
+
|
| 446 |
+
```
|
| 447 |
+
hospital-los-xgboost/
|
| 448 |
+
βββ xgb_hospital_full_pipeline.pkl # Complete pipeline (recommended)
|
| 449 |
+
βββ xgb_modelv1.pkl # XGBoost model only
|
| 450 |
+
βββ hospital_data_cleanerv1.pkl # Preprocessor only
|
| 451 |
+
βββ feature_names.pkl # Expected 312 feature names
|
| 452 |
+
βββ README.md # This model card
|
| 453 |
+
βββ requirements.txt # Python dependencies
|
| 454 |
+
|
| 455 |
+
```
|
| 456 |
+
|
| 457 |
+
**Total size**: ~15 MB (compressed)
|
| 458 |
+
|
| 459 |
+
---
|
| 460 |
+
|
| 461 |
+
## Changelog
|
| 462 |
+
|
| 463 |
+
### Version 1.0.0 (February 2026)
|
| 464 |
+
- Initial release
|
| 465 |
+
- Trained on SPARCS 2017 dataset (2.3M records)
|
| 466 |
+
- 13 input features β 312 encoded features
|
| 467 |
+
- XGBoost regressor with target-encoded features
|
| 468 |
+
- Confidence interval estimation
|
| 469 |
+
- Risk factor analysis
|
| 470 |
+
|
| 471 |
+
### Planned Updates
|
| 472 |
+
- [ ] Retrain on 2022-2024 data
|
| 473 |
+
- [ ] Add SHAP explanations
|
| 474 |
+
- [ ] Incorporate CMS quality metrics
|
| 475 |
+
- [ ] Multi-output prediction (LOS + readmission risk)
|
| 476 |
+
- [ ] Fairness-aware training
|
| 477 |
+
|
| 478 |
+
---
|
| 479 |
+
|
| 480 |
+
## Acknowledgments
|
| 481 |
+
|
| 482 |
+
- **New York State Department of Health** for SPARCS data access
|
| 483 |
+
- **Kaggle community** for data hosting and discussions
|
| 484 |
+
- **XGBoost development team** for the excellent ML framework
|
| 485 |
+
- **Hugging Face** for model hosting infrastructure
|
| 486 |
+
|
| 487 |
+
---
|
| 488 |
+
|
| 489 |
+
## License
|
| 490 |
+
|
| 491 |
+
This model is released under the **MIT License**.
|
| 492 |
+
|
| 493 |
+
```
|
| 494 |
+
MIT License
|
| 495 |
+
|
| 496 |
+
Copyright (c) 2025 [Ajiboye Toluwalase]
|
| 497 |
+
|
| 498 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 499 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 500 |
+
in the Software without restriction, including without limitation the rights
|
| 501 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 502 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 503 |
+
furnished to do so, subject to the following conditions:
|
| 504 |
+
|
| 505 |
+
The above copyright notice and this permission notice shall be included in all
|
| 506 |
+
copies or substantial portions of the Software.
|
| 507 |
+
|
| 508 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 509 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 510 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
| 511 |
+
```
|
| 512 |
+
|
| 513 |
+
---
|
| 514 |
+
|
| 515 |
+
## Additional Resources
|
| 516 |
+
|
| 517 |
+
- π [Live Demo](https://your-demo-url.com)
|
| 518 |
+
- π» [GitHub Repository](https://github.com/metrosmash/Hospital_LOS_Predictor)
|
| 519 |
+
- π [Technical Documentation](https://your-docs-url.com)
|
| 520 |
+
- π¬ [Model Training Notebook](https://colab.research.google.com/your-notebook)
|
| 521 |
+
- π§ [Contact for Collaboration](mailto:ajiboyetolu1@gmail.com)
|
| 522 |
+
|
| 523 |
+
---
|
| 524 |
+
|
| 525 |
+
**βοΈ Remember**: This model is a tool to support healthcare professionals, not replace them. Always involve clinical expertise in patient care decisions.
|
| 526 |
+
|
| 527 |
+
---
|
| 528 |
+
|
| 529 |
+
*Last updated: February 2026*
|