Clear old code

This commit is contained in:
Piotr Kopycki 2022-01-24 12:36:24 +01:00
parent 1390b7fe8c
commit af7877d81e
2 changed files with 55 additions and 236 deletions

236
main.py
View File

@ -5,242 +5,6 @@ import matplotlib.pyplot as plt
from read_data import get_leagues_data from read_data import get_leagues_data
import pandas as pd import pandas as pd
# https://pythonhosted.org/scikit-fuzzy/auto_examples/plot_tipping_problem.html
# Variables for universes
unv_clubs = unv_goals = unv_avgValue = unv_players = unv_teamsChL = unv_teamsEuL = unv_teamsCfL = unv_score = None
# Variables for fuzzy membership functions
clubs_few = clubs_some = clubs_several = clubs_many = None
goals_few = goals_moderate = goals_many = None
avgValue_vpoor = avgValue_poor = avgValue_mpoor = avgValue_moderate = avgValue_mrich = avgValue_rich = avgValue_vrich = None
players_none = players_few = players_moderate = players_many = None
teamsChL_min = teamsChL_mid = teamsChL_max = None
teamsEuL_min = teamsEuL_mid = teamsEuL_max = None
teamsCfL_min = teamsCfL_mid = teamsCfL_max = None
score_tragic = score_bad = score_moderate = score_good = score_best = None
# Activations of fuzzy membership functions
clubs_few_level = clubs_some_level = clubs_several_level = clubs_many_level = None
goals_few_level = goals_moderate_level = goals_many_level = None
avgValue_vpoor_level = avgValue_poor_level = avgValue_mpoor_level = avgValue_moderate_level = avgValue_mrich_level = avgValue_rich_level = avgValue_vrich_level = None
players_none_level = players_few_level = players_moderate_level = players_many_level = None
teamsChL_min_level = teamsChL_mid_level = teamsChL_max_level = None
teamsEuL_min_level = teamsEuL_mid_level = teamsEuL_max_level = None
teamsCfL_min_level = teamsCfL_mid_level = teamsCfL_max_level = None
def initFuzzyMembershipFunctions():
global unv_clubs, unv_goals, unv_avgValue, unv_players, unv_teamsChL, unv_teamsEuL, unv_teamsCfL, unv_score
global clubs_few, clubs_some, clubs_several, clubs_many
global goals_few, goals_moderate, goals_many
global avgValue_vpoor, avgValue_poor, avgValue_mpoor, avgValue_moderate, avgValue_mrich, avgValue_rich, avgValue_vrich
global players_none, players_few, players_moderate, players_many
global teamsChL_min, teamsChL_mid, teamsChL_max
global teamsEuL_min, teamsEuL_mid, teamsEuL_max
global teamsCfL_min, teamsCfL_mid, teamsCfL_max
global score_tragic, score_bad, score_moderate, score_good, score_best
# Universes for variables
unv_clubs = np.arange(2, 31, 1)
unv_goals = np.arange(0.99, 5.01, 0.01)
unv_avgValue = np.arange(0.01, 500.01, 0.01)
unv_players = np.arange(0, 101, 1)
unv_teamsChL = np.arange(0, 6, 1)
unv_teamsEuL = np.arange(0, 6, 1)
unv_teamsCfL = np.arange(0, 6, 1)
# Result score universum
unv_score = np.arange(0, 101, 1)
# Generate fuzzy membership functions
# trimf - triangular function
# trapmf - trapezoidal function
clubs_few = fuzz.trapmf(unv_clubs, [2, 2, 5, 8])
clubs_some = fuzz.trapmf(unv_clubs, [3, 6, 9, 12])
clubs_several = fuzz.trapmf(unv_clubs, [8, 11, 15, 18])
clubs_many = fuzz.trapmf(unv_clubs, [15, 18, 30, 30])
goals_few = fuzz.trapmf(unv_goals, [1.0, 1.0, 2.0, 3.0])
goals_moderate = fuzz.trimf(unv_goals, [2.5, 3.0, 3.5])
goals_many = fuzz.trapmf(unv_goals, [3.0, 3.5, 5.0, 5.0])
avgValue_vpoor = fuzz.trapmf(unv_avgValue, [0.01, 0.01, 1.0, 2.0])
avgValue_poor = fuzz.trimf(unv_avgValue, [1.0, 5.0, 15.0])
avgValue_mpoor = fuzz.trimf(unv_avgValue, [7.5, 20.0, 50.0])
avgValue_moderate = fuzz.trimf(unv_avgValue, [20.0, 50.0, 100.0])
avgValue_mrich = fuzz.trimf(unv_avgValue, [50.0, 100.0, 175.0])
avgValue_rich = fuzz.trimf(unv_avgValue, [150.0, 200.0, 275.0])
avgValue_vrich = fuzz.trapmf(unv_avgValue, [200.0, 300.0, 500.0, 500.0])
players_none = fuzz.trimf(unv_players, [0, 0, 1])
players_few = fuzz.trapmf(unv_players, [1, 5, 10, 15])
players_moderate = fuzz.trapmf(unv_players, [10, 15, 20, 25])
players_many = fuzz.trapmf(unv_players, [20, 25, 100, 100])
teamsChL_min = fuzz.trapmf(unv_teamsChL, [0, 0, 1, 2])
teamsChL_mid = fuzz.trapmf(unv_teamsChL, [1, 2, 3, 4])
teamsChL_max = fuzz.trapmf(unv_teamsChL, [3, 4, 5, 5])
teamsEuL_min = fuzz.trimf(unv_teamsEuL, [0, 0, 1])
teamsEuL_mid = fuzz.trimf(unv_teamsEuL, [0, 1, 2])
teamsEuL_max = fuzz.trapmf(unv_teamsEuL, [1, 2, 5, 5])
teamsCfL_min = fuzz.trapmf(unv_teamsCfL, [0, 0, 1, 2])
teamsCfL_mid = fuzz.trimf(unv_teamsCfL, [1, 2, 3])
teamsCfL_max = fuzz.trapmf(unv_teamsCfL, [2, 3, 5, 5])
score_tragic = fuzz.trapmf(unv_score, [0, 0, 15, 25])
score_bad = fuzz.trapmf(unv_score, [15, 25, 35, 45])
score_moderate = fuzz.trapmf(unv_score, [35, 45, 55, 65])
score_good = fuzz.trapmf(unv_score, [55, 65, 75, 85])
score_best = fuzz.trapmf(unv_score, [75, 85, 100, 100])
def activateFuzzyMembershipFunctions(values):
global unv_clubs, unv_goals, unv_avgValue, unv_players, unv_teamsChL, unv_teamsEuL, unv_teamsCfL
global clubs_few, clubs_some, clubs_several, clubs_many
global goals_few, goals_moderate, goals_many
global avgValue_vpoor, avgValue_poor, avgValue_mpoor, avgValue_moderate, avgValue_mrich, avgValue_rich, avgValue_vrich
global players_none, players_few, players_moderate, players_many
global teamsChL_min, teamsChL_mid, teamsChL_max
global teamsEuL_min, teamsEuL_mid, teamsEuL_max
global teamsCfL_min, teamsCfL_mid, teamsCfL_max
global clubs_few_level, clubs_some_level, clubs_several_level, clubs_many_level
global goals_few_level, goals_moderate_level, goals_many_level
global avgValue_vpoor_level, avgValue_poor_level, avgValue_mpoor_level, avgValue_moderate_level, avgValue_mrich_level, avgValue_rich_level, avgValue_vrich_level
global players_none_level, players_few_level, players_moderate_level, players_many_level
global teamsChL_min_level, teamsChL_mid_level, teamsChL_max_level
global teamsEuL_min_level, teamsEuL_mid_level, teamsEuL_max_level
global teamsCfL_min_level, teamsCfL_mid_level, teamsCfL_max_level
# Activation of fuzzy membership functions at given values.
clubs_few_level = fuzz.interp_membership(unv_clubs, clubs_few, values['clubs'])
clubs_some_level = fuzz.interp_membership(unv_clubs, clubs_some, values['clubs'])
clubs_several_level = fuzz.interp_membership(unv_clubs, clubs_several, values['clubs'])
clubs_many_level = fuzz.interp_membership(unv_clubs, clubs_many, values['clubs'])
goals_few_level = fuzz.interp_membership(unv_goals, goals_few, values['goalsPerMatch'])
goals_moderate_level = fuzz.interp_membership(unv_goals, goals_moderate, values['goalsPerMatch'])
goals_many_level = fuzz.interp_membership(unv_goals, goals_many, values['goalsPerMatch'])
avgValue_vpoor_level = fuzz.interp_membership(unv_avgValue, avgValue_vpoor, values['avgMarketValueInMln'])
avgValue_poor_level = fuzz.interp_membership(unv_avgValue, avgValue_poor, values['avgMarketValueInMln'])
avgValue_mpoor_level = fuzz.interp_membership(unv_avgValue, avgValue_mpoor, values['avgMarketValueInMln'])
avgValue_moderate_level = fuzz.interp_membership(unv_avgValue, avgValue_moderate, values['avgMarketValueInMln'])
avgValue_mrich_level = fuzz.interp_membership(unv_avgValue, avgValue_mrich, values['avgMarketValueInMln'])
avgValue_rich_level = fuzz.interp_membership(unv_avgValue, avgValue_rich, values['avgMarketValueInMln'])
avgValue_vrich_level = fuzz.interp_membership(unv_avgValue, avgValue_vrich, values['avgMarketValueInMln'])
players_none_level = fuzz.interp_membership(unv_players, players_none, values['famousPlayers'])
players_few_level = fuzz.interp_membership(unv_players, players_few, values['famousPlayers'])
players_moderate_level = fuzz.interp_membership(unv_players, players_moderate, values['famousPlayers'])
players_many_level = fuzz.interp_membership(unv_players, players_many, values['famousPlayers'])
teamsChL_min_level = fuzz.interp_membership(unv_teamsChL, teamsChL_min, values['teamsInChampionsLeague'])
teamsChL_mid_level = fuzz.interp_membership(unv_teamsChL, teamsChL_mid, values['teamsInChampionsLeague'])
teamsChL_max_level = fuzz.interp_membership(unv_teamsChL, teamsChL_max, values['teamsInChampionsLeague'])
teamsEuL_min_level = fuzz.interp_membership(unv_teamsEuL, teamsEuL_min, values['teamsInEuropaLeague'])
teamsEuL_mid_level = fuzz.interp_membership(unv_teamsEuL, teamsEuL_mid, values['teamsInEuropaLeague'])
teamsEuL_max_level = fuzz.interp_membership(unv_teamsEuL, teamsEuL_max, values['teamsInEuropaLeague'])
teamsCfL_min_level = fuzz.interp_membership(unv_teamsCfL, teamsCfL_min, values['teamsInConferenceLeague'])
teamsCfL_mid_level = fuzz.interp_membership(unv_teamsCfL, teamsCfL_mid, values['teamsInConferenceLeague'])
teamsCfL_max_level = fuzz.interp_membership(unv_teamsCfL, teamsCfL_max, values['teamsInConferenceLeague'])
def defineRules():
global clubs_few_level, clubs_some_level, clubs_several_level, clubs_many_level
global goals_few_level, goals_moderate_level, goals_many_level
global avgValue_vpoor_level, avgValue_poor_level, avgValue_mpoor_level, avgValue_moderate_level, avgValue_mrich_level, avgValue_rich_level, avgValue_vrich_level
global players_none_level, players_few_level, players_moderate_level, players_many_level
global teamsChL_min_level, teamsChL_mid_level, teamsChL_max_level
global teamsEuL_min_level, teamsEuL_mid_level, teamsEuL_max_level
global teamsCfL_min_level, teamsCfL_mid_level, teamsCfL_max_level
global score_tragic, score_bad, score_moderate, score_good, score_best, unv_score
# OR zmienić na AND (bo Or wybija wysokie wartości)
active_rule1 = np.fmax(clubs_some_level,
np.fmax(clubs_few_level,
np.fmax(goals_few_level,
np.fmax(avgValue_mpoor_level,
np.fmax(avgValue_poor_level,
np.fmax(avgValue_vpoor_level,
np.fmax(players_none_level,
np.fmax(teamsChL_min_level,
np.fmax(teamsEuL_min_level,
np.fmax(teamsCfL_max_level, teamsCfL_mid_level))))))))))
active_rule2 = np.fmax(clubs_several_level,
np.fmax(clubs_some_level,
np.fmax(clubs_few_level,
np.fmax(goals_moderate_level,
np.fmax(goals_few_level,
np.fmax(avgValue_moderate_level,
np.fmax(avgValue_mpoor_level,
np.fmax(avgValue_poor_level,
np.fmax(players_few_level,
np.fmax(players_none_level,
np.fmax(teamsChL_min_level,
np.fmax(teamsEuL_min_level,
np.fmax(teamsCfL_max_level, teamsCfL_mid_level)))))))))))))
active_rule3 = np.fmax(clubs_several_level,
np.fmax(clubs_some_level,
np.fmax(goals_moderate_level,
np.fmax(avgValue_mrich_level,
np.fmax(avgValue_moderate_level,
np.fmax(avgValue_mpoor_level,
np.fmax(players_moderate_level,
np.fmax(players_few_level,
np.fmax(teamsChL_mid_level,
np.fmax(teamsChL_min_level,
np.fmax(teamsEuL_mid_level,
np.fmax(teamsEuL_min_level,
np.fmax(teamsCfL_max_level, teamsCfL_mid_level)))))))))))))
active_rule4 = np.fmax(clubs_many_level,
np.fmax(clubs_several_level,
np.fmax(goals_many_level,
np.fmax(goals_moderate_level,
np.fmax(avgValue_vrich_level,
np.fmax(avgValue_rich_level,
np.fmax(avgValue_mrich_level,
np.fmax(players_many_level,
np.fmax(players_moderate_level,
np.fmax(teamsChL_mid_level,
np.fmax(teamsEuL_mid_level, teamsCfL_mid_level)))))))))))
active_rule5 = np.fmax(clubs_many_level,
np.fmax(goals_many_level,
np.fmax(avgValue_vrich_level,
np.fmax(players_many_level,
np.fmax(teamsChL_max_level,
np.fmax(teamsEuL_max_level, teamsCfL_min_level))))))
score_activation_tragic = np.fmin(active_rule1, score_tragic)
score_activation_bad = np.fmin(active_rule2, score_bad)
score_activation_moderate = np.fmin(active_rule3, score_moderate)
score_activation_good = np.fmin(active_rule4, score_good)
score_activation_best = np.fmin(active_rule5, score_best)
aggregated_rules = np.fmax(score_activation_tragic, np.fmax(score_activation_bad, np.fmax(score_activation_moderate, np.fmax(score_activation_good, score_activation_best))))
# active_rule1 = np.fmax(qual_level_lo, serv_level_lo)
# tip_activation_lo = np.fmin(active_rule1, tip_lo) # removed entirely to 0
#
#
# tip_activation_md = np.fmin(serv_level_md, tip_md)
#
# active_rule3 = np.fmax(qual_level_hi, serv_level_hi)
# tip_activation_hi = np.fmin(active_rule3, tip_hi)
#
# aggregated_rules = np.fmax(tip_activation_lo, np.fmax(tip_activation_md, tip_activation_hi))
score = fuzz.defuzz(unv_score, aggregated_rules, 'centroid')
score_activation = fuzz.interp_membership(unv_score, aggregated_rules, score) # for plot
return score_activation
class LeagueController: class LeagueController:
clubs = None clubs = None
goals = None goals = None

55
res2.csv Normal file
View File

@ -0,0 +1,55 @@
League,Score
Premier League,89.79166666666667
LaLiga,87.99305555555551
Serie A,69.99999999999997
Bundesliga,69.99999999999997
Ligue 1,70.0
Liga Bwin,50.0
Eredivisie,50.0
Bundesliga,50.0
Premiership,50.0
Premier Liga,50.0
Premier Liga,50.0
Super liga Srbije,16.06985926699488
Jupiler Pro League,50.0
Super League,16.720238095238116
Protathlima Cyta,37.46376811594203
1.HNL,19.502537932480898
Fortuna Liga,50.0
Super Lig,50.0
Super League 1,16.72023809523811
Superligaen,50.0
Eliteserien,18.708853030574293
Ligat ha'Al,18.452797318931577
Allsvenskan,16.373584957387074
efbet Liga,18.30879493889046
Premyer Liqa,16.513252197430706
Liga 1,16.563786394400363
Ekstraklasa,17.799929815326582
NB I.,16.607555033649284
Fortuna Liga,17.47128703953887
Premier Liga,17.017969510028376
Prva Liga,18.027979553403277
Vysheyshaya Liga,16.92098939265932
Divizia Nationala,17.47128703953887
A Lyga,16.945442256089507
Premijer Liga,18.93687055144107
Veikkausliiga,18.118481435127244
BGL Ligue,13.732949223788575
Virsliga,17.81954033134955
BKT Superliga e Kosovës,40.104166666666664
Premier Division,12.170932536120004
Premiership,14.77821484228063
Kategoria Superiore,17.47128703953886
Bardzragujn khumb,18.027979553403277
Betri-deildin,40.104166666666664
Premium Liiga,40.104166666666664
Premier League,17.576907528891994
Crystalbet Erovnuli Liga,17.384648906569666
Prva liga,16.993931364085164
Cymru Premier,10.990792282448856
Gibraltar National League,10.208333333333334
Pepsi Max deild,13.976944727639466
1. CFL,16.945442256089507
Primera Divisió,40.104166666666664
Camp. Sammarinese,40.104166666666664
1 League Score
2 Premier League 89.79166666666667
3 LaLiga 87.99305555555551
4 Serie A 69.99999999999997
5 Bundesliga 69.99999999999997
6 Ligue 1 70.0
7 Liga Bwin 50.0
8 Eredivisie 50.0
9 Bundesliga 50.0
10 Premiership 50.0
11 Premier Liga 50.0
12 Premier Liga 50.0
13 Super liga Srbije 16.06985926699488
14 Jupiler Pro League 50.0
15 Super League 16.720238095238116
16 Protathlima Cyta 37.46376811594203
17 1.HNL 19.502537932480898
18 Fortuna Liga 50.0
19 Super Lig 50.0
20 Super League 1 16.72023809523811
21 Superligaen 50.0
22 Eliteserien 18.708853030574293
23 Ligat ha'Al 18.452797318931577
24 Allsvenskan 16.373584957387074
25 efbet Liga 18.30879493889046
26 Premyer Liqa 16.513252197430706
27 Liga 1 16.563786394400363
28 Ekstraklasa 17.799929815326582
29 NB I. 16.607555033649284
30 Fortuna Liga 17.47128703953887
31 Premier Liga 17.017969510028376
32 Prva Liga 18.027979553403277
33 Vysheyshaya Liga 16.92098939265932
34 Divizia Nationala 17.47128703953887
35 A Lyga 16.945442256089507
36 Premijer Liga 18.93687055144107
37 Veikkausliiga 18.118481435127244
38 BGL Ligue 13.732949223788575
39 Virsliga 17.81954033134955
40 BKT Superliga e Kosovës 40.104166666666664
41 Premier Division 12.170932536120004
42 Premiership 14.77821484228063
43 Kategoria Superiore 17.47128703953886
44 Bardzragujn khumb 18.027979553403277
45 Betri-deildin 40.104166666666664
46 Premium Liiga 40.104166666666664
47 Premier League 17.576907528891994
48 Crystalbet Erovnuli Liga 17.384648906569666
49 Prva liga 16.993931364085164
50 Cymru Premier 10.990792282448856
51 Gibraltar National League 10.208333333333334
52 Pepsi Max deild 13.976944727639466
53 1. CFL 16.945442256089507
54 Primera Divisió 40.104166666666664
55 Camp. Sammarinese 40.104166666666664