2024-01-06 15:53:05 +01:00
|
|
|
import pandas as pd
|
|
|
|
from simpful import *
|
2024-01-06 20:36:34 +01:00
|
|
|
from rules import *
|
|
|
|
from data_filters import *
|
|
|
|
from sklearn.ensemble import RandomForestClassifier
|
|
|
|
from sklearn.model_selection import train_test_split
|
|
|
|
from sklearn.metrics import accuracy_score
|
|
|
|
from sklearn.preprocessing import LabelEncoder
|
|
|
|
from sklearn.metrics import classification_report
|
|
|
|
|
2024-01-06 15:53:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-01-06 20:36:34 +01:00
|
|
|
if __name__ == "__main__":
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-06 20:36:34 +01:00
|
|
|
df = pd.read_csv('df_full_premierleague.csv')
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-06 20:36:34 +01:00
|
|
|
result = last5Matches('10/11', 'Stoke City', '2010-10-02', df)
|
|
|
|
#print(result.to_markdown())
|
|
|
|
#print(result)
|
|
|
|
result = last5Matches('10/11', 'Blackburn Rovers', '2010-10-02', df)
|
|
|
|
#print(result.to_markdown())
|
|
|
|
#print(result)
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-06 20:36:34 +01:00
|
|
|
print(calculatePoints(result,'Blackburn Rovers'))
|
|
|
|
print(calculateGoalDifference(result, 'Blackburn Rovers'))
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-22 15:59:58 +01:00
|
|
|
# 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")
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-22 15:59:58 +01:00
|
|
|
# df = add_column(df, categorize_possesion, "c_away_possession", "away_possession")
|
|
|
|
# df = add_column(df, categorize_possesion, "c_home_possession", "home_possession")
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-22 15:59:58 +01:00
|
|
|
# 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)
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-22 15:59:58 +01:00
|
|
|
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")
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-22 15:59:58 +01:00
|
|
|
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_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")
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-06 20:36:34 +01:00
|
|
|
df = generateFuzzyLogicData(df)
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-06 20:36:34 +01:00
|
|
|
label_encoder = LabelEncoder()
|
|
|
|
df['season'] = label_encoder.fit_transform(df['season'])
|
|
|
|
df['c_home_result'] = get_result_list(df,True)
|
|
|
|
df['c_away_result'] = get_result_list(df,True)
|
|
|
|
temp = df[['home_team', 'away_team']].stack()
|
|
|
|
temp[:] = temp.factorize()[0]
|
|
|
|
df[['home_team', 'away_team']] = temp.unstack()
|
|
|
|
X = df.drop(['result_full', 'date', 'c_home_result', 'c_away_result'], axis=1)
|
|
|
|
y = df['c_home_result']
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-06 20:36:34 +01:00
|
|
|
model = RandomForestClassifier(n_estimators=100, random_state=42)
|
|
|
|
model.fit(X_train, y_train)
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-06 20:36:34 +01:00
|
|
|
y_pred = model.predict(X_test)
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-06 20:36:34 +01:00
|
|
|
accuracy = accuracy_score(y_test, y_pred)
|
|
|
|
print(f'Dokładność modelu: {accuracy}')
|
|
|
|
|
|
|
|
accuracy = accuracy_score(y_test, y_pred)
|
|
|
|
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'))
|
2024-01-06 15:53:05 +01:00
|
|
|
|
2024-01-21 21:50:20 +01:00
|
|
|
print(categorize_fuzzy_passes(450,50))
|