Jimin Park commited on
Commit
6eabb8e
·
1 Parent(s): 299f9c4

kermitting soon

Browse files
Files changed (1) hide show
  1. util/app.py +13 -0
util/app.py CHANGED
@@ -207,6 +207,8 @@ def show_stats(player_opgg_url):
207
 
208
  def predict_champion(player_opgg_url, *champions):
209
  """Make prediction based on selected champions"""
 
 
210
  if not player_opgg_url or None in champions:
211
  return "Please fill in all fields"
212
 
@@ -219,6 +221,7 @@ def predict_champion(player_opgg_url, *champions):
219
 
220
  # Get and process the data
221
  training_df = get_user_training_df(player_opgg_url)
 
222
 
223
  if isinstance(training_df, str): # Error message
224
  return training_df
@@ -226,28 +229,36 @@ def predict_champion(player_opgg_url, *champions):
226
  # Apply necessary transformations
227
  training_df = convert_df(training_df)
228
  training_df = apply_feature_engineering(training_df)
 
229
 
230
  # Get feature columns (excluding champion and region)
231
  feature_columns = [col for col in training_df.columns
232
  if col not in ['champion', 'region', 'stratify_label']]
233
  X = training_df[feature_columns]
 
234
 
235
  # Handle categorical features
236
  categorical_columns = X.select_dtypes(include=['category']).columns
237
  X_processed = X.copy()
 
238
 
239
  # Convert categorical columns to numeric
240
  for col in categorical_columns:
241
  X_processed[col] = X_processed[col].cat.codes
 
242
 
243
  # Convert to float32
244
  X_processed = X_processed.astype('float32')
 
245
 
246
  # Create DMatrix with categorical feature support
247
  dtest = DMatrix(X_processed, enable_categorical=True)
 
248
 
249
  # Make prediction
 
250
  predictions = model.predict(dtest)
 
251
 
252
  # Get the highest probability prediction
253
  if len(predictions.shape) > 1:
@@ -257,8 +268,10 @@ def predict_champion(player_opgg_url, *champions):
257
 
258
  # Decode predictions using loaded label encoder
259
  decoded_preds = label_encoder.inverse_transform(pred_indices)
 
260
 
261
  # Return the first prediction
 
262
  return f"Predicted champion: {decoded_preds[0]}"
263
 
264
  except Exception as e:
 
207
 
208
  def predict_champion(player_opgg_url, *champions):
209
  """Make prediction based on selected champions"""
210
+
211
+ print("==================== Inside: predict_champion() ===================== \n")
212
  if not player_opgg_url or None in champions:
213
  return "Please fill in all fields"
214
 
 
221
 
222
  # Get and process the data
223
  training_df = get_user_training_df(player_opgg_url)
224
+ print("training_df retrieved: ", training_df, "\n")
225
 
226
  if isinstance(training_df, str): # Error message
227
  return training_df
 
229
  # Apply necessary transformations
230
  training_df = convert_df(training_df)
231
  training_df = apply_feature_engineering(training_df)
232
+ print("training_df converted and feature engineered: ", training_df, "\n")
233
 
234
  # Get feature columns (excluding champion and region)
235
  feature_columns = [col for col in training_df.columns
236
  if col not in ['champion', 'region', 'stratify_label']]
237
  X = training_df[feature_columns]
238
+ print("Got feature columns X: ", X, "\n")
239
 
240
  # Handle categorical features
241
  categorical_columns = X.select_dtypes(include=['category']).columns
242
  X_processed = X.copy()
243
+ print("Handled categorical features, X_processed = ", X_processed, "\n")
244
 
245
  # Convert categorical columns to numeric
246
  for col in categorical_columns:
247
  X_processed[col] = X_processed[col].cat.codes
248
+ print("Converted categorical columns to numeric: ", categorical_columns, "\n")
249
 
250
  # Convert to float32
251
  X_processed = X_processed.astype('float32')
252
+ print("Converted X_processed to float32: ", X_processed, "\n")
253
 
254
  # Create DMatrix with categorical feature support
255
  dtest = DMatrix(X_processed, enable_categorical=True)
256
+ print("Converted to Dmatrix: ", dtest, "\n")
257
 
258
  # Make prediction
259
+ print("Starting model prediction...\n")
260
  predictions = model.predict(dtest)
261
+ print("Model prediction complete\n")
262
 
263
  # Get the highest probability prediction
264
  if len(predictions.shape) > 1:
 
268
 
269
  # Decode predictions using loaded label encoder
270
  decoded_preds = label_encoder.inverse_transform(pred_indices)
271
+ print("Decoded predictions: ", decoded_preds, "\n")
272
 
273
  # Return the first prediction
274
+ print("==================== Exiting: predict_champion()===================\n")
275
  return f"Predicted champion: {decoded_preds[0]}"
276
 
277
  except Exception as e: