Spaces:
Sleeping
Sleeping
Jimin Park
commited on
Commit
·
e8a5ec7
1
Parent(s):
7625b8c
kermitting soon
Browse files- util/app.py +27 -6
util/app.py
CHANGED
@@ -67,7 +67,7 @@ def get_user_training_df(player_opgg_url):
|
|
67 |
#return f"Error getting training data: {e}"
|
68 |
|
69 |
def prepare_training_df(df, target_column='champion', stratify_columns=['champion', 'region'],
|
70 |
-
min_samples_per_class=6, train_size=0, val_size=
|
71 |
df = df.copy()
|
72 |
original_dtypes = df.dtypes.to_dict()
|
73 |
|
@@ -234,19 +234,40 @@ def predict_champion(player_opgg_url, *champions):
|
|
234 |
)
|
235 |
print("type(X_test): ", type(X_test), "\n")
|
236 |
|
237 |
-
#
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
print("type(X_test) after converting to DMatrix: ", type(X_test), "\n")
|
241 |
|
242 |
print("Starting model prediction... \n")
|
243 |
|
244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
|
246 |
-
|
|
|
|
|
247 |
|
248 |
# Decode predictions (if using LabelEncoder)
|
249 |
-
decoded_preds = label_encoder.inverse_transform(
|
250 |
print("decoded_preds: ", decoded_preds, "\n")
|
251 |
|
252 |
return f"Predicted champion: {decoded_preds}"
|
|
|
67 |
#return f"Error getting training data: {e}"
|
68 |
|
69 |
def prepare_training_df(df, target_column='champion', stratify_columns=['champion', 'region'],
|
70 |
+
min_samples_per_class=6, train_size=0.6, val_size=0.2, random_state=42):
|
71 |
df = df.copy()
|
72 |
original_dtypes = df.dtypes.to_dict()
|
73 |
|
|
|
234 |
)
|
235 |
print("type(X_test): ", type(X_test), "\n")
|
236 |
|
237 |
+
# Handle categorical features
|
238 |
+
categorical_columns = X_val.select_dtypes(include=['category']).columns
|
239 |
+
X_val_processed = X_val.copy()
|
240 |
+
|
241 |
+
# Convert categorical columns to numeric
|
242 |
+
for col in categorical_columns:
|
243 |
+
X_val_processed[col] = X_val_processed[col].cat.codes
|
244 |
+
|
245 |
+
# Convert to float32
|
246 |
+
X_val_processed = X_val_processed.astype('float32')
|
247 |
+
|
248 |
+
# Create DMatrix with categorical feature support from pandas dataframe.
|
249 |
+
dtest = DMatrix(X_val_processed, enable_categorical=True)
|
250 |
|
251 |
print("type(X_test) after converting to DMatrix: ", type(X_test), "\n")
|
252 |
|
253 |
print("Starting model prediction... \n")
|
254 |
|
255 |
+
predictions = model.predict(dtest)
|
256 |
+
print("Previous line: predictions = model.predict(dtest). \n prediction: ", predictions , "\n")
|
257 |
+
|
258 |
+
'''
|
259 |
+
# Get the highest probability prediction
|
260 |
+
if len(predictions.shape) > 1:
|
261 |
+
pred_indices = predictions.argmax(axis=1)
|
262 |
+
else:
|
263 |
+
pred_indices = predictions.astype(int)
|
264 |
|
265 |
+
# Decode predictions using loaded label encoder
|
266 |
+
decoded_preds = label_encoder.inverse_transform(pred_indices)
|
267 |
+
'''
|
268 |
|
269 |
# Decode predictions (if using LabelEncoder)
|
270 |
+
decoded_preds = label_encoder.inverse_transform(predictions)
|
271 |
print("decoded_preds: ", decoded_preds, "\n")
|
272 |
|
273 |
return f"Predicted champion: {decoded_preds}"
|