Jimin Park commited on
Commit
cf0a632
·
1 Parent(s): d3292b9

kermitting soon

Browse files
Files changed (3) hide show
  1. requirements.txt +1 -0
  2. util/app.py +22 -7
  3. util/label_encoder.joblib +3 -0
requirements.txt CHANGED
@@ -7,3 +7,4 @@ numpy==1.26.0
7
  scikit-learn==1.3.1
8
  selenium==4.27.1
9
  webdriver-manager== 4.0.2
 
 
7
  scikit-learn==1.3.1
8
  selenium==4.27.1
9
  webdriver-manager== 4.0.2
10
+ joblib
util/app.py CHANGED
@@ -8,6 +8,7 @@ import pandas as pd
8
  from sklearn.model_selection import train_test_split
9
  from sklearn.preprocessing import LabelEncoder
10
  from helper import *
 
11
 
12
 
13
  # Define champion list for dropdowns
@@ -43,6 +44,13 @@ except Exception as e:
43
  print(f"Error loading model: {e}")
44
  model = None
45
 
 
 
 
 
 
 
 
46
  # Functions
47
  def get_user_training_df(player_opgg_url):
48
  try:
@@ -82,7 +90,7 @@ def prepare_training_df(df, target_column='champion', stratify_columns=['champio
82
 
83
  category_mappings = {}
84
  temp_encoded_df = df.copy()
85
-
86
  # Convert categorical columns to codes but keep original data
87
  for col in categorical_columns:
88
  if col in df.columns:
@@ -91,7 +99,7 @@ def prepare_training_df(df, target_column='champion', stratify_columns=['champio
91
  'ordered': df[col].cat.ordered
92
  }
93
  temp_encoded_df[col] = df[col].cat.codes
94
-
95
  # Remove combinations with too few samples
96
  combo_counts = df['stratify_label'].value_counts()
97
  valid_combos = combo_counts[combo_counts >= min_samples_per_class].index
@@ -138,6 +146,7 @@ def prepare_training_df(df, target_column='champion', stratify_columns=['champio
138
 
139
  print("X_val: ", X_val, "\n X_val type: ", type(X_val), "\n y_val: ", y_val, "\n y_val type: ", type(y_val))
140
 
 
141
  # Restore categorical dtypes
142
  for col in categorical_columns:
143
  if col in X_train.columns:
@@ -156,7 +165,7 @@ def prepare_training_df(df, target_column='champion', stratify_columns=['champio
156
  categories=category_mappings[col]['categories'],
157
  ordered=category_mappings[col]['ordered']
158
  )
159
-
160
 
161
  return X_train, X_val, X_test, y_train, y_val, y_test, label_encoder
162
 
@@ -207,6 +216,8 @@ def predict_champion(player_opgg_url, *champions):
207
  try:
208
  if model is None:
209
  return "Model not loaded properly"
 
 
210
 
211
  print("============= Inside predict_champion(): Model loaded properly=================\n")
212
 
@@ -226,8 +237,8 @@ def predict_champion(player_opgg_url, *champions):
226
  target_column='champion',
227
  stratify_columns=['champion', 'region'],
228
  min_samples_per_class=5,
229
- train_size=0.6,
230
- val_size=0.2,
231
  random_state=42
232
  )
233
  print("type(X_test): ", type(X_test), "\n")
@@ -241,9 +252,13 @@ def predict_champion(player_opgg_url, *champions):
241
 
242
  prediction = model.predict(X_test)
243
 
244
- print("prediction", prediction , "\n")
 
 
 
 
245
 
246
- return f"Predicted champion: {prediction}"
247
  except Exception as e:
248
  return f"Error making prediction: {e}"
249
 
 
8
  from sklearn.model_selection import train_test_split
9
  from sklearn.preprocessing import LabelEncoder
10
  from helper import *
11
+ import joblib
12
 
13
 
14
  # Define champion list for dropdowns
 
44
  print(f"Error loading model: {e}")
45
  model = None
46
 
47
+ # Load the saved LabelEncoder
48
+ try:
49
+ label_encoder = joblib.load('label_encoder.joblib')
50
+ except Exception as e:
51
+ print(f"Error loading label encoder: {e}")
52
+ label_encoder = None
53
+
54
  # Functions
55
  def get_user_training_df(player_opgg_url):
56
  try:
 
90
 
91
  category_mappings = {}
92
  temp_encoded_df = df.copy()
93
+ '''
94
  # Convert categorical columns to codes but keep original data
95
  for col in categorical_columns:
96
  if col in df.columns:
 
99
  'ordered': df[col].cat.ordered
100
  }
101
  temp_encoded_df[col] = df[col].cat.codes
102
+ '''
103
  # Remove combinations with too few samples
104
  combo_counts = df['stratify_label'].value_counts()
105
  valid_combos = combo_counts[combo_counts >= min_samples_per_class].index
 
146
 
147
  print("X_val: ", X_val, "\n X_val type: ", type(X_val), "\n y_val: ", y_val, "\n y_val type: ", type(y_val))
148
 
149
+ '''
150
  # Restore categorical dtypes
151
  for col in categorical_columns:
152
  if col in X_train.columns:
 
165
  categories=category_mappings[col]['categories'],
166
  ordered=category_mappings[col]['ordered']
167
  )
168
+ '''
169
 
170
  return X_train, X_val, X_test, y_train, y_val, y_test, label_encoder
171
 
 
216
  try:
217
  if model is None:
218
  return "Model not loaded properly"
219
+ if label_encoder is None:
220
+ return "Label encoder not loaded properly"
221
 
222
  print("============= Inside predict_champion(): Model loaded properly=================\n")
223
 
 
237
  target_column='champion',
238
  stratify_columns=['champion', 'region'],
239
  min_samples_per_class=5,
240
+ train_size=0,
241
+ val_size=1,
242
  random_state=42
243
  )
244
  print("type(X_test): ", type(X_test), "\n")
 
252
 
253
  prediction = model.predict(X_test)
254
 
255
+ print("prediction: ", prediction , "\n")
256
+
257
+ # Decode predictions (if using LabelEncoder)
258
+ decoded_preds = label_encoder.inverse_transform(prediction)
259
+ print("decoded_preds: ", decoded_preds, "\n")
260
 
261
+ return f"Predicted champion: {decoded_preds}"
262
  except Exception as e:
263
  return f"Error making prediction: {e}"
264
 
util/label_encoder.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:38ec04acda4d7987202f744bcc40b7d02d8374f55c17f5701840320e6b07ff29
3
+ size 1541