rangerrRed commited on
Commit
d022159
·
verified ·
1 Parent(s): 6830370

Update heart_utils.py

Browse files
Files changed (1) hide show
  1. heart_utils.py +17 -6
heart_utils.py CHANGED
@@ -1,10 +1,21 @@
1
  import joblib
2
  import numpy as np
3
 
4
- model = joblib.load("heart_model.joblib")
 
5
 
6
- def predict_heart(age, sex, cp, trestbps, chol):
7
- sex = 1 if sex == "Male" else 0
8
- data = np.array([[age, sex, cp, trestbps, chol]])
9
- prediction = model.predict(data)
10
- return "High Risk" if prediction[0] == 1 else "Low Risk"
 
 
 
 
 
 
 
 
 
 
 
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"