-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathml_model.py
More file actions
32 lines (26 loc) · 888 Bytes
/
Copy pathml_model.py
File metadata and controls
32 lines (26 loc) · 888 Bytes
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
# core/ml_model.py
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.preprocessing import LabelEncoder
import joblib
import os
# Paths
data_path = "data/sessions.csv"
model_dir = "core/models"
os.makedirs(model_dir, exist_ok=True)
# Load CSV
df = pd.read_csv(data_path)
df = df.dropna() # remove incomplete rows
# Features & labels
X = df[['mouth_asym','eye_asym','brow_asym','fsi','pitch_var','jitter','shimmer','clarity_score']]
y = df['house_brackmann_grade']
# Encode labels
le = LabelEncoder()
y_enc = le.fit_transform(y)
# Train model
clf = RandomForestClassifier(n_estimators=100, random_state=42)
clf.fit(X, y_enc)
# Save model
joblib.dump(clf, os.path.join(model_dir,"housebrackmann_model.pkl"))
joblib.dump(le, os.path.join(model_dir,"label_encoder.pkl"))
print("ML model trained and saved successfully.")