initial commit

This commit is contained in:
s452662 2024-01-06 15:53:05 +01:00
commit 7a16f22192
4 changed files with 4331 additions and 0 deletions

113
data_dictionary.txt Normal file
View File

@ -0,0 +1,113 @@
link_match : page link of match in Premier League Official website
season : match season
date : match date
home_team : home team
away_team : away team
result_full : match result
result_ht : match result in 1st time
home_clearances : home team clearances in the match
home_corners : home team corners in the match
home_fouls_conceded : home team fouls conceded in the match
home_offsides : home team offsides in the match
home_passes : home team passes in the match
home_possession : home team possession in the match
home_red_cards : home team red cards in the match
home_shots : home team shots in the match
home_shots_on_target : home team shots on target in the match
home_tackles : home team tackles in the match
home_touches : home team touches in the match
home_yellow_cards : home team yellow cards in the match
away_clearances : away tem clearances in the match
away_corners : away team corners in the match
away_fouls_conceded : away team fouls conceded in the match
away_offsides : away team offsides in the match
away_passes : away team passes in the match
away_possession : away team possession in the match
away_red_cards : away team red cards in the match
away_shots : away team shots in the match
away_shots_on_target : away team shots on target in the match
away_tackles : away team tackles in the match
away_touches : away team touches in the match
away_yellow_cards : away team yellow cards in the match
goal_home_ft : home team goals scored in the match
goal_away_ft : away team goals scored in the match
sg_match_ft : goals difference between home team and away team in the match
goal_home_ht : home team goals scored in 1st time in the match
goal_away_ht : away team goals scored in 1st time in the match
sg_match_ht : goals difference between home team and away team in 1st time in the match
clearances_avg_H : average home team clearances in matches as host in the season; accumulated until the last match
corners_avg_H : average home team corners in matches as host in the season; accumulated until the last match
fouls_conceded_avg_H : average home team fouls conceded in matches as host in the season; accumulated until the last match
offsides_avg_H : average home team offsides in matches as host in the season; accumulated until the last match
passes_avg_H : average home team passes in matches as host in the season; accumulated until the last match
possession_avg_H : average home team possession in matches as host in the season; accumulated until the last match
red_cards_avg_H : average home team red cards in matches as host in the season; accumulated until the last match
shots_avg_H : average home team shots in matches as host in the season; accumulated until the last match
shots_on_target_avg_H : average home team shots on target in matches as host in the season; accumulated until the last match
tackles_avg_H : average home team tackles in matches as host in the season; accumulated until the last match
touches_avg_H : average home team touches in matches as host in the season; accumulated until the last match
yellow_cards_avg_H : average home team yellow cards in matches as host in the season; accumulated until the last match
goals_scored_ft_avg_H : average home team goals scored in matches as host in the season; accumulated until the last match
goals_conced_ft_avg_H : average home team goals conceded in matches as host in the season; accumulated until the last match
sg_match_ft_acum_H : goals difference in matches as host in the season; accumulated until the last match
goals_scored_ht_avg_H : average home team goals scored in 1st time in matches as host in the season; accumulated until the last match
goals_conced_ht_avg_H : average home team goals conceded in 1st time in matches as host in the season; accumulated until the last match
sg_match_ht_acum_H : goals difference in 1st time in matches as host in the season; accumulated until the last match
performance_acum_H : home team percentage of points gains in matches as host in the season; accumulated until the last match
clearances_avg_A : average away team clearances in matches as host in the season; accumulated until the last match
corners_avg_A : average away team corners in matches as host in the season; accumulated until the last match
fouls_conceded_avg_A : average away team fouls conceded in matches as host in the season; accumulated until the last match
offsides_avg_A : average away team offsides in matches as host in the season; accumulated until the last match
passes_avg_A : average away team passes in matches as host in the season; accumulated until the last match
possession_avg_A : average away team possession in matches as host in the season; accumulated until the last match
red_cards_avg_A : average away team red cards in matches as host in the season; accumulated until the last match
shots_avg_A : average away team shots in matches as host in the season; accumulated until the last match
shots_on_target_avg_A : average away team shots on target in matches as host in the season; accumulated until the last match
tackles_avg_A : average away team tackles in matches as host in the season; accumulated until the last match
touches_avg_A : average away team touches in matches as host in the season; accumulated until the last match
yellow_cards_avg_A : average away team yellow cards in matches as host in the season; accumulated until the last match
goals_scored_ft_avg_A : average away team goals scored in matches as host in the season; accumulated until the last match
goals_conced_ft_avg_A : average away team goals conceded in matches as host in the season; accumulated until the last match
sg_match_ft_acum_A : goals difference in matches as host in the season; accumulated until the last match
goals_scored_ht_avg_A : average away team goals scored in 1st time in matches as host in the season; accumulated until the last match
goals_conced_ht_avg_A : average away team goals conceded in 1st time in matches as host in the season; accumulated until the last match
sg_match_ht_acum_A : goals difference in 1st time in matches as host in the season; accumulated until the last match
performance_acum_A : away team percentage of points gains in matches as host in the season; accumulated until the last match
clearances_avg_home : average home team clearances in the season; accumulated until the last match
corners_avg_home : average home team corners in the season; accumulated until the last match
fouls_conceded_avg_home : average home team fouls conceded in the season; accumulated until the last match
offsides_avg_home : average home team offsides in the season; accumulated until the last match
passes_avg_home : average home team passes in the season; accumulated until the last match
possession_avg_home : average home team possession in the season; accumulated until the last match
red_cards_avg_home : average home team red cards in the season; accumulated until the last match
shots_avg_home : average home team shots in the season; accumulated until the last match
shots_on_target_avg_home: average home team shots on target in the season; accumulated until the last match
tackles_avg_home : average home team tackles in the season; accumulated until the last match
touches_avg_home : average home team touches in the season; accumulated until the last match
yellow_cards_avg_home : average home team yellow cards in the season; accumulated until the last match
goals_scored_ft_avg_home: average home team goals scored in the season; accumulated until the last match
goals_conced_ft_avg_home: average home team goals conceded in the season; accumulated until the last match
sg_match_ft_acum_home : goals difference in the season; accumulated until the last match
goals_scored_ht_avg_home: average home team goals scored in 1st time in the season; accumulated until the last match
goals_conced_ht_avg_home: average home team goals conceded in 1st time in the season; accumulated until the last match
sg_match_ht_acum_home : goals difference in 1st time in the season; accumulated until the last match
performance_acum_home : home team percentage of points gains in the season; accumulated until the last match
clearances_avg_away : average away team clearances in the season; accumulated until the last match
corners_avg_away : average away team corners in the season; accumulated until the last match
fouls_conceded_avg_away : average away team fouls conceded in the season; accumulated until the last match
offsides_avg_away : average away team offsides in the season; accumulated until the last match
passes_avg_away : average away team passes in the season; accumulated until the last match
possession_avg_away : average away team possession in the season; accumulated until the last match
red_cards_avg_away : average away team red cards in the season; accumulated until the last match
shots_avg_away : average away team shots in the season; accumulated until the last match
shots_on_target_avg_away: average away team shots on target in the season; accumulated until the last match
tackles_avg_away : average away team tackles in the season; accumulated until the last match
touches_avg_away : average away team touches in the season; accumulated until the last match
yellow_cards_avg_away : average away team yellow cards in the season; accumulated until the last match
goals_scored_ft_avg_away: average away team goals scored in the season; accumulated until the last match
goals_conced_ft_avg_away: average away team goals conceded in the season; accumulated until the last match
sg_match_ft_acum_away : goals difference in the season; accumulated until the last match
goals_scored_ht_avg_away: average away team goals scored in 1st time in the season; accumulated until the last match
goals_conced_ht_avg_away: average away team goals conceded in 1st time in the season; accumulated until the last match
sg_match_ht_acum_away : goals difference in 1st time in the season; accumulated until the last match
performance_acum_away : away team percentage of points gains in the season; accumulated until the last match

4071
df_full_premierleague.csv Normal file

File diff suppressed because it is too large Load Diff

106
main.py Normal file
View File

@ -0,0 +1,106 @@
import pandas as pd
from simpful import *
df = pd.read_csv('df_full_premierleague.csv')
# Ostatnie 5 spotkań
#Forma: 0-6 punktow = słaba, średnia 6-10, dobra 10-15 punktow
#Bilans bramek ujemny dodatni
#Strzały 6- mało pomiędzy średnio 12 - dużo
#Posiadanie piłki słabe 30-40, średnie = 40-55, dobre = 56-64
#Podania ponizej 300-400 słabo powyżej 500 dużo
def generateTrainingData(dataframe):
columns = ['season','date','home_team','away_team','result_full','home_passes','away_passes',
'home_possession','away_possession','home_shots','away_shots']
return dataframe[columns]
def last5Matches(sezon, druzynaA, data, df):
# Wybierz rekordy dla danej pary drużyn i sezonu
subset = df[((df['season'] == sezon) & ((df['home_team'] == druzynaA) | (df['away_team'] == druzynaA)))]
# Filtruj dane, aby zawierały te przed daną datą
przed_dana_data = subset[pd.to_datetime(subset['date']) < pd.to_datetime(data)]
# Posortuj wg daty w odwrotnej kolejności
przed_dana_data = przed_dana_data.sort_values(by='date', ascending=False)
# Wybierz 5 ostatnich przed daną datą
ostatnie_przed_data = przed_dana_data.head(5)
return ostatnie_przed_data
def getResult(score,teamHome):
x,y = score.split('-')
x = int(x)
y = int(y)
if (x > y and teamHome == True) or (x < y and teamHome == False):
return "win"
elif x == y:
return "draw"
else:
return "loss"
def calculatePoints(matches, team):
points = 0
for index, row in matches.iterrows():
if team == row['home_team']:
teamHome = True
else:
teamHome = False
x = getResult(row['result_full'], teamHome)
print(x)
if x == "win":
points = points + 3
elif x == "draw":
points = points + 1
return points
def calculateGoalDifference(matches, team):
goal_diff = 0
for index, row in matches.iterrows():
if team == row['home_team']:
teamHome = True
else:
teamHome = False
x,y = row['result_full'].split('-')
x = int(x)
y = int(y)
if teamHome:
goal_diff = goal_diff + (x-y)
else:
goal_diff = goal_diff + (y-x)
return goal_diff
def categorize_passes(pass_count):
if pass_count < 400:
return 0 #słabo
elif 400 <= pass_count <= 500:
return 1 #średnio
else:
return 2 #dużo
wynik = last5Matches('10/11', 'Stoke City', '2010-10-02', df)
#print(wynik.to_markdown())
print(wynik)
#wynik = last5Matches('10/11', 'Blackburn Rovers', '2010-10-02', df)
#print(wynik.to_markdown())
#print(wynik)
print(calculatePoints(wynik,'Stoke City'))
print(calculateGoalDifference(wynik, 'Stoke City'))
df = generateTrainingData(df)
print(df)

41
rules.py Normal file
View File

@ -0,0 +1,41 @@
import simpful
def kategoryzuj_strzaly(ilosc_strzalow):
FS = FuzzySystem()
TLV = AutoTriangle(3, terms=['mało', 'średnio', 'dużo'], universe_of_discourse=[0, 25])
FS.add_linguistic_variable("strzaly", TLV)
shots1 = TriangleFuzzySet(0, 0, 6, term='mało')
shots2 = TriangleFuzzySet(6, 12, 18, term='średnio')
shots3 = TriangleFuzzySet(12, 25, 25, term='dużo')
FS.add_linguistic_variable("bilans", LinguisticVariable([shots1, shots2, shots3], universe_of_discourse=[0, 25]))
FS.add_rules(["IF strzaly IS mało THEN bilans IS mało",
"IF strzaly IS średnio THEN bilans IS średnio",
"IF strzaly IS dużo THEN bilans IS dużo"])
FS.set_variable("strzaly", ilosc_strzalow)
bilans = FS.inference()
if bilans['bilans'] >= 12:
return 2
elif bilans['bilans'] <= 6:
return 0
else:
return 1
def kategorie_strzalow(druzyna, sezon, data, df):
ostatnie_spotkania = last5Matches(sezon, druzyna, data, df)
shots = []
for index, spotkanie in ostatnie_spotkania.iterrows():
if spotkanie['home_team'] == druzyna:
ilosc_strzalow = spotkanie['home_shots']
else:
ilosc_strzalow = spotkanie['away_shots']
kategoria = kategoryzuj_strzaly(ilosc_strzalow)
shots.append(kategoria)
ostatnie_spotkania['cat_shots'] = shots
return ostatnie_spotkania