RICHERGIRL commited on
Commit
642e4b0
·
verified ·
1 Parent(s): e911fa0

Update model/random_forest.pkl

Browse files
Files changed (1) hide show
  1. model/random_forest.pkl +22 -18
model/random_forest.pkl CHANGED
@@ -1,36 +1,40 @@
1
- # Re-run this corrected version of train_model.py
2
- import pandas as pd
3
  from sklearn.ensemble import RandomForestClassifier
4
  from sklearn.preprocessing import LabelEncoder
5
  import joblib
 
6
  import os
7
 
8
- # Create fresh data
9
  data = {
10
- 'face_shape': ['Oval', 'Round', 'Square'] * 50,
11
- 'skin_tone': ['Fair', 'Medium', 'Dark'] * 50,
12
- 'face_size': ['Small', 'Medium', 'Large'] * 50,
13
- 'mask_style': ['Glitter', 'Animal', 'Floral'] * 50
14
  }
15
  df = pd.DataFrame(data)
16
 
17
- # Create and save new encoders
18
- encoders = {col: LabelEncoder().fit(df[col].unique())
19
- for col in ['face_shape', 'skin_tone', 'face_size', 'mask_style']}
 
 
20
 
21
- # Train new model
22
- model = RandomForestClassifier(n_estimators=100, random_state=42)
 
 
 
 
23
  model.fit(
24
  pd.DataFrame({col: encoders[col].transform(df[col])
25
  for col in ['face_shape', 'skin_tone', 'face_size']}),
26
  encoders['mask_style'].transform(df['mask_style'])
27
  )
28
 
29
- # Save properly
30
  os.makedirs('model', exist_ok=True)
31
- joblib.dump(model, 'model/random_forest.pkl')
32
- joblib.dump(encoders, 'model/label_encoders.pkl')
33
 
34
- # Add this to your app.py before loading
35
- print("Current directory:", os.listdir())
36
- print("Model directory:", os.listdir('model'))
 
1
+ # train_model.py (corrected)
 
2
  from sklearn.ensemble import RandomForestClassifier
3
  from sklearn.preprocessing import LabelEncoder
4
  import joblib
5
+ import pandas as pd
6
  import os
7
 
8
+ # 1. Create sample data
9
  data = {
10
+ 'face_shape': ['Oval', 'Round', 'Square'] * 100,
11
+ 'skin_tone': ['Fair', 'Medium', 'Dark'] * 100,
12
+ 'face_size': ['Small', 'Medium', 'Large'] * 100,
13
+ 'mask_style': ['StyleA', 'StyleB', 'StyleC'] * 100
14
  }
15
  df = pd.DataFrame(data)
16
 
17
+ # 2. Create and fit encoders
18
+ encoders = {
19
+ col: LabelEncoder().fit(df[col])
20
+ for col in ['face_shape', 'skin_tone', 'face_size', 'mask_style']
21
+ }
22
 
23
+ # 3. Train model
24
+ model = RandomForestClassifier(
25
+ n_estimators=50,
26
+ random_state=42,
27
+ max_depth=5
28
+ )
29
  model.fit(
30
  pd.DataFrame({col: encoders[col].transform(df[col])
31
  for col in ['face_shape', 'skin_tone', 'face_size']}),
32
  encoders['mask_style'].transform(df['mask_style'])
33
  )
34
 
35
+ # 4. Save with protocol=4 for compatibility
36
  os.makedirs('model', exist_ok=True)
37
+ joblib.dump(model, 'model/random_forest.pkl', protocol=4)
38
+ joblib.dump(encoders, 'model/label_encoders.pkl', protocol=4)
39
 
40
+ print("Model saved successfully!")