Update files

This commit is contained in:
unknown 2023-01-31 10:54:42 +01:00
parent 29847d3799
commit b444f98b5d
4 changed files with 86 additions and 326 deletions

View File

@ -4,7 +4,7 @@ from numpy import inf, nan, nan_to_num
names_to_shortcuts = {
"Evil Geniuses" : "EG",
"Evil Geniuses": "EG",
"TSM": "TSM",
"Cloud9": "C9",
"Immortals Progressive": "IMT",
@ -47,6 +47,7 @@ def get_win_team_name(row):
def get_win_ratio(df, team_name, number_of_games):
df = df[(df["blueTeam_name"] == team_name) | (df["redTeam_name"] == team_name)]
df = df.head(number_of_games)
return len(df[df["winTeam_name"] == team_name]) / len(df)
@ -61,6 +62,7 @@ def get_last_5_games_win_ratio(df, team_name, number_of_games):
def get_games_ids(df, team_name, number_of_games):
df = df[(df["blueTeam_name"] == team_name) | (df["redTeam_name"] == team_name)]
df = df.head(number_of_games)
return df["id"]
@ -76,7 +78,6 @@ def get_kdas(df_player_stats, games_ids, team_name):
players_kdas = players_kdas.values
players_kdas[players_kdas == inf] = 10
players_kdas = nan_to_num(players_kdas, nan=1)
players_kdas = players_kdas.mean()
kda.append(players_kdas)
@ -84,7 +85,7 @@ def get_kdas(df_player_stats, games_ids, team_name):
return sum(kda) / len(kda)
def get_prediction(team_A, team_B, number_of_games_A, number_of_games_B, league, fuzzy_system):
def get_prediction(team_A, team_B, number_of_games_A, number_of_games_B, league, fuzzy_system, team_a_win, verbose):
df_lol = pd.read_csv(f"matchHistory.csv")
df_lol = df_lol[df_lol["tournament"] == league]
@ -111,9 +112,12 @@ def get_prediction(team_A, team_B, number_of_games_A, number_of_games_B, league,
adv_standings = (team_A_standings - team_B_standings) / 2 + 50
adv_form = (team_A_form - team_B_form) / 2 + 50
adv_performance = (1 - (1 / (1 + kda_proportion))) * 100
print("\n########## PREDICTION ##########")
print(f"Advantage standings: {adv_standings}")
print(f"Advantage form: {adv_form}")
print(f"Advantage performance: {adv_performance}")
return make_inference(fuzzy_system, adv_standings, adv_form, 50)
if verbose is True:
print("\n########## PREDICTION ##########")
print(f"Advantage standings: {adv_standings}")
print(f"Advantage form: {adv_form}")
print(f"Advantage performance: {adv_performance}")
res = make_inference(fuzzy_system, adv_standings, adv_form, adv_performance)["RESULT"]
return res

View File

@ -49,24 +49,18 @@ def create_fuzzy_system():
universe_of_discourse=[0, 100]))
RULE1 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS positive) THEN (RESULT IS team_a_surely_wins)"
RULE2 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS negative) THEN (RESULT IS team_b_surely_wins)"
RULE3 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS positive) THEN (RESULT IS team_a_most_likely_wins)"
RULE4 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS negative) THEN (RESULT IS team_b_most_likely_wins)"
RULE5 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS positive) THEN (RESULT IS team_a_most_likely_wins)"
RULE6 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS negative) THEN (RESULT IS team_b_most_likely_wins)"
RULE7 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS neutral) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_a_most_likely_wins)"
RULE8 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS neutral) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_b_most_likely_wins)"
RULE9 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS neutral) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS draw)"
RULE1 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS positive) THEN (RESULT IS team_a_surely_wins)"
RULE2 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS negative) THEN (RESULT IS team_b_surely_wins)"
RULE3 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS negative) THEN (RESULT IS team_a_most_likely_wins)"
RULE4 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS positive) THEN (RESULT IS team_b_most_likely_wins)"
RULE5 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS positive) THEN (RESULT IS team_a_most_likely_wins)"
RULE6 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS negative) THEN (RESULT IS team_b_most_likely_wins)"
RULE7 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS neutral) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS draw)"
RULE8 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_a_surely_wins)"
RULE9 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_b_surely_wins)"
RULE10 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS positive) THEN (RESULT IS team_a_most_likely_wins)"
RULE11 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS negative) THEN (RESULT IS team_b_most_likely_wins)"
RULE12 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS neutral) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_a_most_likely_wins)"
RULE13 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS neutral) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_b_most_likely_wins)"
RULE14 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_a_most_likely_wins)"
RULE15 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_b_most_likely_wins)"
FS.add_rules([RULE1, RULE2, RULE3, RULE4, RULE5, RULE6, RULE7, RULE8, RULE9, RULE10, RULE11, RULE12, RULE13, RULE14, RULE15])
rules = [RULE1, RULE2, RULE3, RULE4, RULE5, RULE6, RULE7, RULE8, RULE9]
FS.add_rules(rules)
return FS
@ -75,4 +69,4 @@ def make_inference(FS, standings, form, performance):
FS.set_variable("ADVANTAGE_FORM", form)
FS.set_variable("ADVANTAGE_PERFORMANCE", performance)
return FS.inference(["RESULT"])
return FS.inference(["RESULT"], ignore_warnings=True)

44
get_test_data.py Normal file
View File

@ -0,0 +1,44 @@
def get_test_data():
team_a_win = [1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0,
1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0,
1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1]
teams_a = ["TSM", "Team Liquid Honda", "CLG", "Cloud9", "FlyQuest", "Golden Guardians", "100 Thieves", "FlyQuest",
"CLG", "Golden Guardians", "Immortals Progressive", "FlyQuest", "100 Thieves", "Dignitas",
"Golden Guardians", "Immortals Progressive", "Dignitas", "Team Liquid Honda", "CLG", "100 Thieves",
"SK Gaming", "MAD Lions", "Team Vitality", "Rogue", "G2 Esports", "Team Vitality", "Schalke 04 Esports",
"Misfits Gaming", "Fnatic", "Rogue", "Misfits Gaming", "Schalke 04 Esports", "SK Gaming", "Fnatic",
"Team Vitality",
"Team ESCA Gaming", "Zero Tenacity", "Komil&Friends", "Topo Centras Iron Wolves", "AGO Rogue",
"Team ESCA Gaming", "Devils.One", "Gentlemen's Gaming", "Zero Tenacity", "Goskilla",
"Maturalni Forsaken",
"Topo Centras Iron Wolves", "Team ESCA Gaming", "Gentlemen's Gaming", "Zero Tenacity"]
teams_b = ["100 Thieves", "Evil Geniuses", "Dignitas", "Evil Geniuses", "TSM", "Immortals Progressive",
"Team Liquid Honda", "Cloud9", "Immortals Progressive", "Dignitas", "Evil Geniuses", "Team Liquid Honda",
"CLG", "TSM", "FlyQuest", "Cloud9", "Evil Geniuses", "Cloud9", "TSM", "Golden Guardians",
"Schalke 04 Esports", "EXCEL", "Fnatic", "Misfits Gaming", "Astralis", "SK Gaming", "MAD Lions",
"Astralis",
"EXCEL", "G2 Esports", "EXCEL", "Rogue", "MAD Lions", "Astralis", "G2 Esports",
"Gentlemen's Gaming", "Devils.One", "Maturalni Forsaken", "Goskilla", "Illuminar Gaming",
"Komil&Friends",
"Maturalni Forsaken", "Illuminar Gaming", "Topo Centras Iron Wolves", "AGO Rogue", "AGO Rogue",
"Komil&Friends", "Illuminar Gaming", "Devils.One", "Goskilla"]
team_a_games = [10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13,
9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11,
8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10]
team_b_games = [10, 10, 10, 11, 11, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 12, 13, 13, 13, 13,
9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11,
8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10]
res_dict = {
"team_a_win": team_a_win,
"teams_a": teams_a,
"teams_b": teams_b,
"team_a_games": team_a_games,
"team_b_games": team_b_games
}
return res_dict

318
main.py
View File

@ -1,306 +1,24 @@
from DataOperations import *
from get_test_data import get_test_data
import numpy as np
# Code prints results for 50 matches from 3 different leagues
test_data = get_test_data()
team_a_win = test_data["team_a_win"]
teams_a = test_data["teams_a"]
teams_b = test_data["teams_b"]
team_a_games = test_data["team_a_games"]
team_b_games = test_data["team_b_games"]
FS = create_fuzzy_system()
print(get_prediction(team_A="TSM",
team_B="100 Thieves",
number_of_games_A=10,
number_of_games_B=10,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="Team Liquid Honda",
team_B="Evil Geniuses",
number_of_games_A=10,
number_of_games_B=10,
league="lcs_summer_2020",
fuzzy_system=FS))
for x in range(50):
if x < 20:
res = get_prediction(teams_a[x], teams_b[x], team_a_games[x], team_b_games[x], "lcs_summer_2020", FS, team_a_win[x], verbose=True)
elif x < 35:
res = get_prediction(teams_a[x], teams_b[x], team_a_games[x], team_b_games[x], "lec_summer_2021", FS, team_a_win[x], verbose=True)
else:
res = get_prediction(teams_a[x], teams_b[x], team_a_games[x], team_b_games[x], "ultraliga_summer_2022", FS, team_a_win[x], verbose=True)
print(get_prediction(team_A="CLG",
team_B="Dignitas",
number_of_games_A=10,
number_of_games_B=10,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="Cloud9",
team_B="Evil Geniuses",
number_of_games_A=10,
number_of_games_B=11,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="FlyQuest",
team_B="TSM",
number_of_games_A=10,
number_of_games_B=11,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="Golden Guardians",
team_B="Immortals Progressive",
number_of_games_A=10,
number_of_games_B=10,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="100 Thieves",
team_B="Team Liquid Honda",
number_of_games_A=11,
number_of_games_B=11,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="FlyQuest",
team_B="Cloud9",
number_of_games_A=11,
number_of_games_B=11,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="CLG",
team_B="Immortals Progressive",
number_of_games_A=11,
number_of_games_B=11,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="Golden Guardians",
team_B="Dignitas",
number_of_games_A=11,
number_of_games_B=11,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="Immortals Progressive",
team_B="Evil Geniuses",
number_of_games_A=12,
number_of_games_B=12,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="FlyQuest",
team_B="Team Liquid Honda",
number_of_games_A=12,
number_of_games_B=12,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="100 Thieves",
team_B="CLG",
number_of_games_A=12,
number_of_games_B=12,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="Dignitas",
team_B="TSM",
number_of_games_A=12,
number_of_games_B=12,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="Golden Guardians",
team_B="FlyQuest",
number_of_games_A=12,
number_of_games_B=13,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="Immortals Progressive",
team_B="Cloud9",
number_of_games_A=13,
number_of_games_B=12,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="Dignitas",
team_B="Evil Geniuses",
number_of_games_A=13,
number_of_games_B=13,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="Team Liquid Honda",
team_B="Cloud9",
number_of_games_A=13,
number_of_games_B=13,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="CLG",
team_B="TSM",
number_of_games_A=13,
number_of_games_B=13,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="100 Thieves",
team_B="Golden Guardians",
number_of_games_A=13,
number_of_games_B=13,
league="lcs_summer_2020",
fuzzy_system=FS))
print(get_prediction(team_A="SK Gaming",
team_B="Schalke 04 Esports",
number_of_games_A=9,
number_of_games_B=9,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="MAD Lions",
team_B="EXCEL",
number_of_games_A=9,
number_of_games_B=9,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Team Vitality",
team_B="Fnatic",
number_of_games_A=9,
number_of_games_B=9,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Rogue",
team_B="Misfits Gaming",
number_of_games_A=9,
number_of_games_B=9,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="G2 Esports",
team_B="Astralis",
number_of_games_A=9,
number_of_games_B=9,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Team Vitality",
team_B="SK Gaming",
number_of_games_A=10,
number_of_games_B=10,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Schalke 04 Esports",
team_B="MAD Lions",
number_of_games_A=10,
number_of_games_B=10,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Misfits Gaming",
team_B="Astralis",
number_of_games_A=10,
number_of_games_B=10,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Fnatic",
team_B="EXCEL",
number_of_games_A=10,
number_of_games_B=10,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Rogue",
team_B="G2 Esports",
number_of_games_A=10,
number_of_games_B=10,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Misfits Gaming",
team_B="EXCEL",
number_of_games_A=11,
number_of_games_B=11,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Schalke 04 Esports",
team_B="Rogue",
number_of_games_A=11,
number_of_games_B=11,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="SK Gaming",
team_B="MAD Lions",
number_of_games_A=11,
number_of_games_B=11,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Fnatic",
team_B="Astralis",
number_of_games_A=11,
number_of_games_B=11,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Team Vitality",
team_B="G2 Esports",
number_of_games_A=11,
number_of_games_B=11,
league="lec_summer_2021",
fuzzy_system=FS))
print(get_prediction(team_A="Team ESCA Gaming",
team_B="Gentlemen's Gaming",
number_of_games_A=8,
number_of_games_B=8,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Zero Tenacity",
team_B="Devils.One",
number_of_games_A=8,
number_of_games_B=8,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Komil&Friends",
team_B="Maturalni Forsaken",
number_of_games_A=8,
number_of_games_B=8,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Topo Centras Iron Wolves",
team_B="Goskilla",
number_of_games_A=8,
number_of_games_B=8,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="AGO Rogue",
team_B="Illuminar Gaming",
number_of_games_A=8,
number_of_games_B=8,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Team ESCA Gaming",
team_B="Komil&Friends",
number_of_games_A=9,
number_of_games_B=9,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Devils.One",
team_B="Maturalni Forsaken",
number_of_games_A=9,
number_of_games_B=9,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Gentlemen's Gaming",
team_B="Illuminar Gaming",
number_of_games_A=9,
number_of_games_B=9,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Zero Tenacity",
team_B="Topo Centras Iron Wolves",
number_of_games_A=9,
number_of_games_B=9,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Goskilla",
team_B="AGO Rogue",
number_of_games_A=9,
number_of_games_B=9,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Maturalni Forsaken",
team_B="AGO Rogue",
number_of_games_A=10,
number_of_games_B=10,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Topo Centras Iron Wolves",
team_B="Komil&Friends",
number_of_games_A=10,
number_of_games_B=10,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Team ESCA Gaming",
team_B="Illuminar Gaming",
number_of_games_A=10,
number_of_games_B=10,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Gentlemen's Gaming",
team_B="Devils.One",
number_of_games_A=10,
number_of_games_B=10,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(get_prediction(team_A="Zero Tenacity",
team_B="Goskilla",
number_of_games_A=10,
number_of_games_B=10,
league="ultraliga_summer_2022",
fuzzy_system=FS))
print(f"Prediction: {res}")