Heart Risk Prediction Studio

Educational project · NOT a medical diagnosis · Uncalibrated model score

Offline UCI Cleveland cardiovascular modeling (303 records, 13 clinical inputs): median/mode imputation, standardization, and exact 28-feature Logistic Regression formula.

Loading Logistic Regression parameters (model.json) & golden cases…
heart risk prediction · 13 uci cleveland inputs

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.

Range: 20 – 100
Range: 80 – 220
Range: 100 – 600
Range: 60 – 220
Range: 0 – 7
linear interpretability · exact feature contributions

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.

preprocessing parity · 13 inputs → 28 model features

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.

evaluation · uci cleveland 80/20 split · cv comparison

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_proba within 5.2e-15 max absolute difference across all 303 UCI Cleveland rows (303/303 identical class @0.5).

5-Fold Cross-Validation Model Comparison (Training Split)

Model5-Fold CV ROC-AUCNotes
Logistic Regression (active formula)0.902Closed-form linear model used by offline web & mobile clients (C=1.0)
Random Forest0.894Tuned RF reaches CV AUC 0.904; Streamlit RF test AUC 0.955 (TN 27, FP 6, FN 3, TP 25)
SVM0.888Within 1 SD of top models on 242-patient training split
KNN0.8725-fold stratified CV on training set
Gradient Boosting0.8575-fold stratified CV on training set
Decision Tree0.786Single tree baseline
Dummy baseline0.500Chance baseline
Honest Limitations:
  • 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.
leakage-free pipeline · arithmetic recipe

Preprocessing & Inference Specification

  1. 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.
  2. Numeric Block (order: age, trestbps, chol, thalach, oldpeak): Missing values are imputed with training column medians; each value is standardized via (v - mean) / scale.
  3. Categorical Block (order: sex, cp, fbs, restecg, exang, slope, ca, thal): Missing values are imputed with training column modes; known categories emit one-hot 1.0/0.0 flags matching OneHotEncoder(handle_unknown="ignore") (unknown codes emit all zeros).
  4. Linear Combination & Sigmoid: Computes z = intercept + sum(coef[i] * x[i]) over all 28 transformed features and outputs 1 / (1 + exp(-z)).

← Biomedical AI LabHeart Risk case study ↗ECG Analysis Studio →EEG Analysis Studio →