Spaces:
Runtime error
Runtime error
Update heart_utils.py
Browse files- heart_utils.py +17 -6
heart_utils.py
CHANGED
|
@@ -1,10 +1,21 @@
|
|
| 1 |
import joblib
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import joblib
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
+
# Load the trained heart disease model
|
| 5 |
+
heart_model = joblib.load("heart_model.joblib")
|
| 6 |
|
| 7 |
+
def encode_sex(sex):
|
| 8 |
+
return 1 if sex == "Male" else 0
|
| 9 |
+
|
| 10 |
+
def predict_heart(age, sex, cp, trestbps, chol, fbs, restecg,
|
| 11 |
+
thalach, exang, oldpeak, slope, ca, thal):
|
| 12 |
+
# Encode 'sex' from string to numeric
|
| 13 |
+
sex_encoded = encode_sex(sex)
|
| 14 |
+
|
| 15 |
+
# Create feature array (13 features)
|
| 16 |
+
features = np.array([[age, sex_encoded, cp, trestbps, chol, fbs, restecg,
|
| 17 |
+
thalach, exang, oldpeak, slope, ca, thal]])
|
| 18 |
+
|
| 19 |
+
# Predict using the loaded model
|
| 20 |
+
prediction = heart_model.predict(features)[0]
|
| 21 |
+
return "Heart Disease Detected" if prediction == 1 else "No Heart Disease Detected"
|