Skip to main content
•
Updated:
•
3 min read

Cleveland Heart Disease Prediction with Logistic Regression

A logistic regression model that predicts the presence of heart disease from routine clinical measurements, built on the Cleveland Heart Disease dataset. The work is as much about the data as the model: heavy missingness, clinically meaningful feature engineering, and coefficients that line up with established cardiovascular risk factors.

Educational project, not a medical device. Nothing here is validated for diagnosis or clinical use.

Results

Metric Score
Accuracy 82.1%
Precision 82.2%
Recall 86.3%
F1 84.2%
Specificity 77%

Measured on a held-out split of 184 patients: 88 true positives, 63 true negatives, 19 false positives and 14 false negatives.

The data

920 patients and 16 original features from the Cleveland Clinic Foundation, the Hungarian Institute of Cardiology, and the university hospitals of Zurich and Basel. The target is binary — disease present or absent — with 55.3% positive cases.

Missingness defines the preprocessing. ca is absent in 66.4% of rows, thal in 52.8%, slope in 33.6%, and the rest sit between 3% and 10%. Numeric columns are median-imputed and categorical ones by most frequent value.

Feature engineering

The pipeline expands 16 columns into roughly 40 features built around clinical thresholds rather than arbitrary bins:

  • Blood pressure — hypertension stage 1 and 2, hypotension
  • Cholesterol — high (≥240), borderline (200–240), normal (<200)
  • Age bands — under 45, 45–64, 65 and older
  • Exercise response — age-adjusted heart-rate reserve, exercise-induced angina
  • ST depression — significant (≥2.0), mild (1.0–2.0), normal (<1.0)
  • Coronary anatomy — no vessel, one vessel, two or more

Composite scores count the major risk factors and flag patients with three or more.

Model

One logistic regression, tuned by five-fold cross-validation with balanced class weights:

LogisticRegression(
    solver="lbfgs",
    C=0.1,
    class_weight="balanced",
    max_iter=1000,
    random_state=42,
)

The coefficients read in clinical terms:

Feature Effect on the odds of disease
Male sex +58.9%
Exercise-induced angina +47%
Age +33.7% per year
Chest-pain risk score rises with the score
Cholesterol slightly protective in this cohort

The cholesterol result is a known quirk of this dataset, not a finding to act on. The rest match the risk factors a cardiologist would name first.

Run it

git clone https://public.omerduran.dev/omer/riskfactor-heart.git
cd riskfactor-heart
uv sync
uv run main.py

The script downloads the dataset, runs the pipeline and writes a figure with the confusion matrix and the top coefficients.

Limitations

  • One historical cohort, not representative of today’s population.
  • Binary outcome only: no severity, no time to event.
  • No external validation; the numbers describe this dataset and nothing beyond it.

License

MIT — see LICENSE in the repository.