Spaces:
Configuration error
Configuration error
Create train_model.py
Browse files- train_model.py +31 -0
train_model.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 3 |
+
from sklearn.preprocessing import LabelEncoder
|
| 4 |
+
import joblib
|
| 5 |
+
|
| 6 |
+
# Load your dataset
|
| 7 |
+
df = pd.read_csv("mask_dataset.csv")
|
| 8 |
+
|
| 9 |
+
# Encode features
|
| 10 |
+
face_shape_encoder = LabelEncoder()
|
| 11 |
+
skin_tone_encoder = LabelEncoder()
|
| 12 |
+
style_encoder = LabelEncoder()
|
| 13 |
+
|
| 14 |
+
X = pd.DataFrame({
|
| 15 |
+
'face_shape': face_shape_encoder.fit_transform(df['face_shape']),
|
| 16 |
+
'skin_tone': skin_tone_encoder.fit_transform(df['skin_tone'])
|
| 17 |
+
})
|
| 18 |
+
|
| 19 |
+
y = style_encoder.fit_transform(df['recommended_style'])
|
| 20 |
+
|
| 21 |
+
# Train the model
|
| 22 |
+
model = RandomForestClassifier(n_estimators=100, random_state=42)
|
| 23 |
+
model.fit(X, y)
|
| 24 |
+
|
| 25 |
+
# Save the model and encoders
|
| 26 |
+
joblib.dump(model, "mask_model.pkl")
|
| 27 |
+
joblib.dump(face_shape_encoder, "face_shape_encoder.pkl")
|
| 28 |
+
joblib.dump(skin_tone_encoder, "skin_tone_encoder.pkl")
|
| 29 |
+
joblib.dump(style_encoder, "style_encoder.pkl")
|
| 30 |
+
|
| 31 |
+
print("✅ Training complete. Model and encoders saved.")
|