cassiomo commited on
Commit
a3faec3
β€’
1 Parent(s): 3520d74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +324 -324
app.py CHANGED
@@ -1003,333 +1003,333 @@ pipe_knock.fit(pipe_X,pipe_y)
1003
 
1004
  joblib.dump(pipe_knock,"./knockout_stage_prediction.pkl")
1005
 
1006
- st.title("FIFA winner predication")
1007
- st.write('This app predict 2022 FIFA winner')
1008
-
1009
- if st.button("Predict FIFA Winner"):
1010
-
1011
- last_team_scores = pd.read_csv('./data/last_team_scores.csv')
1012
- last_team_scores.tail()
1013
-
1014
- squad_stats = pd.read_csv('./data/squad_stats.csv')
1015
- squad_stats.tail()
1016
-
1017
- group_matches = pd.read_csv('./data/Qatar_group_stage.csv')
1018
- round_16 = group_matches.iloc[48:56, :]
1019
- quarter_finals = group_matches.iloc[56:60, :]
1020
- semi_finals = group_matches.iloc[60:62, :]
1021
- final = group_matches.iloc[62:63, :]
1022
- second_final = group_matches.iloc[63:64, :]
1023
- group_matches = group_matches.iloc[:48, :]
1024
- group_matches.tail()
1025
-
1026
- xgb_gs_model = joblib.load("./groups_stage_prediction.pkl")
1027
-
1028
- xgb_ks_model = joblib.load("./knockout_stage_prediction.pkl")
1029
-
1030
- team_group = group_matches.drop(['country2'], axis=1)
1031
- team_group = team_group.drop_duplicates().reset_index(drop=True)
1032
- team_group = team_group.rename(columns={"country1": "team"})
1033
- team_group.head(5)
1034
-
1035
- def matches(g_matches):
1036
- g_matches.insert(2, 'potential1',
1037
- g_matches['country1'].map(squad_stats.set_index('nationality_name')['potential']))
1038
- g_matches.insert(3, 'potential2',
1039
- g_matches['country2'].map(squad_stats.set_index('nationality_name')['potential']))
1040
- g_matches.insert(4, 'rank1', g_matches['country1'].map(last_team_scores.set_index('team')['rank']))
1041
- g_matches.insert(5, 'rank2', g_matches['country2'].map(last_team_scores.set_index('team')['rank']))
1042
- pred_set = []
1043
-
1044
- for index, row in g_matches.iterrows():
1045
- if row['potential1'] > row['potential2'] and abs(row['potential1'] - row['potential2']) > 2:
 
 
 
 
 
1046
  pred_set.append({'Team1': row['country1'], 'Team2': row['country2']})
1047
- elif row['potential2'] > row['potential1'] and abs(row['potential2'] - row['potential1']) > 2:
1048
- pred_set.append({'Team1': row['country2'], 'Team2': row['country1']})
1049
- else:
1050
- if row['rank1'] > row['rank2']:
1051
- pred_set.append({'Team1': row['country1'], 'Team2': row['country2']})
1052
- else:
1053
- pred_set.append({'Team1': row['country2'], 'Team2': row['country1']})
1054
-
1055
- pred_set = pd.DataFrame(pred_set)
1056
- pred_set.insert(2, 'Team1_FIFA_RANK', pred_set['Team1'].map(last_team_scores.set_index('team')['rank']))
1057
- pred_set.insert(3, 'Team2_FIFA_RANK', pred_set['Team2'].map(last_team_scores.set_index('team')['rank']))
1058
- pred_set.insert(4, 'Team1_Goalkeeper_Score',
1059
- pred_set['Team1'].map(last_team_scores.set_index('team')['goalkeeper_score']))
1060
- pred_set.insert(5, 'Team2_Goalkeeper_Score',
1061
- pred_set['Team2'].map(last_team_scores.set_index('team')['goalkeeper_score']))
1062
- pred_set.insert(6, 'Team1_Defense', pred_set['Team1'].map(last_team_scores.set_index('team')['defense_score']))
1063
- pred_set.insert(7, 'Team1_Offense', pred_set['Team1'].map(last_team_scores.set_index('team')['offense_score']))
1064
- pred_set.insert(8, 'Team1_Midfield',
1065
- pred_set['Team1'].map(last_team_scores.set_index('team')['midfield_score']))
1066
- pred_set.insert(9, 'Team2_Defense', pred_set['Team2'].map(last_team_scores.set_index('team')['defense_score']))
1067
- pred_set.insert(10, 'Team2_Offense', pred_set['Team2'].map(last_team_scores.set_index('team')['offense_score']))
1068
- pred_set.insert(11, 'Team2_Midfield',
1069
- pred_set['Team2'].map(last_team_scores.set_index('team')['midfield_score']))
1070
- return pred_set
1071
-
1072
- def print_results(dataset, y_pred, matches, proba):
1073
- results = []
1074
- for i in range(dataset.shape[0]):
1075
- print()
1076
- if y_pred[i] == 2:
1077
- print(matches.iloc[i, 0] + " vs. " + matches.iloc[i, 1] + " => Draw")
1078
- results.append({'result': 'Draw'})
1079
- elif y_pred[i] == 1:
1080
- print(matches.iloc[i, 0] + " vs. " + matches.iloc[i, 1] + " => Winner: " + dataset.iloc[i, 0])
1081
- results.append({'result': dataset.iloc[i, 0]})
1082
  else:
1083
- print(matches.iloc[i, 0] + " vs. " + matches.iloc[i, 1] + " => Winner: " + dataset.iloc[i, 1])
1084
- results.append({'result': dataset.iloc[i, 1]})
1085
- try:
1086
- print('Probability of ' + dataset.iloc[i, 0] + ' winning: ', '%.3f' % (proba[i][1]))
1087
- print('Probability of Draw: ', '%.3f' % (proba[i][2]))
1088
- print('Probability of ' + dataset.iloc[i, 1] + ' winning: ', '%.3f' % (proba[i][0]))
1089
- except:
1090
- print('Probability of ' + dataset.iloc[i, 1] + ' winning: ', '%.3f' % (proba[i][0]))
1091
- print("")
1092
- results = pd.DataFrame(results)
1093
- matches = pd.concat([matches.group, results], axis=1)
1094
- return matches
1095
-
1096
- def winner_to_match(round, prev_match):
1097
- round.insert(0, 'c1', round['country1'].map(prev_match.set_index('group')['result']))
1098
- round.insert(1, 'c2', round['country2'].map(prev_match.set_index('group')['result']))
1099
- round = round.drop(['country1', 'country2'], axis=1)
1100
- round = round.rename(columns={'c1': 'country1', 'c2': 'country2'}).reset_index(drop=True)
1101
- return round
1102
-
1103
- def prediction_knockout(round):
1104
- dataset_round = matches(round)
1105
- prediction_round = xgb_ks_model.predict(dataset_round)
1106
- proba_round = xgb_ks_model.predict_proba(dataset_round)
1107
-
1108
- # prediction_round = ada_ks_model.predict(dataset_round)
1109
- # proba_round = ada_ks_model.predict_proba(dataset_round)
1110
-
1111
- # prediction_round = rf_ks_model.predict(dataset_round)
1112
- # proba_round = rf_ks_model.predict_proba(dataset_round)
1113
-
1114
- results_round = print_results(dataset_round, prediction_round, round, proba_round)
1115
- return results_round
1116
-
1117
- def center_str(round):
1118
- spaces = ['', ' ', ' ', ' ', ' ', ' ', ]
1119
- for j in range(2):
1120
- for i in range(round.shape[0]):
1121
- if (13 - len(round.iloc[i, j])) % 2 == 0:
1122
- round.iloc[i, j] = spaces[int((13 - len(round.iloc[i, j])) / 2)] + round.iloc[i, j] + spaces[
1123
- int((13 - len(round.iloc[i, j])) / 2)]
1124
- else:
1125
- round.iloc[i, j] = spaces[int(((13 - len(round.iloc[i, j])) / 2) - 0.5)] + round.iloc[i, j] + \
1126
- spaces[int(((13 - len(round.iloc[i, j])) / 2) + 0.5)]
1127
- return round
1128
-
1129
- def center2(a):
1130
- spaces = ['', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
1131
- ' ', ' ', ' ', ' ', ' ',
1132
- ' ', ' ', ' ', ' ',
1133
- ' ']
1134
- if (29 - len(a)) % 2 == 0:
1135
- a = spaces[int((29 - len(a)) / 2)] + a + spaces[int((29 - len(a)) / 2)]
1136
  else:
1137
- a = spaces[int(((29 - len(a)) / 2) - 0.5)] + a + spaces[int(((29 - len(a)) / 2) + 0.5)]
1138
- return a
1139
-
1140
- dataset_groups = matches(group_matches)
1141
- dataset_groups.tail()
1142
- print(dataset_groups)
1143
-
1144
- prediction_groups = xgb_gs_model.predict(dataset_groups)
1145
- proba = xgb_gs_model.predict_proba(dataset_groups)
1146
-
1147
- # prediction_groups = ada_gs_model.predict(dataset_groups)
1148
- # proba = ada_gs_model.predict_proba(dataset_groups)
1149
-
1150
- # prediction_groups = rf_gs_model.predict(dataset_groups)
1151
- # proba = rf_gs_model.predict_proba(dataset_groups)
1152
-
1153
- results = print_results(dataset_groups, prediction_groups, group_matches, proba)
1154
-
1155
- team_group['points'] = 0
1156
- team_group
1157
- for i in range(results.shape[0]):
1158
- for j in range(team_group.shape[0]):
1159
- if results.iloc[i, 1] == team_group.iloc[j, 0]:
1160
- team_group.iloc[j, 2] += 3
1161
-
1162
- print(team_group.groupby(['group', 'team']).mean().astype(int))
1163
-
1164
- round_of_16 = team_group[team_group['points'] > 5].reset_index(drop=True)
1165
- round_of_16['group'] = (4 - 1 / 3 * round_of_16.points).astype(int).astype(str) + round_of_16.group
1166
- round_of_16 = round_of_16.rename(columns={"team": "result"})
1167
-
1168
- round_16 = winner_to_match(round_16, round_of_16)
1169
- results_round_16 = prediction_knockout(round_16)
1170
-
1171
- quarter_finals = winner_to_match(quarter_finals, results_round_16)
1172
- results_quarter_finals = prediction_knockout(quarter_finals)
1173
-
1174
- semi_finals = winner_to_match(semi_finals, results_quarter_finals)
1175
- results_finals = prediction_knockout(semi_finals)
1176
-
1177
- final = winner_to_match(final, results_finals)
1178
- winner = prediction_knockout(final)
1179
-
1180
- second = results_finals[~results_finals.result.isin(winner.result)]
1181
- results_finals_3 = results_quarter_finals[~results_quarter_finals.result.isin(results_finals.result)]
1182
- results_finals_3.iloc[0, 0] = 'z1'
1183
- results_finals_3.iloc[1, 0] = 'z2'
1184
- second_final = winner_to_match(second_final, results_finals_3)
1185
- third = prediction_knockout(second_final)
1186
-
1187
- round_16 = center_str(round_16)
1188
- quarter_finals = center_str(quarter_finals)
1189
- semi_finals = center_str(semi_finals)
1190
- final = center_str(final)
1191
- group_matches = center_str(group_matches)
1192
-
1193
- # Function to center align text
1194
- def center(text):
1195
- return f"<div style='text-align: center;'>{text}</div>"
1196
-
1197
- # Function to generate the formatted text
1198
- def generate_text(round_16, quarter_finals, semi_finals, final):
1199
- formatted_text = (
1200
- round_16.iloc[
1201
- 0, 0] + '━━━━┓ ┏━━━━' +
1202
- round_16.iloc[4, 0] + '\n' +
1203
- ' ┃ ┃\n' +
1204
- ' ┃━━━━' + quarter_finals.iloc[
1205
- 0, 0] + '━━━━┓ ┏━━━━' +
1206
- quarter_finals.iloc[2, 0] + '━━━━┃\n' +
1207
- ' ┃ ┃ ┃ ┃\n' +
1208
- round_16.iloc[
1209
- 0, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1210
- round_16.iloc[4, 1] + '\n' +
1211
- ' ┃━━━━' + semi_finals.iloc[
1212
- 0, 0] + '━━━━┓ ┏━━━━' + semi_finals.iloc[1, 0] + '━━━━┃\n' +
1213
- round_16.iloc[
1214
- 1, 0] + '━━━━┓ ┃ ┃ ┃ ┃ ┏━━━━' +
1215
- round_16.iloc[5, 0] + '\n' +
1216
- ' ┃ ┃ ┃ ┃ ┃ ┃\n' +
1217
- ' ┃━━━━' + quarter_finals.iloc[
1218
- 0, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1219
- quarter_finals.iloc[2, 1] + '━━━━┃\n' +
1220
- ' ┃ ┃ ┃ ┃\n' +
1221
- round_16.iloc[
1222
- 1, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1223
- round_16.iloc[5, 1] + '\n' +
1224
- ' ┃━━━━' + final.iloc[0, 0] + 'vs.' +
1225
- final.iloc[0, 1] + '━━━━┃\n' +
1226
- round_16.iloc[
1227
- 2, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1228
- round_16.iloc[6, 0] + '\n' +
1229
- ' ┃ ┃ ┃ ┃\n' +
1230
- ' ┃━━━━' + quarter_finals.iloc[
1231
- 1, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1232
- quarter_finals.iloc[3, 0] + '━━━━┃\n' +
1233
- ' ┃ ┃ ┃ ┃ ┃ ┃\n' +
1234
- round_16.iloc[
1235
- 2, 1] + '━━━━┛ ┃ ┃ ┃ ┃ ┗━━━━' +
1236
- round_16.iloc[6, 1] + '\n' +
1237
- ' ┃━━━━' + semi_finals.iloc[
1238
- 0, 1] + '━━━━┛ ┗━━━━' + semi_finals.iloc[1, 1] + '━━━━┃\n' +
1239
- round_16.iloc[
1240
- 3, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1241
- round_16.iloc[7, 0] + '\n' +
1242
- ' ┃ ┃ ┃ ┃\n' +
1243
- ' ┃━━━━' + quarter_finals.iloc[
1244
- 1, 1] + '━━━━┛ ┗━━━━' +
1245
- quarter_finals.iloc[3, 1] + '━━━━┃\n' +
1246
- ' ┃ ┃\n' +
1247
- round_16.iloc[
1248
- 3, 1] + '━━━━┛ ┗━━━━' +
1249
- round_16.iloc[7, 1] + '\n' +
1250
- " " + center(
1251
- "\U0001F947" + winner.iloc[0, 1]) + '\n' +
1252
- " " + center(
1253
- "\U0001F948" + second.iloc[0, 1]) + '\n' +
1254
- " " + center(
1255
- "\U0001F949" + third.iloc[0, 1])
1256
- )
1257
- return formatted_text
1258
-
1259
- # Generate the formatted text
1260
- formatted_text = generate_text(round_16, quarter_finals, semi_finals, final)
1261
-
1262
- # Define the round_16, quarter_finals, semi_finals, final DataFrames
1263
- # Replace the DataFrame creation with your actual data
1264
-
1265
- # Display the formatted text
1266
- st.text(formatted_text)
1267
- # st.markdown(formatted_text)
1268
-
1269
- print(round_16.iloc[
1270
- 0, 0] + '━━━━┓ ┏━━━━' +
1271
- round_16.iloc[4, 0])
1272
- print(
1273
- ' ┃ ┃')
1274
- print(' ┃━━━━' + quarter_finals.iloc[
1275
- 0, 0] + '━━━━┓ ┏━━━━' +
1276
- quarter_finals.iloc[2, 0] + '━━━━┃')
1277
- print(
1278
- ' ┃ ┃ ┃ ┃')
1279
- print(round_16.iloc[
1280
- 0, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1281
- round_16.iloc[4, 1])
1282
- print(' ┃━━━━' + semi_finals.iloc[
1283
- 0, 0] + '━━━━┓ ┏━━━━' + semi_finals.iloc[1, 0] + '━━━━┃')
1284
- print(round_16.iloc[
1285
- 1, 0] + '━━━━┓ ┃ ┃ ┃ ┃ ┏━━━━' +
1286
- round_16.iloc[5, 0])
1287
- print(
1288
- ' ┃ ┃ ┃ ┃ ┃ ┃')
1289
- print(' ┃━━━━' + quarter_finals.iloc[
1290
- 0, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1291
- quarter_finals.iloc[2, 1] + '━━━━┃')
1292
- print(
1293
- ' ┃ ┃ ┃ ┃')
1294
- print(round_16.iloc[
1295
- 1, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1296
- round_16.iloc[5, 1])
1297
- print(' ┃━━━━' + final.iloc[0, 0] + 'vs.' + final.iloc[
1298
- 0, 1] + '━━━━┃')
1299
- print(round_16.iloc[
1300
- 2, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1301
- round_16.iloc[6, 0])
1302
- print(
1303
- ' ┃ ┃ ┃ ┃')
1304
- print(' ┃━━━━' + quarter_finals.iloc[
1305
- 1, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1306
- quarter_finals.iloc[3, 0] + '━━━━┃')
1307
- print(
1308
- ' ┃ ┃ ┃ ┃ ┃ ┃')
1309
- print(round_16.iloc[
1310
- 2, 1] + '━━━━┛ ┃ ┃ ┃ ┃ ┗━━━━' +
1311
- round_16.iloc[6, 1])
1312
- print(' ┃━━━━' + semi_finals.iloc[
1313
- 0, 1] + '━━━━┛ ┗━━━━' + semi_finals.iloc[1, 1] + '━━━━┃')
1314
- print(round_16.iloc[
1315
- 3, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1316
- round_16.iloc[7, 0])
1317
- print(
1318
- ' ┃ ┃ ┃ ┃')
1319
- print(' ┃━━━━' + quarter_finals.iloc[
1320
- 1, 1] + '━━━━┛ ┗━━━━' +
1321
- quarter_finals.iloc[3, 1] + '━━━━┃')
1322
- print(
1323
- ' ┃ ┃')
1324
- print(round_16.iloc[
1325
- 3, 1] + '━━━━┛ ┗━━━━' +
1326
- round_16.iloc[7, 1])
1327
- print(
1328
- " " + center2("\U0001F947" + winner.iloc[0, 1]))
1329
- print(
1330
- " " + center2("\U0001F948" + second.iloc[0, 1]))
1331
- print(
1332
- " " + center2("\U0001F949" + third.iloc[0, 1]))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1333
 
1334
 
1335
 
 
1003
 
1004
  joblib.dump(pipe_knock,"./knockout_stage_prediction.pkl")
1005
 
1006
+ st.title("FIFA winner predication")
1007
+ st.write('This app predict 2022 FIFA winner')
1008
+
1009
+ if st.button("Predict FIFA Winner"):
1010
+
1011
+ last_team_scores = pd.read_csv('./data/last_team_scores.csv')
1012
+ last_team_scores.tail()
1013
+
1014
+ squad_stats = pd.read_csv('./data/squad_stats.csv')
1015
+ squad_stats.tail()
1016
+
1017
+ group_matches = pd.read_csv('./data/Qatar_group_stage.csv')
1018
+ round_16 = group_matches.iloc[48:56, :]
1019
+ quarter_finals = group_matches.iloc[56:60, :]
1020
+ semi_finals = group_matches.iloc[60:62, :]
1021
+ final = group_matches.iloc[62:63, :]
1022
+ second_final = group_matches.iloc[63:64, :]
1023
+ group_matches = group_matches.iloc[:48, :]
1024
+ group_matches.tail()
1025
+
1026
+ xgb_gs_model = joblib.load("./groups_stage_prediction.pkl")
1027
+
1028
+ xgb_ks_model = joblib.load("./knockout_stage_prediction.pkl")
1029
+
1030
+ team_group = group_matches.drop(['country2'], axis=1)
1031
+ team_group = team_group.drop_duplicates().reset_index(drop=True)
1032
+ team_group = team_group.rename(columns={"country1": "team"})
1033
+ team_group.head(5)
1034
+
1035
+ def matches(g_matches):
1036
+ g_matches.insert(2, 'potential1',
1037
+ g_matches['country1'].map(squad_stats.set_index('nationality_name')['potential']))
1038
+ g_matches.insert(3, 'potential2',
1039
+ g_matches['country2'].map(squad_stats.set_index('nationality_name')['potential']))
1040
+ g_matches.insert(4, 'rank1', g_matches['country1'].map(last_team_scores.set_index('team')['rank']))
1041
+ g_matches.insert(5, 'rank2', g_matches['country2'].map(last_team_scores.set_index('team')['rank']))
1042
+ pred_set = []
1043
+
1044
+ for index, row in g_matches.iterrows():
1045
+ if row['potential1'] > row['potential2'] and abs(row['potential1'] - row['potential2']) > 2:
1046
+ pred_set.append({'Team1': row['country1'], 'Team2': row['country2']})
1047
+ elif row['potential2'] > row['potential1'] and abs(row['potential2'] - row['potential1']) > 2:
1048
+ pred_set.append({'Team1': row['country2'], 'Team2': row['country1']})
1049
+ else:
1050
+ if row['rank1'] > row['rank2']:
1051
  pred_set.append({'Team1': row['country1'], 'Team2': row['country2']})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1052
  else:
1053
+ pred_set.append({'Team1': row['country2'], 'Team2': row['country1']})
1054
+
1055
+ pred_set = pd.DataFrame(pred_set)
1056
+ pred_set.insert(2, 'Team1_FIFA_RANK', pred_set['Team1'].map(last_team_scores.set_index('team')['rank']))
1057
+ pred_set.insert(3, 'Team2_FIFA_RANK', pred_set['Team2'].map(last_team_scores.set_index('team')['rank']))
1058
+ pred_set.insert(4, 'Team1_Goalkeeper_Score',
1059
+ pred_set['Team1'].map(last_team_scores.set_index('team')['goalkeeper_score']))
1060
+ pred_set.insert(5, 'Team2_Goalkeeper_Score',
1061
+ pred_set['Team2'].map(last_team_scores.set_index('team')['goalkeeper_score']))
1062
+ pred_set.insert(6, 'Team1_Defense', pred_set['Team1'].map(last_team_scores.set_index('team')['defense_score']))
1063
+ pred_set.insert(7, 'Team1_Offense', pred_set['Team1'].map(last_team_scores.set_index('team')['offense_score']))
1064
+ pred_set.insert(8, 'Team1_Midfield',
1065
+ pred_set['Team1'].map(last_team_scores.set_index('team')['midfield_score']))
1066
+ pred_set.insert(9, 'Team2_Defense', pred_set['Team2'].map(last_team_scores.set_index('team')['defense_score']))
1067
+ pred_set.insert(10, 'Team2_Offense', pred_set['Team2'].map(last_team_scores.set_index('team')['offense_score']))
1068
+ pred_set.insert(11, 'Team2_Midfield',
1069
+ pred_set['Team2'].map(last_team_scores.set_index('team')['midfield_score']))
1070
+ return pred_set
1071
+
1072
+ def print_results(dataset, y_pred, matches, proba):
1073
+ results = []
1074
+ for i in range(dataset.shape[0]):
1075
+ print()
1076
+ if y_pred[i] == 2:
1077
+ print(matches.iloc[i, 0] + " vs. " + matches.iloc[i, 1] + " => Draw")
1078
+ results.append({'result': 'Draw'})
1079
+ elif y_pred[i] == 1:
1080
+ print(matches.iloc[i, 0] + " vs. " + matches.iloc[i, 1] + " => Winner: " + dataset.iloc[i, 0])
1081
+ results.append({'result': dataset.iloc[i, 0]})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1082
  else:
1083
+ print(matches.iloc[i, 0] + " vs. " + matches.iloc[i, 1] + " => Winner: " + dataset.iloc[i, 1])
1084
+ results.append({'result': dataset.iloc[i, 1]})
1085
+ try:
1086
+ print('Probability of ' + dataset.iloc[i, 0] + ' winning: ', '%.3f' % (proba[i][1]))
1087
+ print('Probability of Draw: ', '%.3f' % (proba[i][2]))
1088
+ print('Probability of ' + dataset.iloc[i, 1] + ' winning: ', '%.3f' % (proba[i][0]))
1089
+ except:
1090
+ print('Probability of ' + dataset.iloc[i, 1] + ' winning: ', '%.3f' % (proba[i][0]))
1091
+ print("")
1092
+ results = pd.DataFrame(results)
1093
+ matches = pd.concat([matches.group, results], axis=1)
1094
+ return matches
1095
+
1096
+ def winner_to_match(round, prev_match):
1097
+ round.insert(0, 'c1', round['country1'].map(prev_match.set_index('group')['result']))
1098
+ round.insert(1, 'c2', round['country2'].map(prev_match.set_index('group')['result']))
1099
+ round = round.drop(['country1', 'country2'], axis=1)
1100
+ round = round.rename(columns={'c1': 'country1', 'c2': 'country2'}).reset_index(drop=True)
1101
+ return round
1102
+
1103
+ def prediction_knockout(round):
1104
+ dataset_round = matches(round)
1105
+ prediction_round = xgb_ks_model.predict(dataset_round)
1106
+ proba_round = xgb_ks_model.predict_proba(dataset_round)
1107
+
1108
+ # prediction_round = ada_ks_model.predict(dataset_round)
1109
+ # proba_round = ada_ks_model.predict_proba(dataset_round)
1110
+
1111
+ # prediction_round = rf_ks_model.predict(dataset_round)
1112
+ # proba_round = rf_ks_model.predict_proba(dataset_round)
1113
+
1114
+ results_round = print_results(dataset_round, prediction_round, round, proba_round)
1115
+ return results_round
1116
+
1117
+ def center_str(round):
1118
+ spaces = ['', ' ', ' ', ' ', ' ', ' ', ]
1119
+ for j in range(2):
1120
+ for i in range(round.shape[0]):
1121
+ if (13 - len(round.iloc[i, j])) % 2 == 0:
1122
+ round.iloc[i, j] = spaces[int((13 - len(round.iloc[i, j])) / 2)] + round.iloc[i, j] + spaces[
1123
+ int((13 - len(round.iloc[i, j])) / 2)]
1124
+ else:
1125
+ round.iloc[i, j] = spaces[int(((13 - len(round.iloc[i, j])) / 2) - 0.5)] + round.iloc[i, j] + \
1126
+ spaces[int(((13 - len(round.iloc[i, j])) / 2) + 0.5)]
1127
+ return round
1128
+
1129
+ def center2(a):
1130
+ spaces = ['', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
1131
+ ' ', ' ', ' ', ' ', ' ',
1132
+ ' ', ' ', ' ', ' ',
1133
+ ' ']
1134
+ if (29 - len(a)) % 2 == 0:
1135
+ a = spaces[int((29 - len(a)) / 2)] + a + spaces[int((29 - len(a)) / 2)]
1136
+ else:
1137
+ a = spaces[int(((29 - len(a)) / 2) - 0.5)] + a + spaces[int(((29 - len(a)) / 2) + 0.5)]
1138
+ return a
1139
+
1140
+ dataset_groups = matches(group_matches)
1141
+ dataset_groups.tail()
1142
+ print(dataset_groups)
1143
+
1144
+ prediction_groups = xgb_gs_model.predict(dataset_groups)
1145
+ proba = xgb_gs_model.predict_proba(dataset_groups)
1146
+
1147
+ # prediction_groups = ada_gs_model.predict(dataset_groups)
1148
+ # proba = ada_gs_model.predict_proba(dataset_groups)
1149
+
1150
+ # prediction_groups = rf_gs_model.predict(dataset_groups)
1151
+ # proba = rf_gs_model.predict_proba(dataset_groups)
1152
+
1153
+ results = print_results(dataset_groups, prediction_groups, group_matches, proba)
1154
+
1155
+ team_group['points'] = 0
1156
+ team_group
1157
+ for i in range(results.shape[0]):
1158
+ for j in range(team_group.shape[0]):
1159
+ if results.iloc[i, 1] == team_group.iloc[j, 0]:
1160
+ team_group.iloc[j, 2] += 3
1161
+
1162
+ print(team_group.groupby(['group', 'team']).mean().astype(int))
1163
+
1164
+ round_of_16 = team_group[team_group['points'] > 5].reset_index(drop=True)
1165
+ round_of_16['group'] = (4 - 1 / 3 * round_of_16.points).astype(int).astype(str) + round_of_16.group
1166
+ round_of_16 = round_of_16.rename(columns={"team": "result"})
1167
+
1168
+ round_16 = winner_to_match(round_16, round_of_16)
1169
+ results_round_16 = prediction_knockout(round_16)
1170
+
1171
+ quarter_finals = winner_to_match(quarter_finals, results_round_16)
1172
+ results_quarter_finals = prediction_knockout(quarter_finals)
1173
+
1174
+ semi_finals = winner_to_match(semi_finals, results_quarter_finals)
1175
+ results_finals = prediction_knockout(semi_finals)
1176
+
1177
+ final = winner_to_match(final, results_finals)
1178
+ winner = prediction_knockout(final)
1179
+
1180
+ second = results_finals[~results_finals.result.isin(winner.result)]
1181
+ results_finals_3 = results_quarter_finals[~results_quarter_finals.result.isin(results_finals.result)]
1182
+ results_finals_3.iloc[0, 0] = 'z1'
1183
+ results_finals_3.iloc[1, 0] = 'z2'
1184
+ second_final = winner_to_match(second_final, results_finals_3)
1185
+ third = prediction_knockout(second_final)
1186
+
1187
+ round_16 = center_str(round_16)
1188
+ quarter_finals = center_str(quarter_finals)
1189
+ semi_finals = center_str(semi_finals)
1190
+ final = center_str(final)
1191
+ group_matches = center_str(group_matches)
1192
+
1193
+ # Function to center align text
1194
+ def center(text):
1195
+ return f"<div style='text-align: center;'>{text}</div>"
1196
+
1197
+ # Function to generate the formatted text
1198
+ def generate_text(round_16, quarter_finals, semi_finals, final):
1199
+ formatted_text = (
1200
+ round_16.iloc[
1201
+ 0, 0] + '━━━━┓ ┏━━━━' +
1202
+ round_16.iloc[4, 0] + '\n' +
1203
+ ' ┃ ┃\n' +
1204
+ ' ┃━━━━' + quarter_finals.iloc[
1205
+ 0, 0] + '━━━━┓ ┏━━━━' +
1206
+ quarter_finals.iloc[2, 0] + '━━━━┃\n' +
1207
+ ' ┃ ┃ ┃ ┃\n' +
1208
+ round_16.iloc[
1209
+ 0, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1210
+ round_16.iloc[4, 1] + '\n' +
1211
+ ' ┃━━━━' + semi_finals.iloc[
1212
+ 0, 0] + '━━━━┓ ┏━━━━' + semi_finals.iloc[1, 0] + '━━━━┃\n' +
1213
+ round_16.iloc[
1214
+ 1, 0] + '━━━━┓ ┃ ┃ ┃ ┃ ┏━━━━' +
1215
+ round_16.iloc[5, 0] + '\n' +
1216
+ ' ┃ ┃ ┃ ┃ ┃ ┃\n' +
1217
+ ' ┃━━━━' + quarter_finals.iloc[
1218
+ 0, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1219
+ quarter_finals.iloc[2, 1] + '━━━━┃\n' +
1220
+ ' ┃ ┃ ┃ ┃\n' +
1221
+ round_16.iloc[
1222
+ 1, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1223
+ round_16.iloc[5, 1] + '\n' +
1224
+ ' ┃━━━━' + final.iloc[0, 0] + 'vs.' +
1225
+ final.iloc[0, 1] + '━━━━┃\n' +
1226
+ round_16.iloc[
1227
+ 2, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1228
+ round_16.iloc[6, 0] + '\n' +
1229
+ ' ┃ ┃ ┃ ┃\n' +
1230
+ ' ┃━━━━' + quarter_finals.iloc[
1231
+ 1, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1232
+ quarter_finals.iloc[3, 0] + '━━━━┃\n' +
1233
+ ' ┃ ┃ ┃ ┃ ┃ ┃\n' +
1234
+ round_16.iloc[
1235
+ 2, 1] + '━━━━┛ ┃ ┃ ┃ ┃ ┗━━━━' +
1236
+ round_16.iloc[6, 1] + '\n' +
1237
+ ' ┃━━━━' + semi_finals.iloc[
1238
+ 0, 1] + '━━━━┛ ┗━━━━' + semi_finals.iloc[1, 1] + '━━━━┃\n' +
1239
+ round_16.iloc[
1240
+ 3, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1241
+ round_16.iloc[7, 0] + '\n' +
1242
+ ' ┃ ┃ ┃ ┃\n' +
1243
+ ' ┃━━━━' + quarter_finals.iloc[
1244
+ 1, 1] + '━━━━┛ ┗━━━━' +
1245
+ quarter_finals.iloc[3, 1] + '━━━━┃\n' +
1246
+ ' ┃ ┃\n' +
1247
+ round_16.iloc[
1248
+ 3, 1] + '━━━━┛ ┗━━━━' +
1249
+ round_16.iloc[7, 1] + '\n' +
1250
+ " " + center(
1251
+ "\U0001F947" + winner.iloc[0, 1]) + '\n' +
1252
+ " " + center(
1253
+ "\U0001F948" + second.iloc[0, 1]) + '\n' +
1254
+ " " + center(
1255
+ "\U0001F949" + third.iloc[0, 1])
1256
+ )
1257
+ return formatted_text
1258
+
1259
+ # Generate the formatted text
1260
+ formatted_text = generate_text(round_16, quarter_finals, semi_finals, final)
1261
+
1262
+ # Define the round_16, quarter_finals, semi_finals, final DataFrames
1263
+ # Replace the DataFrame creation with your actual data
1264
+
1265
+ # Display the formatted text
1266
+ st.text(formatted_text)
1267
+ # st.markdown(formatted_text)
1268
+
1269
+ print(round_16.iloc[
1270
+ 0, 0] + '━━━━┓ ┏━━━━' +
1271
+ round_16.iloc[4, 0])
1272
+ print(
1273
+ ' ┃ ┃')
1274
+ print(' ┃━━━━' + quarter_finals.iloc[
1275
+ 0, 0] + '━━━━┓ ┏━━━━' +
1276
+ quarter_finals.iloc[2, 0] + '━━━━┃')
1277
+ print(
1278
+ ' ┃ ┃ ┃ ┃')
1279
+ print(round_16.iloc[
1280
+ 0, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1281
+ round_16.iloc[4, 1])
1282
+ print(' ┃━━━━' + semi_finals.iloc[
1283
+ 0, 0] + '━━━━┓ ┏━━━━' + semi_finals.iloc[1, 0] + '━━━━┃')
1284
+ print(round_16.iloc[
1285
+ 1, 0] + '━━━━┓ ┃ ┃ ┃ ┃ ┏━━━━' +
1286
+ round_16.iloc[5, 0])
1287
+ print(
1288
+ ' ┃ ┃ ┃ ┃ ┃ ┃')
1289
+ print(' ┃━━━━' + quarter_finals.iloc[
1290
+ 0, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1291
+ quarter_finals.iloc[2, 1] + '━━━━┃')
1292
+ print(
1293
+ ' ┃ ┃ ┃ ┃')
1294
+ print(round_16.iloc[
1295
+ 1, 1] + '━━━━┛ ┃ ┃ ┗━━━━' +
1296
+ round_16.iloc[5, 1])
1297
+ print(' ┃━━━━' + final.iloc[0, 0] + 'vs.' + final.iloc[
1298
+ 0, 1] + '━━━━┃')
1299
+ print(round_16.iloc[
1300
+ 2, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1301
+ round_16.iloc[6, 0])
1302
+ print(
1303
+ ' ┃ ┃ ┃ ┃')
1304
+ print(' ┃━━━━' + quarter_finals.iloc[
1305
+ 1, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1306
+ quarter_finals.iloc[3, 0] + '━━━━┃')
1307
+ print(
1308
+ ' ┃ ┃ ┃ ┃ ┃ ┃')
1309
+ print(round_16.iloc[
1310
+ 2, 1] + '━━━━┛ ┃ ┃ ┃ ┃ ┗━━━━' +
1311
+ round_16.iloc[6, 1])
1312
+ print(' ┃━━━━' + semi_finals.iloc[
1313
+ 0, 1] + '━━━━┛ ┗━━━━' + semi_finals.iloc[1, 1] + '━━━━┃')
1314
+ print(round_16.iloc[
1315
+ 3, 0] + '━━━━┓ ┃ ┃ ┏━━━━' +
1316
+ round_16.iloc[7, 0])
1317
+ print(
1318
+ ' ┃ ┃ ┃ ┃')
1319
+ print(' ┃━━━━' + quarter_finals.iloc[
1320
+ 1, 1] + '━━━━┛ ┗━━━━' +
1321
+ quarter_finals.iloc[3, 1] + '━━━━┃')
1322
+ print(
1323
+ ' ┃ ┃')
1324
+ print(round_16.iloc[
1325
+ 3, 1] + '━━━━┛ ┗━━━━' +
1326
+ round_16.iloc[7, 1])
1327
+ print(
1328
+ " " + center2("\U0001F947" + winner.iloc[0, 1]))
1329
+ print(
1330
+ " " + center2("\U0001F948" + second.iloc[0, 1]))
1331
+ print(
1332
+ " " + center2("\U0001F949" + third.iloc[0, 1]))
1333
 
1334
 
1335