Jimin Park commited on
Commit
d756d90
·
1 Parent(s): 587c8e8

kermitting soon

Browse files
Files changed (1) hide show
  1. util/app.py +37 -8
util/app.py CHANGED
@@ -218,6 +218,11 @@ def predict_champion(player_opgg_url, *champions):
218
 
219
  if label_encoder is None:
220
  return "Label encoder not loaded properly"
 
 
 
 
 
221
 
222
  # Get and process the data
223
  training_df = get_user_training_df(player_opgg_url)
@@ -259,20 +264,44 @@ def predict_champion(player_opgg_url, *champions):
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:
265
  pred_indices = predictions.argmax(axis=1)
266
  else:
267
  pred_indices = predictions.astype(int)
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:
278
  import traceback
 
218
 
219
  if label_encoder is None:
220
  return "Label encoder not loaded properly"
221
+
222
+ # Print label encoder information
223
+ print("\nLabel Encoder Information:")
224
+ print("Classes in encoder:", label_encoder.classes_)
225
+ print("Number of classes:", len(label_encoder.classes_))
226
 
227
  # Get and process the data
228
  training_df = get_user_training_df(player_opgg_url)
 
264
  print("Starting model prediction...\n")
265
  predictions = model.predict(dtest)
266
  print("Model prediction complete\n")
267
+
268
+ print("\nPrediction Information:")
269
+ print("Raw predictions shape:", predictions.shape)
270
+ print("Raw predictions:", predictions)
271
 
272
  # Get the highest probability prediction
273
  if len(predictions.shape) > 1:
274
  pred_indices = predictions.argmax(axis=1)
275
  else:
276
  pred_indices = predictions.astype(int)
277
+
278
+ print("\nPrediction Indices:")
279
+ print("Indices shape:", pred_indices.shape)
280
+ print("Indices:", pred_indices)
281
+
282
+ # Check if indices are within valid range
283
+ print("\nValidation:")
284
+ print("Min index:", pred_indices.min())
285
+ print("Max index:", pred_indices.max())
286
+ print("Valid index range:", 0, len(label_encoder.classes_) - 1)
287
+ # Try to decode predictions
288
+
289
+ try:
290
+ decoded_preds = label_encoder.inverse_transform(pred_indices)
291
+ print("\nDecoded Predictions:")
292
+ print("Type:", type(decoded_preds))
293
+ print("Value:", decoded_preds)
294
+ print("==================== Exiting: predict_champion()===================\n")
295
+ return f"Predicted champion: {decoded_preds[0]}"
296
+ except Exception as e:
297
+ print(f"\nError during decoding: {e}")
298
+ # Fallback: try to directly index into classes
299
+ try:
300
+ champion = label_encoder.classes_[int(pred_indices[0])]
301
+ return f"Predicted champion: {champion}"
302
+ except Exception as e2:
303
+ print(f"Fallback error: {e2}")
304
+ return f"Error decoding prediction: {pred_indices[0]}"
305
 
306
  except Exception as e:
307
  import traceback