-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathml_utils.py
More file actions
38 lines (33 loc) · 1.33 KB
/
ml_utils.py
File metadata and controls
38 lines (33 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# ml_utils.py
import numpy as np
TIP_MAP = {
"Normal": [
"Maintain a balanced diet rich in iron, vitamin B12 and folate.",
"Keep doing routine health check-ups.",
"Stay hydrated and active."
],
"Anemia": [
"Increase iron-rich foods such as leafy greens, red meat, and pulses.",
"Avoid tea and coffee immediately after meals to help iron absorption.",
"Consult a doctor for further evaluation and supplements if needed."
],
"Unknown": [
"Please consult a healthcare provider for proper evaluation."
]
}
def prepare_features(age, gender, hb, mch, mchc, mcv):
"""
Prepare feature array according to model expectations.
Adjust mapping if your model expects different encoding.
Current mapping: gender: female->0, male->1, other->2
Feature order: [gender_val, hb, mch, mchc, mcv]
"""
g = (gender or "").lower()
gender_map = {"female": 0, "male": 1, "other": 2}
gender_val = gender_map.get(g, 2)
mch_val = float(mch) if mch not in (None, "", "None") else 0.0
mchc_val = float(mchc) if mchc not in (None, "", "None") else 0.0
mcv_val = float(mcv) if mcv not in (None, "", "None") else 0.0
return np.array([[gender_val, float(hb), mch_val, mchc_val, mcv_val]])
def get_tips(category):
return TIP_MAP.get(category, TIP_MAP["Unknown"])