Views
No views yet
RandomForestClassifier (scikit-learn)0 → No heart disease1 → Heart disease presentheart_disease_model.joblibHeartDiseasePredictionProject.ipynbheart-disease.csv.target)1: 1650: 138| Feature | Description |
|---|---|
age | Age in years |
sex | Sex (commonly encoded as 1 = male, 0 = female) |
cp | Chest pain type (categorical encoded as integers) |
trestbps | Resting blood pressure |
chol | Serum cholesterol |
fbs | Fasting blood sugar (binary) |
restecg | Resting ECG results (categorical encoded as integers) |
thalach | Maximum heart rate achieved |
exang | Exercise-induced angina (binary) |
oldpeak | ST depression induced by exercise relative to rest |
slope | Slope of peak exercise ST segment (categorical encoded as integers) |
ca | Number of major vessels (categorical encoded as integers) |
thal | Thalassemia category (categorical encoded as integers) |
train_test_split(test_size=0.2)np.random.seed(42) in the notebookRandomizedSearchCV used to tune Random Forest
cv=5, n_iter=20n_estimators=210max_depth=3min_samples_split=4min_samples_leaf=19heart_disease_model.joblib) corresponds to:RandomForestClassifier(n_estimators=210, max_depth=3, min_samples_split=4, min_samples_leaf=19)pip install scikit-learn joblib pandas numpy huggingface_hub1from huggingface_hub import hf_hub_download
2import joblib
3import pandas as pd
4
5# Replace with your HF repo id, e.g. "brej-29/heart-disease-prediction-rf"
6repo_id = "YOUR_USERNAME/YOUR_MODEL_REPO"
7
8model_path = hf_hub_download(
9 repo_id=repo_id,
10 filename="heart_disease_model.joblib"
11)
12
13model = joblib.load(model_path)
14
15# Example input (values are placeholders; use correctly-encoded values)
16sample = pd.DataFrame([{
17 "age": 57,
18 "sex": 1,
19 "cp": 0,
20 "trestbps": 120,
21 "chol": 354,
22 "fbs": 0,
23 "restecg": 1,
24 "thalach": 163,
25 "exang": 1,
26 "oldpeak": 0.6,
27 "slope": 2,
28 "ca": 0,
29 "thal": 2
30}])
31
32pred = model.predict(sample)[0]
33proba = model.predict_proba(sample)[0, 1] # probability of class "1"
34
35print("Prediction:", int(pred))
36print("P(heart disease):", float(proba))cp, restecg, slope, ca, thal) follow the same integer encoding as used in trainingint/float); no missing valuesheart_disease_model.joblib)