Heart Risk Prediction Studio
Educational project · NOT a medical diagnosis · Uncalibrated model scoreOffline UCI Cleveland cardiovascular modeling (303 records, 13 clinical inputs): median/mode imputation, standardization, and exact 28-feature Logistic Regression formula.
Interactive Heart Risk Prediction Workspace
Enter 13 clinical measurements (accepts Latin, Persian ۰-۹, and Arabic-Indic ٠-٩ digits with ., ,, or ٫ decimal separators), or load a real UCI Cleveland reference case below to verify missing-value imputation and exact scikit-learn parity.
Per-Feature Log-Odds Contributions (Δz)
Because Logistic Regression is strictly additive in log-odds space (z = intercept + Σ coef_i · x_i), each input feature's exact signed contribution to z is computed directly from the active preprocessed vector.
Transformed 28-Feature Vector & Coefficients
Numeric features are median-imputed and standardized (x − mean) / scale; categorical features are mode-imputed and one-hot encoded (handle_unknown = "ignore", unseen categories become all zeros). Concatenation order matches output_features[0..27] exactly.
Published Evaluation Metrics & Honest Limits
Evaluated on a stratified 80/20 split (242 training patients, 61 held-out test patients) with all imputation, scaling, and one-hot encoding fitted strictly inside the pipeline to prevent data leakage.
- Active Web Model
LogisticRegression(max_iter=1000, C=1.0)exported from the 242-row training split as exact preprocessing constants + 28 weights (scikit-learn 1.6.1).- 5-Fold Stratified CV
- ROC-AUC 0.9025 ± 0.0144 on the 242-row training split (GridSearchCV over
C ∈ [0.01, 0.1, 1, 10]). - Held-out Test Split (61)
- ROC-AUC 0.9665 · Recall 0.9286 · Precision 0.8387 (inspected once after locking
C = 1.0). - Formula Parity Check
- Matches scikit-learn
predict_probawithin5.2e-15max absolute difference across all 303 UCI Cleveland rows (303/303identical class @0.5).
5-Fold Cross-Validation Model Comparison (Training Split)
| Model | 5-Fold CV ROC-AUC | Notes |
|---|---|---|
| Logistic Regression (active formula) | 0.902 | Closed-form linear model used by offline web & mobile clients (C=1.0) |
| Random Forest | 0.894 | Tuned RF reaches CV AUC 0.904; Streamlit RF test AUC 0.955 (TN 27, FP 6, FN 3, TP 25) |
| SVM | 0.888 | Within 1 SD of top models on 242-patient training split |
| KNN | 0.872 | 5-fold stratified CV on training set |
| Gradient Boosting | 0.857 | 5-fold stratified CV on training set |
| Decision Tree | 0.786 | Single tree baseline |
| Dummy baseline | 0.500 | Chance baseline |
- Small single-center dataset (303 records): with only 61 held-out test patients (28 positive), test metrics fluctuate noticeably; 5-fold CV AUC (~0.90) is the more conservative indicator.
- No external validation: the model has not been evaluated on patients from other hospitals or populations.
- Specialized clinical inputs: features such as fluoroscopy major vessels (
ca) and thallium scan (thal) require specialized medical testing and are not general-public measurements. - Associations, not causation: Logistic Regression weights reflect statistical correlations inside the Cleveland dataset, not causal mechanisms.
Preprocessing & Inference Specification
- Stratified Split Before Fitting:
train_test_split(test_size=0.2, random_state=42, stratify=y)separates 242 training rows from 61 test rows prior to computing medians, means, scales, or modes. - Numeric Block (order:
age, trestbps, chol, thalach, oldpeak): Missing values are imputed with training column medians; each value is standardized via(v - mean) / scale. - Categorical Block (order:
sex, cp, fbs, restecg, exang, slope, ca, thal): Missing values are imputed with training column modes; known categories emit one-hot1.0/0.0flags matchingOneHotEncoder(handle_unknown="ignore")(unknown codes emit all zeros). - Linear Combination & Sigmoid: Computes
z = intercept + sum(coef[i] * x[i])over all 28 transformed features and outputs1 / (1 + exp(-z)).
← Biomedical AI LabHeart Risk case study ↗ECG Analysis Studio →EEG Analysis Studio →