changed data filtering
This commit is contained in:
parent
5b4baf4202
commit
882c09cdc3
@ -1,4 +1,4 @@
|
||||
link_match : page link of match in Premier League Official website
|
||||
link_match : page link of match in Premier League Official websitemarkdow
|
||||
season : match season
|
||||
date : match date
|
||||
home_team : home team
|
||||
|
@ -1,6 +1,18 @@
|
||||
import pandas as pd
|
||||
from fuzzy import *
|
||||
|
||||
|
||||
def zapisz_do_csv(nazwa_pliku, dataframe):
|
||||
dataframe.to_csv(nazwa_pliku, mode='a', index=False, header=not pd.DataFrame().append(dataframe).empty)
|
||||
|
||||
def podziel_na_partie(dataframe, rozmiar_partii):
|
||||
for i in range(0, len(dataframe), rozmiar_partii):
|
||||
yield dataframe.iloc[i:i + rozmiar_partii]
|
||||
|
||||
def przetwarzaj_co_50_rekordow(plik_wejsciowy, plik_wyjsciowy):
|
||||
dataframe_wejsciowe = pd.read_csv(plik_wejsciowy)
|
||||
|
||||
|
||||
def generateTrainingData(dataframe):
|
||||
columns = ['season','date','home_team','away_team','result_full','home_passes','away_passes',
|
||||
'home_possession','away_possession','home_shots','away_shots']
|
||||
@ -10,10 +22,20 @@ def generateTrainingData(dataframe):
|
||||
def generateFuzzyLogicData(dataframe):
|
||||
columns = ['season','date','home_team','away_team','result_full','c_home_form_5m','c_away_form_5m',#,'c_home_passes','c_away_passes',
|
||||
# 'c_home_possession','c_away_possession','c_home_shots','c_away_shots',
|
||||
'c_home_diff_5m', 'c_away_diff_5m', 'c_home_aggression_5m',
|
||||
'c_away_aggression_5m', 'c_home_aggression_season', 'c_away_aggression_season',
|
||||
'c_home_form_season','c_away_form_season',
|
||||
'c_home_diff_season', 'c_away_diff_season']
|
||||
'c_home_diff_5m', 'c_away_diff_5m',"c_home_form_5s",
|
||||
'c_away_form_5s','c_home_diff_5s','c_away_diff_5s'
|
||||
, 'c_home_aggression_5m',
|
||||
'c_away_aggression_5m', 'c_away_shots_5m','c_away_shots_5m',
|
||||
'c_away_shots_5btw', 'c_away_shots_5btw', 'c_away_defence_5m',
|
||||
'c_away_defence_5m', 'c_away_defence_5btw', 'c_away_defence_5btw',
|
||||
'c_home_passing_5m', 'c_away_passing_5m', 'c_home_passing_5btw',
|
||||
'c_away_passing_5btw', 'c_away_aggression_5btw', 'c_away_aggression_5btw'
|
||||
|
||||
|
||||
#'c_home_aggression_season', 'c_away_aggression_season',
|
||||
# 'c_home_form_season','c_away_form_season',
|
||||
# 'c_home_diff_season', 'c_away_diff_season'
|
||||
]
|
||||
return dataframe[columns]
|
||||
|
||||
|
||||
@ -30,7 +52,7 @@ def last5Matches(season, teamA, data, df):
|
||||
# Wybierz 5 ostatnich przed daną datą
|
||||
last_before_date = before_given_date.head(5)
|
||||
|
||||
return last_before_date
|
||||
return last_before_date, "_5m"
|
||||
|
||||
def last5MatchesBtwTeams(teamA, teamB, data, df):
|
||||
subset = df[(((df['home_team'] == teamA) | (df['away_team'] == teamA)) & ((df['home_team'] == teamB) | (df['away_team'] == teamB)))]
|
||||
@ -38,7 +60,7 @@ def last5MatchesBtwTeams(teamA, teamB, data, df):
|
||||
before_given_date = before_given_date.sort_values(by='date', ascending=False)
|
||||
last_before_date = before_given_date.head(5)
|
||||
|
||||
return last_before_date
|
||||
return last_before_date, "_5btw"
|
||||
|
||||
def seasonMatches(season, teamA, data, df):
|
||||
# Wybierz rekordy dla danej pary drużyn i sezonu
|
||||
@ -50,7 +72,7 @@ def seasonMatches(season, teamA, data, df):
|
||||
# Posortuj wg daty w odwrotnej kolejności
|
||||
before_given_date = before_given_date.sort_values(by='date', ascending=False)
|
||||
|
||||
return before_given_date
|
||||
return before_given_date, "_s"
|
||||
|
||||
def getResult(score,teamHome):
|
||||
x,y = score.split('-')
|
||||
@ -64,23 +86,23 @@ def getResult(score,teamHome):
|
||||
else:
|
||||
return "loss"
|
||||
|
||||
def calculateAggression(matches, team):
|
||||
aggression = 0
|
||||
for index, row in matches.iterrows():
|
||||
if team == row['home_team']:
|
||||
yellow_cards = row['home_yellow_cards']
|
||||
red_cards = row['home_red_cards']
|
||||
else:
|
||||
yellow_cards = row['away_yellow_cards']
|
||||
red_cards = row['away_red_cards']
|
||||
aggression_result = calculateFuzzyAggression(yellow_cards, red_cards)
|
||||
#print(aggression_result['aggression'])
|
||||
aggression = aggression + aggression_result['aggression']
|
||||
if matches.shape[0] != 0:
|
||||
aggression_avg = aggression / matches.shape[0]
|
||||
else:
|
||||
aggression_avg = 0
|
||||
return aggression_avg
|
||||
# def calculateAggression(matches, team):
|
||||
# aggression = 0
|
||||
# for index, row in matches.iterrows():
|
||||
# if team == row['home_team']:
|
||||
# yellow_cards = row['home_yellow_cards']
|
||||
# red_cards = row['home_red_cards']
|
||||
# else:
|
||||
# yellow_cards = row['away_yellow_cards']
|
||||
# red_cards = row['away_red_cards']
|
||||
# aggression_result = calculateFuzzyAggression(yellow_cards, red_cards)
|
||||
# #print(aggression_result['aggression'])
|
||||
# aggression = aggression + aggression_result['aggression']
|
||||
# if matches.shape[0] != 0:
|
||||
# aggression_avg = aggression / matches.shape[0]
|
||||
# else:
|
||||
# aggression_avg = 0
|
||||
# return aggression_avg
|
||||
|
||||
def calculatePoints(matches, team):
|
||||
points = 0
|
||||
@ -118,4 +140,17 @@ def calculateGoalDifference(matches, team):
|
||||
goal_diff = goal_diff + (y-x)
|
||||
return goal_diff
|
||||
|
||||
|
||||
def calculateColumn(matches, team, column_name):
|
||||
result = 0
|
||||
for index, row in matches.iterrows():
|
||||
if team == row['home_team']:
|
||||
column = row[column_name]
|
||||
else:
|
||||
column = row[column_name]
|
||||
result = result + column
|
||||
if matches.shape[0] != 0:
|
||||
result_avg = result / matches.shape[0]
|
||||
else:
|
||||
result_avg = 0
|
||||
return result_avg
|
||||
|
||||
|
14
fuzzy.py
14
fuzzy.py
@ -10,7 +10,7 @@ FS = FuzzySystem()
|
||||
# odbiory i wslizgi (xDef) - Michał, ekspert od xDef
|
||||
# statystyki z calego sezonu - Wojtek OK
|
||||
# 5 ostatnich spotkan miedzy druzynami - Witek
|
||||
def categorize_fuzzy_passes(passes,possession):
|
||||
def categorizeFuzzyPasses(passes,possession):
|
||||
|
||||
|
||||
FS.set_crisp_output_value("low", 0.0)
|
||||
@ -64,10 +64,10 @@ def categorize_fuzzy_passes(passes,possession):
|
||||
|
||||
pass_domination = FS.inference()
|
||||
|
||||
return pass_domination
|
||||
return pass_domination['pass_domination']
|
||||
|
||||
|
||||
def categorize_fuzzy_defence(tackles,clearances):
|
||||
def categorizeFuzzyDefence(tackles,clearances):
|
||||
|
||||
|
||||
FS.set_crisp_output_value("low", 0.0)
|
||||
@ -113,9 +113,9 @@ def categorize_fuzzy_defence(tackles,clearances):
|
||||
|
||||
defence_actions = FS.inference()
|
||||
|
||||
return defence_actions
|
||||
return defence_actions['defence_actions']
|
||||
|
||||
def categorize_fuzzy_shots(shots_overall, shots_on_target):
|
||||
def categorizeFuzzyShots(shots_overall, shots_on_target):
|
||||
|
||||
FS.set_crisp_output_value("low", 0.0)
|
||||
FS.set_crisp_output_value("average", 0.5)
|
||||
@ -169,7 +169,7 @@ def categorize_fuzzy_shots(shots_overall, shots_on_target):
|
||||
|
||||
quality_of_shots = FS.inference()
|
||||
|
||||
return quality_of_shots
|
||||
return quality_of_shots['quality_of_shots']
|
||||
|
||||
def calculateFuzzyAggression(yellow_cards, red_cards):
|
||||
FS.set_crisp_output_value("low", 0.0)
|
||||
@ -219,4 +219,4 @@ def calculateFuzzyAggression(yellow_cards, red_cards):
|
||||
FS.set_variable("red_cards", red_cards)
|
||||
|
||||
aggression = FS.inference()
|
||||
return aggression
|
||||
return aggression['aggression']
|
197
main.py
197
main.py
@ -23,17 +23,27 @@ from sklearn.metrics import classification_report
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
df = pd.read_csv('df_full_premierleague.csv')
|
||||
result = last5Matches('10/11', 'Stoke City', '2010-10-02', df)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
df = pd.read_csv('df_full_premierleague.csv')
|
||||
result = last5Matches('10/11', 'Stoke City', '2010-10-02', df)[0]
|
||||
#print(result.to_markdown())
|
||||
#print(result)
|
||||
result = last5Matches('10/11', 'Blackburn Rovers', '2010-10-02', df)
|
||||
result = last5Matches('10/11', 'Blackburn Rovers', '2010-10-02', df)[0]
|
||||
#print(result.to_markdown())
|
||||
#print(result)
|
||||
|
||||
print(calculatePoints(result,'Blackburn Rovers'))
|
||||
print(calculateGoalDifference(result, 'Blackburn Rovers'))
|
||||
|
||||
'''
|
||||
|
||||
# df = generateTrainingData(df)
|
||||
# df = add_column(df, categorize_passes, "c_away_passes", "away_passes")
|
||||
# df = add_column(df, categorize_passes, "c_home_passes", "home_passes")
|
||||
@ -44,22 +54,159 @@ if __name__ == "__main__":
|
||||
# df = add_column(df, categorize_shots, "c_away_shots", "away_shots")
|
||||
# df = add_column(df, categorize_shots, "c_home_shots", "home_shots")
|
||||
# print(df.columns)
|
||||
###############################################################################################
|
||||
# df = add_column(df, getColumnMethod(df, True, 'home_yellow_cards', seasonMatches), "c_home_yellow_cards_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'away_yellow_cards', seasonMatches), "c_away_yellow_cards_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'home_red_cards', seasonMatches), "c_home_red_cards_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'away_red_cards', seasonMatches), "c_away_red_cards_s")
|
||||
df = df.sort_values(by='date', ascending=False)
|
||||
|
||||
df = add_column(df, getColumnMethod(df, True, 'home_yellow_cards', last5Matches), "c_home_yellow_cards_5m")
|
||||
df = add_column(df, getColumnMethod(df, False, 'away_yellow_cards', last5Matches), "c_away_yellow_cards_5m")
|
||||
df = add_column(df, getColumnMethod(df, True, 'home_red_cards', last5Matches), "c_home_red_cards_5m")
|
||||
df = add_column(df, getColumnMethod(df, False, 'away_red_cards', last5Matches), "c_away_red_cards_5m")
|
||||
|
||||
df = add_column(df, getColumnMethod5Btw(df, True, 'home_yellow_cards', last5MatchesBtwTeams),
|
||||
"c_home_yellow_cards_5btw")
|
||||
df = add_column(df, getColumnMethod5Btw(df, False, 'away_yellow_cards', last5MatchesBtwTeams),
|
||||
"c_away_yellow_cards_5btw")
|
||||
df = add_column(df, getColumnMethod5Btw(df, True, 'home_red_cards', last5MatchesBtwTeams), "c_home_red_cards_5btw")
|
||||
df = add_column(df, getColumnMethod5Btw(df, False, 'away_red_cards', last5MatchesBtwTeams), "c_away_red_cards_5btw")
|
||||
|
||||
|
||||
|
||||
###################################################################################################################
|
||||
# df = add_column(df, getColumnMethod(df, True, 'home_shots', seasonMatches), "c_home_shots_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'away_shots', seasonMatches), "c_away_shots_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'home_shots_on_target', seasonMatches), "c_home_shots_on_target_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'away_shots_on_target', seasonMatches), "c_away_shots_on_target_s")
|
||||
|
||||
df = add_column(df, getColumnMethod(df, True, 'home_shots', last5Matches), "c_home_shots_5m")
|
||||
df = add_column(df, getColumnMethod(df, False, 'away_shots', last5Matches), "c_away_shots_5m")
|
||||
df = add_column(df, getColumnMethod(df, True, 'home_shots_on_target', last5Matches), "c_home_shots_on_target_5m")
|
||||
df = add_column(df, getColumnMethod(df, False, 'away_shots_on_target', last5Matches), "c_away_shots_on_target_5m")
|
||||
|
||||
df = add_column(df, getColumnMethod5Btw(df, True, 'home_shots', last5MatchesBtwTeams), "c_home_shots")
|
||||
df = add_column(df, getColumnMethod5Btw(df, False, 'away_shots', last5MatchesBtwTeams), "c_away_shots")
|
||||
df = add_column(df, getColumnMethod5Btw(df, True, 'home_shots_on_target', last5MatchesBtwTeams),
|
||||
"c_home_shots_on_target_5btw")
|
||||
df = add_column(df, getColumnMethod5Btw(df, False, 'away_shots_on_target', last5MatchesBtwTeams),
|
||||
"c_away_shots_on_target_5btw")
|
||||
|
||||
|
||||
###################################################################################################################################
|
||||
# df = add_column(df, getColumnMethod(df, True, 'home_tackles', seasonMatches), "c_home_tackles_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'away_tackles', seasonMatches), "c_away_tackles_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'home_clearances', seasonMatches), "c_home_clearances_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'away_clearances', seasonMatches), "c_away_clearances_s")
|
||||
|
||||
df = add_column(df, getColumnMethod(df, True, 'home_tackles', last5Matches), "c_home_tackles_5m")
|
||||
df = add_column(df, getColumnMethod(df, False, 'away_tackles', last5Matches), "c_away_tackles_5m")
|
||||
df = add_column(df, getColumnMethod(df, True, 'home_clearances', last5Matches), "c_home_clearances_5m")
|
||||
df = add_column(df, getColumnMethod(df, False, 'away_clearances', last5Matches), "c_away_clearances_5m")
|
||||
|
||||
df = add_column(df, getColumnMethod5Btw(df, True, 'home_tackles', last5MatchesBtwTeams), "c_home_tackles_5btw")
|
||||
df = add_column(df, getColumnMethod5Btw(df, False, 'away_tackles', last5MatchesBtwTeams), "c_away_tackles_5btw")
|
||||
df = add_column(df, getColumnMethod5Btw(df, True, 'home_clearances', last5MatchesBtwTeams),
|
||||
"c_home_clearances_5btw")
|
||||
df = add_column(df, getColumnMethod5Btw(df, False, 'away_clearances', last5MatchesBtwTeams),
|
||||
"c_away_clearances_5btw")
|
||||
|
||||
|
||||
|
||||
####################################################################################################################################
|
||||
# df = add_column(df, getColumnMethod(df, True, 'home_passes', seasonMatches), "c_home_passes_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'away_passes', seasonMatches), "c_away_passes_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'home_possession', seasonMatches), "c_home_possession_s")
|
||||
# df = add_column(df, getColumnMethod(df, True, 'away_possession', seasonMatches), "c_away_possession_s")
|
||||
|
||||
df = add_column(df, getColumnMethod(df, True, 'home_passes', last5Matches), "c_home_passes_5m")
|
||||
df = add_column(df, getColumnMethod(df, False, 'away_passes', last5Matches), "c_away_passes_5m")
|
||||
df = add_column(df, getColumnMethod(df, True, 'home_possession', last5Matches), "c_home_possession_5m")
|
||||
df = add_column(df, getColumnMethod(df, False, 'away_possession', last5Matches), "c_away_possession_5m")
|
||||
|
||||
df = add_column(df, getColumnMethod5Btw(df, True, 'home_passes', last5MatchesBtwTeams), "c_home_passes_5btw")
|
||||
df = add_column(df, getColumnMethod5Btw(df, False, 'away_passes', last5MatchesBtwTeams), "c_away_passes_5btw")
|
||||
df = add_column(df, getColumnMethod5Btw(df, True, 'home_possession', last5MatchesBtwTeams),
|
||||
"c_home_possession_5btw")
|
||||
df = add_column(df, getColumnMethod5Btw(df, False, 'away_possession', last5MatchesBtwTeams),
|
||||
"c_away_possession_5btw")
|
||||
|
||||
# TU
|
||||
|
||||
|
||||
##########################################################################################################################################
|
||||
|
||||
df = add_column(df, get_method(df, True, categorize_points, last5Matches), "c_home_form_5m")
|
||||
df = add_column(df, get_method(df, False, categorize_points, last5Matches), "c_away_form_5m")
|
||||
|
||||
df = add_column(df, get_method(df, True, categorize_diff, last5Matches), "c_home_diff_5m")#categorize_diff
|
||||
df = add_column(df, get_method(df, False, categorize_diff,last5Matches), "c_away_diff_5m")
|
||||
df = add_column(df, get_method(df, True, categorize_aggression, last5Matches), "c_home_aggression_5m")#categorize_diff
|
||||
df = add_column(df, get_method(df, False, categorize_aggression,last5Matches), "c_away_aggression_5m")
|
||||
df = add_column(df, get_method(df, True, categorize_points, seasonMatches), "c_home_form_season")
|
||||
df = add_column(df, get_method(df, False, categorize_points, seasonMatches), "c_away_form_season")
|
||||
df = add_column(df, get_method(df, True, categorize_diff, seasonMatches), "c_home_diff_5m")
|
||||
df = add_column(df, get_method(df, False, categorize_diff, seasonMatches), "c_away_diff_5m")
|
||||
|
||||
df = add_column(df, get_method(df, True, categorize_diff, seasonMatches), "c_home_diff_season")#categorize_diff
|
||||
df = add_column(df, get_method(df, False, categorize_diff,seasonMatches), "c_away_diff_season")
|
||||
df = add_column(df, get_method(df, True, categorize_points_Btw, last5MatchesBtwTeams), "c_home_form_5btw")
|
||||
df = add_column(df, get_method(df, False, categorize_points_Btw, last5MatchesBtwTeams), "c_away_form_5btw")
|
||||
|
||||
df = add_column(df, get_method(df, True, categorize_aggression, seasonMatches), "c_home_aggression_season")#categorize_diff
|
||||
df = add_column(df, get_method(df, False, categorize_aggression,seasonMatches), "c_away_aggression_season")
|
||||
df = add_column(df, get_method(df, True, categorize_diff_Btw, last5MatchesBtwTeams), "c_home_diff_5btw")
|
||||
df = add_column(df, get_method(df, False, categorize_diff_Btw, last5MatchesBtwTeams), "c_away_diff_5btw")
|
||||
|
||||
df = add_column(df, get_method(df, True, categorize_points, seasonMatches), "c_home_form_5s")
|
||||
df = add_column(df, get_method(df, False, categorize_points, seasonMatches), "c_away_form_5s")
|
||||
|
||||
df = add_column(df, get_method(df, True, categorize_diff, seasonMatches), "c_home_diff_5s")
|
||||
df = add_column(df, get_method(df, False, categorize_diff, seasonMatches), "c_away_diff_5s")
|
||||
|
||||
df.to_csv('df.csv', index=False)
|
||||
#TU sie zapisuje zbior
|
||||
|
||||
rozmiar_partii = 50
|
||||
for part in podziel_na_partie(df, rozmiar_partii):
|
||||
|
||||
|
||||
part = add_column(part,
|
||||
getFuzzyMethod(part, calculateFuzzyAggression, True, "c_home_yellow_cards_5m", "c_home_red_cards_5m"),
|
||||
"c_home_aggression_5m")
|
||||
part = add_column(part, getFuzzyMethod(part, calculateFuzzyAggression, False, "c_away_yellow_cards_5m",
|
||||
"c_away_red_cards_5m"), "c_away_aggression_5m")
|
||||
|
||||
part = add_column(part, getFuzzyMethod(part, calculateFuzzyAggression, True, "c_home_yellow_cards_5btw",
|
||||
"c_home_red_cards_5btw"), "c_home_aggression_5btw")
|
||||
part = add_column(part, getFuzzyMethod(part, calculateFuzzyAggression, False, "c_away_yellow_cards_5btw",
|
||||
"c_away_red_cards_5btw"), "c_away_aggression_5btw")
|
||||
|
||||
part = add_column(part, getFuzzyMethod(part, categorizeFuzzyShots, True, "c_home_shots_5m", "c_home_shots_5m"),
|
||||
"c_home_shots_5m")
|
||||
part = add_column(part, getFuzzyMethod(part, categorizeFuzzyShots, False, "c_away_shots_5m", "c_away_shots_5m"),
|
||||
"c_away_shots_5m")
|
||||
|
||||
part = add_column(part, getFuzzyMethod(part, categorizeFuzzyShots, True, "c_home_shots_on_target_5btw",
|
||||
"c_home_shots_on_target_5btw"), "c_home_shots_5btw")
|
||||
part = add_column(part, getFuzzyMethod(part, categorizeFuzzyShots, False, "c_away_shots_on_target_5btw",
|
||||
"c_away_shots_on_target_5btw"), "c_away_shots_5btw")
|
||||
|
||||
part = add_column(part, getFuzzyMethod(part, categorizeFuzzyDefence, True, "c_home_tackles_5m", "c_home_clearances_5m"),
|
||||
"c_home_defence_5m")
|
||||
part = add_column(part, getFuzzyMethod(part, categorizeFuzzyDefence, False, "c_away_tackles_5m", "c_away_clearances_5m"),
|
||||
"c_away_defence_5m")
|
||||
|
||||
part = add_column(part,
|
||||
getFuzzyMethod(part, categorizeFuzzyDefence, True, "c_home_tackles_5btw", "c_home_clearances_5btw"),
|
||||
"c_home_defence_5btw")
|
||||
part = add_column(part,
|
||||
getFuzzyMethod(part, categorizeFuzzyDefence, False, "c_away_tackles_5btw", "c_away_clearances_5btw"),
|
||||
"c_away_defence_5btw")
|
||||
part = add_column(part, getFuzzyMethod(part, categorizeFuzzyPasses, True, "c_home_passes_5m", "c_home_possession_5m"),
|
||||
"c_home_passing_5m")
|
||||
part = add_column(part, getFuzzyMethod(part, categorizeFuzzyPasses, False, "c_away_passes_5m", "c_away_possession_5m"),
|
||||
"c_away_passing_5m")
|
||||
|
||||
part = add_column(part, getFuzzyMethod(part, categorizeFuzzyPasses, True, "c_home_passes_5btw", "c_home_possession_5btw"),
|
||||
"c_home_passing_5btw")
|
||||
part = add_column(part,
|
||||
getFuzzyMethod(part, categorizeFuzzyPasses, False, "c_away_passes_5btw", "c_away_possession_5btw"),
|
||||
"c_away_passing_5btw")
|
||||
|
||||
|
||||
zapisz_do_csv("df_parts", part)
|
||||
|
||||
df = generateFuzzyLogicData(df)
|
||||
|
||||
@ -86,8 +233,26 @@ if __name__ == "__main__":
|
||||
print(f'Dokładność modelu: {accuracy}')
|
||||
print(classification_report(y_test, y_pred))
|
||||
|
||||
result = last5Matches('10/11', 'Manchester United', '2010-12-16', df)
|
||||
print(calculatePoints(result,'Manchester United'))
|
||||
print(calculateGoalDifference(result, 'Manchester United'))
|
||||
|
||||
print(categorize_fuzzy_passes(450,50))
|
||||
#print(categorize_fuzzy_passes(450,50))
|
||||
|
||||
#df.to_csv('df.csv', index=False)
|
||||
|
||||
|
||||
# df = add_column(df, get_method(df, True, categorize_aggression, last5Matches), "c_home_aggression_5m")#categorize_diff
|
||||
# df = add_column(df, get_method(df, False, categorize_aggression,last5Matches), "c_away_aggression_5m")
|
||||
# df = add_column(df, get_method(df, True, categorize_points, seasonMatches), "c_home_form_season")
|
||||
# df = add_column(df, get_method(df, False, categorize_points, seasonMatches), "c_away_form_season")
|
||||
|
||||
#df = add_column(df, get_method(df, True, categorize_diff, seasonMatches), "c_home_diff_season")#categorize_diff
|
||||
# df = add_column(df, get_method(df, False, categorize_diff,seasonMatches), "c_away_diff_season")
|
||||
|
||||
# df = add_column(df, get_method(df, True, categorize_aggression, seasonMatches), "c_home_aggression_season")#categorize_diff
|
||||
# df = add_column(df, get_method(df, False, categorize_aggression,seasonMatches), "c_away_aggression_season")
|
||||
|
||||
|
||||
#df = add_column(df, get_method(df, True, categorize_points, last5MatchesBtwTeams), "c_home_form_5btw")
|
||||
#df = add_column(df, get_method(df, False, categorize_points, last5MatchesBtwTeams), "c_away_form_5btw")
|
||||
|
||||
#df = add_column(df, get_method(df, True, categorize_diff, last5MatchesBtwTeams), "c_home_diff_5btw")#categorize_diff
|
||||
#df = add_column(df, get_method(df, False, categorize_diff,last5MatchesBtwTeams), "c_away_diff_5btw")
|
118
rules.py
118
rules.py
@ -28,10 +28,10 @@ def categorize_possesion(shots):
|
||||
|
||||
def categorize_points(data, row, teamHome, matches_type):
|
||||
if teamHome:
|
||||
data_5 = matches_type(row['season'], row['home_team'], row['date'], data)
|
||||
data_5 = matches_type(row['season'], row['home_team'], row['date'], data)[0]
|
||||
points = calculatePoints(data_5,row['home_team'])
|
||||
else:
|
||||
data_5 = matches_type(row['season'], row['away_team'], row['date'], data)
|
||||
data_5 = matches_type(row['season'], row['away_team'], row['date'], data)[0]
|
||||
points = calculatePoints(data_5,row['away_team'])
|
||||
if points <=1:
|
||||
return 0
|
||||
@ -40,12 +40,30 @@ def categorize_points(data, row, teamHome, matches_type):
|
||||
else:
|
||||
return 1
|
||||
|
||||
def categorize_points_Btw(data, row, teamHome, matches_type):
|
||||
if teamHome:
|
||||
data_5 = matches_type(row['home_team'], row['away_team'], row['date'], data)[0]
|
||||
points = calculatePoints(data_5,row['home_team'])
|
||||
else:
|
||||
data_5 = matches_type(row['home_team'], row['away_team'], row['date'], data)[0]
|
||||
points = calculatePoints(data_5,row['away_team'])
|
||||
if points <=1:
|
||||
return 0
|
||||
elif points >=2:
|
||||
return 2
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
|
||||
def get_method(data, home_away, method, matches_type):
|
||||
values = []
|
||||
for index, row in data.iterrows():
|
||||
values.append(method(data, row, home_away, matches_type))
|
||||
return values
|
||||
|
||||
|
||||
def get_points_home(data):
|
||||
points = []
|
||||
for index, row in data.iterrows():
|
||||
@ -65,28 +83,53 @@ def get_points_away(data):
|
||||
|
||||
def categorize_diff(data, row, teamHome, matches_type):
|
||||
if teamHome:
|
||||
data_5 = matches_type(row['season'], row['home_team'], row['date'], data)
|
||||
data_5 = matches_type(row['season'], row['home_team'], row['date'], data)[0]
|
||||
diff = calculateGoalDifference(data_5,row['home_team'])
|
||||
else:
|
||||
data_5 = matches_type(row['season'], row['away_team'], row['date'], data)
|
||||
data_5 = matches_type(row['season'], row['away_team'], row['date'], data)[0]
|
||||
diff = calculateGoalDifference(data_5,row['away_team'])
|
||||
if diff <=0:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
def categorize_diff_Btw(data, row, teamHome, matches_type):
|
||||
if teamHome:
|
||||
data_5 = matches_type(row['home_team'], row['away_team'], row['date'], data)[0]
|
||||
diff = calculateGoalDifference(data_5,row['home_team'])
|
||||
else:
|
||||
data_5 = matches_type(row['home_team'], row['away_team'], row['date'], data)[0]
|
||||
diff = calculateGoalDifference(data_5,row['away_team'])
|
||||
if diff <=0:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
||||
def categorize_diff(data, row, teamHome, matches_type):
|
||||
if teamHome:
|
||||
data_5 = matches_type(row['season'], row['home_team'], row['date'], data)[0]
|
||||
diff = calculateGoalDifference(data_5,row['home_team'])
|
||||
else:
|
||||
data_5 = matches_type(row['season'], row['away_team'], row['date'], data)[0]
|
||||
diff = calculateGoalDifference(data_5,row['away_team'])
|
||||
if diff <=0:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
def categorize_aggression(data, row, teamHome, matches_type):
|
||||
if teamHome:
|
||||
data_5 = matches_type(row['season'], row['home_team'], row['date'], data)
|
||||
diff = calculateAggression(data_5,row['home_team'])
|
||||
else:
|
||||
data_5 = matches_type(row['season'], row['away_team'], row['date'], data)
|
||||
diff = calculateAggression(data_5,row['away_team'])
|
||||
return diff
|
||||
# if diff <=0:
|
||||
# return 0
|
||||
# else:
|
||||
# return 1
|
||||
# def categorize_aggression(data, row, teamHome, matches_type):
|
||||
# if teamHome:
|
||||
# data_5 = matches_type(row['season'], row['home_team'], row['date'], data)
|
||||
# diff = calculateAggression(data_5,row['home_team'])
|
||||
# else:
|
||||
# data_5 = matches_type(row['season'], row['away_team'], row['date'], data)
|
||||
# diff = calculateAggression(data_5,row['away_team'])
|
||||
# return diff
|
||||
# # if diff <=0:
|
||||
# # return 0
|
||||
# # else:
|
||||
# # return 1
|
||||
def get_diff_home(data):
|
||||
points = []
|
||||
for index, row in data.iterrows():
|
||||
@ -119,3 +162,46 @@ def get_result_list(df, home_team):
|
||||
for score in df['result_full']:
|
||||
results.append(getResult(score,home_team))
|
||||
return results
|
||||
|
||||
def getColumnMethod(data, home_away, column, matches_type):
|
||||
values = []
|
||||
for index, row in data.iterrows():
|
||||
values.append(getColumnByMatches(data, row, home_away, matches_type,column))
|
||||
return values
|
||||
|
||||
def getColumnMethod5Btw(data, home_away, column, matches_type):
|
||||
values = []
|
||||
for index, row in data.iterrows():
|
||||
values.append(getColumnByMatches5Btw(data, row, home_away, matches_type,column))
|
||||
return values
|
||||
|
||||
def getFuzzyMethod(data, method, home_away, frist_column, second_column):
|
||||
values = []
|
||||
for index, row in data.iterrows():
|
||||
values.append(getFuzzyByMatches(method, row, home_away, frist_column, second_column))
|
||||
return values
|
||||
|
||||
def getColumnByMatches(data, row, teamHome, matches_type, column):
|
||||
if teamHome:
|
||||
data_5, end = matches_type(row['season'], row['home_team'], row['date'], data)
|
||||
result = calculateColumn(data_5, row['home_team'], column)
|
||||
else:
|
||||
data_5, end = matches_type(row['season'], row['away_team'], row['date'], data)
|
||||
result = calculateColumn(data_5, row['away_team'], column)
|
||||
return result
|
||||
|
||||
def getColumnByMatches5Btw(data, row, teamHome, matches_type, column):
|
||||
if teamHome:
|
||||
data_5, end = last5MatchesBtwTeams(row['home_team'], row['away_team'], row['date'], data)
|
||||
result = calculateColumn(data_5, row['home_team'], column)
|
||||
else:
|
||||
data_5, end = matches_type(row['home_team'], row['away_team'], row['date'], data)
|
||||
result = calculateColumn(data_5, row['away_team'], column)
|
||||
return result
|
||||
|
||||
def getFuzzyByMatches(method, row, teamHome, frist_column, second_column):
|
||||
if teamHome:
|
||||
result = method(row[frist_column], row[second_column])
|
||||
else:
|
||||
result = method(row[frist_column], row[second_column])
|
||||
return result
|
Loading…
Reference in New Issue
Block a user