File size: 746 Bytes
2ed073c
 
 
d022159
 
2ed073c
d022159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import joblib
import numpy as np

# Load the trained heart disease model
heart_model = joblib.load("heart_model.joblib")

def encode_sex(sex):
    return 1 if sex == "Male" else 0

def predict_heart(age, sex, cp, trestbps, chol, fbs, restecg,
                  thalach, exang, oldpeak, slope, ca, thal):
    # Encode 'sex' from string to numeric
    sex_encoded = encode_sex(sex)

    # Create feature array (13 features)
    features = np.array([[age, sex_encoded, cp, trestbps, chol, fbs, restecg,
                          thalach, exang, oldpeak, slope, ca, thal]])

    # Predict using the loaded model
    prediction = heart_model.predict(features)[0]
    return "Heart Disease Detected" if prediction == 1 else "No Heart Disease Detected"