Naprawa kategorycznych, Zmiana zapisywania/wczytywania xgboost
This commit is contained in:
parent
3749cf22b0
commit
db214d217e
@ -25,12 +25,12 @@ const Hero = () => {
|
|||||||
|
|
||||||
const handleOneOnOneChange = (event) => {
|
const handleOneOnOneChange = (event) => {
|
||||||
SetoneOnOne(event.target.checked);
|
SetoneOnOne(event.target.checked);
|
||||||
sentQuestion()
|
sentQuestion();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAfterAirDuelChange = (event) => {
|
const handleAfterAirDuelChange = (event) => {
|
||||||
SetafterAirDuele(event.target.checked);
|
SetafterAirDuele(event.target.checked);
|
||||||
sentQuestion()
|
sentQuestion();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOpenGoalChange = (event) => {
|
const handleOpenGoalChange = (event) => {
|
||||||
@ -301,7 +301,7 @@ const handleRedirectChange = (event) => {
|
|||||||
///Dziwny Blad
|
///Dziwny Blad
|
||||||
loadPlayers()
|
loadPlayers()
|
||||||
if (number_of_shooters_rev.current == 1) {
|
if (number_of_shooters_rev.current == 1) {
|
||||||
console.log('Wysyłanie wartości: ', bodyPart, technique, actionType, shooterPossition, gameMinute, firstShot);
|
//console.log('Wysyłanie wartości: ', bodyPart, technique, actionType, shooterPossition, gameMinute, firstShot);
|
||||||
// Użyj backticksów zamiast zwykłych cudzysłowów
|
// Użyj backticksów zamiast zwykłych cudzysłowów
|
||||||
fetch(`http://127.0.0.1:5000/get_model?shooter=${shooter}&goalkeeper=${goalkeeper}&defenders=${defenders}&strickers=${stricers}&bodyPart=${bodyPart}&technique=${technique}&actionType=${actionType}&shooterPossition=${shooterPossition}&gameMinute=${gameMinute}&shot_first_time=${firstShot}&shot_one_on_one=${oneOnOne}&shot_aerial_won=${afterAirDuel}&shot_open_goal=${openGoal}&shot_follows_dribble=${afterDribbling}&shot_redirect=${redirect}`).then(
|
fetch(`http://127.0.0.1:5000/get_model?shooter=${shooter}&goalkeeper=${goalkeeper}&defenders=${defenders}&strickers=${stricers}&bodyPart=${bodyPart}&technique=${technique}&actionType=${actionType}&shooterPossition=${shooterPossition}&gameMinute=${gameMinute}&shot_first_time=${firstShot}&shot_one_on_one=${oneOnOne}&shot_aerial_won=${afterAirDuel}&shot_open_goal=${openGoal}&shot_follows_dribble=${afterDribbling}&shot_redirect=${redirect}`).then(
|
||||||
res => res.json()
|
res => res.json()
|
||||||
|
BIN
app/src/flask-server/labelEncoder.joblib
Normal file
BIN
app/src/flask-server/labelEncoder.joblib
Normal file
Binary file not shown.
BIN
app/src/flask-server/modele/__pycache__/modele.cpython-312.pyc
Normal file
BIN
app/src/flask-server/modele/__pycache__/modele.cpython-312.pyc
Normal file
Binary file not shown.
@ -3,6 +3,8 @@ import pandas as pd
|
|||||||
from math import sqrt
|
from math import sqrt
|
||||||
import math
|
import math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import xgboost
|
||||||
|
from sklearn.preprocessing import OrdinalEncoder
|
||||||
|
|
||||||
# Funkcja zwraca prawdopodobieństwo zdobycia gola
|
# Funkcja zwraca prawdopodobieństwo zdobycia gola
|
||||||
def LogisticRegression_predict_proba(position_x, position_y, distance_to_goalM, angle, match_minute, Number_Intervening_Opponents, Number_Intervening_Teammates, isFoot, isHead):
|
def LogisticRegression_predict_proba(position_x, position_y, distance_to_goalM, angle, match_minute, Number_Intervening_Opponents, Number_Intervening_Teammates, isFoot, isHead):
|
||||||
@ -35,8 +37,12 @@ def xgboost_predict_proba(minute=0, position_name='Center Forward', shot_body_pa
|
|||||||
y_player_teammate_7=np.nan, y_player_teammate_8=np.nan, y_player_teammate_9=np.nan,
|
y_player_teammate_7=np.nan, y_player_teammate_8=np.nan, y_player_teammate_9=np.nan,
|
||||||
y_player_teammate_10=np.nan, x_player_opponent_7=np.nan, y_player_opponent_7=np.nan,
|
y_player_teammate_10=np.nan, x_player_opponent_7=np.nan, y_player_opponent_7=np.nan,
|
||||||
x_player_teammate_Goalkeeper=np.nan, y_player_teammate_Goalkeeper=np.nan):
|
x_player_teammate_Goalkeeper=np.nan, y_player_teammate_Goalkeeper=np.nan):
|
||||||
|
|
||||||
model = load('xgboost.joblib')
|
model = xgboost.XGBClassifier()
|
||||||
|
model.load_model('xgboost.json')
|
||||||
|
|
||||||
|
enc = OrdinalEncoder()
|
||||||
|
enc = load('labelEncoder.joblib')
|
||||||
|
|
||||||
X_new = pd.DataFrame(columns=['minute', 'position_name', 'shot_body_part_name', 'shot_technique_name',
|
X_new = pd.DataFrame(columns=['minute', 'position_name', 'shot_body_part_name', 'shot_technique_name',
|
||||||
'shot_type_name', 'shot_first_time', 'shot_one_on_one',
|
'shot_type_name', 'shot_first_time', 'shot_one_on_one',
|
||||||
@ -83,21 +89,40 @@ def xgboost_predict_proba(minute=0, position_name='Center Forward', shot_body_pa
|
|||||||
y_player_teammate_7, y_player_teammate_8, y_player_teammate_9,
|
y_player_teammate_7, y_player_teammate_8, y_player_teammate_9,
|
||||||
y_player_teammate_10, x_player_opponent_7, y_player_opponent_7,
|
y_player_teammate_10, x_player_opponent_7, y_player_opponent_7,
|
||||||
x_player_teammate_Goalkeeper, y_player_teammate_Goalkeeper]
|
x_player_teammate_Goalkeeper, y_player_teammate_Goalkeeper]
|
||||||
|
|
||||||
X_new[['position_name',
|
X_new[['position_name',
|
||||||
|
'shot_technique_name',
|
||||||
|
'shot_type_name',
|
||||||
|
'shot_body_part_name']] = enc.transform(X_new[['position_name', 'shot_technique_name', 'shot_type_name', 'shot_body_part_name']], )
|
||||||
|
|
||||||
|
X_new[['minute',
|
||||||
|
'position_name',
|
||||||
'shot_technique_name',
|
'shot_technique_name',
|
||||||
'shot_type_name',
|
'shot_type_name',
|
||||||
'number_of_players_opponents',
|
'number_of_players_opponents',
|
||||||
'number_of_players_teammates',
|
'number_of_players_teammates',
|
||||||
'shot_body_part_name']] = X_new[['position_name',
|
'shot_body_part_name']] = X_new[['minute',
|
||||||
|
'position_name',
|
||||||
'shot_technique_name',
|
'shot_technique_name',
|
||||||
'shot_type_name',
|
'shot_type_name',
|
||||||
'number_of_players_opponents',
|
'number_of_players_opponents',
|
||||||
'number_of_players_teammates',
|
'number_of_players_teammates',
|
||||||
'shot_body_part_name']].astype('category')
|
'shot_body_part_name']].astype(int)
|
||||||
|
|
||||||
X_new['minute'] = X_new['minute'].astype(int)
|
|
||||||
|
|
||||||
|
# X_new[['minute',
|
||||||
|
# 'position_name',
|
||||||
|
# 'shot_technique_name',
|
||||||
|
# 'shot_type_name',
|
||||||
|
# 'number_of_players_opponents',
|
||||||
|
# 'number_of_players_teammates',
|
||||||
|
# 'shot_body_part_name']] = X_new[['minute',
|
||||||
|
# 'position_name',
|
||||||
|
# 'shot_technique_name',
|
||||||
|
# 'shot_type_name',
|
||||||
|
# 'number_of_players_opponents',
|
||||||
|
# 'number_of_players_teammates',
|
||||||
|
# 'shot_body_part_name']].astype('category')
|
||||||
|
|
||||||
X_new[['shot_first_time',
|
X_new[['shot_first_time',
|
||||||
'shot_one_on_one',
|
'shot_one_on_one',
|
||||||
'shot_aerial_won',
|
'shot_aerial_won',
|
||||||
@ -108,8 +133,11 @@ def xgboost_predict_proba(minute=0, position_name='Center Forward', shot_body_pa
|
|||||||
'shot_aerial_won',
|
'shot_aerial_won',
|
||||||
'shot_open_goal',
|
'shot_open_goal',
|
||||||
'shot_follows_dribble',
|
'shot_follows_dribble',
|
||||||
'shot_redirect']].astype(bool)
|
'shot_redirect']].astype(int)
|
||||||
|
print(X_new)
|
||||||
|
print(X_new.dtypes)
|
||||||
|
|
||||||
|
|
||||||
return model.predict_proba(X_new)[0][1].round(3)
|
return model.predict_proba(X_new)[0][1].round(3)
|
||||||
|
|
||||||
#XgBoost_2
|
#XgBoost_2
|
||||||
|
@ -91,7 +91,7 @@ def get_model():
|
|||||||
atakujacy_macierz = zmienWMaciez(atakujacy_lista)
|
atakujacy_macierz = zmienWMaciez(atakujacy_lista)
|
||||||
|
|
||||||
if gameMinute == "":
|
if gameMinute == "":
|
||||||
gameMinute = 1 # to change
|
gameMinute = 1.0 # to change
|
||||||
|
|
||||||
print("wspolrzedne obroncow: ", obroncy)
|
print("wspolrzedne obroncow: ", obroncy)
|
||||||
print("wspolrzedne atakujacych: ", atakujacy)
|
print("wspolrzedne atakujacych: ", atakujacy)
|
||||||
@ -124,11 +124,15 @@ def get_model():
|
|||||||
posortowani_atakujacy = sort_coordinates_by_distance(atakujacy_macierz, [shooter_x, shooter_y])
|
posortowani_atakujacy = sort_coordinates_by_distance(atakujacy_macierz, [shooter_x, shooter_y])
|
||||||
|
|
||||||
print("Posortowani obroncy: ", posortowani_obroncy)
|
print("Posortowani obroncy: ", posortowani_obroncy)
|
||||||
print("Posortowani atakujacy: ", posortowani_atakujacy)
|
|
||||||
|
|
||||||
number_of_players_opponents = np.sum(~np.isnan(posortowani_obroncy).all(axis=1))
|
|
||||||
number_of_players_teammates = np.sum(~np.isnan(posortowani_atakujacy).all(axis=1))
|
|
||||||
|
|
||||||
|
print("Posortowani atakujacy: ", posortowani_atakujacy)
|
||||||
|
|
||||||
|
|
||||||
|
number_of_players_opponents = float(np.sum(~np.isnan(posortowani_obroncy).all(axis=1)))
|
||||||
|
number_of_players_teammates = float(np.sum(~np.isnan(posortowani_atakujacy).all(axis=1)))
|
||||||
|
|
||||||
|
print("Liczba obroncow:", number_of_players_opponents)
|
||||||
|
print("Liczba atakujacych:", number_of_players_teammates)
|
||||||
## add angle, match minutes and number of players
|
## add angle, match minutes and number of players
|
||||||
|
|
||||||
def loc2angle(x, y):
|
def loc2angle(x, y):
|
||||||
@ -155,8 +159,42 @@ def get_model():
|
|||||||
|
|
||||||
print("bramkarz:", goalkepper_x, goalkepper_y)
|
print("bramkarz:", goalkepper_x, goalkepper_y)
|
||||||
|
|
||||||
|
if shot_first_time == 'true':
|
||||||
|
shot_first_time = True
|
||||||
|
else:
|
||||||
|
shot_first_time = False
|
||||||
|
if shot_one_on_one == 'true':
|
||||||
|
shot_one_on_one = True
|
||||||
|
else:
|
||||||
|
shot_one_on_one = False
|
||||||
|
if shot_aerial_won == 'true':
|
||||||
|
shot_aerial_won = True
|
||||||
|
else:
|
||||||
|
shot_aerial_won = False
|
||||||
|
if shot_open_goal == 'true':
|
||||||
|
shot_open_goal = True
|
||||||
|
else:
|
||||||
|
shot_open_goal = False
|
||||||
|
if shot_follows_dribble == 'true':
|
||||||
|
shot_follows_dribble = True
|
||||||
|
else:
|
||||||
|
shot_follows_dribble = False
|
||||||
|
if shot_redirect == 'true':
|
||||||
|
shot_redirect = True
|
||||||
|
else:
|
||||||
|
shot_redirect = False
|
||||||
|
|
||||||
|
#### CHECKLIST
|
||||||
|
print('CHECKLISTA')
|
||||||
|
print('shot_first_time', shot_first_time)
|
||||||
|
print('shot_one_on_one', shot_one_on_one)
|
||||||
|
print('shot_aerial_won', shot_aerial_won)
|
||||||
|
print('shot_open_goal', shot_open_goal)
|
||||||
|
print('shot_follows_dribble', shot_follows_dribble)
|
||||||
|
print('shot_redirect', shot_redirect)
|
||||||
|
|
||||||
# MODEL XGBOOST
|
# MODEL XGBOOST
|
||||||
response = xgboost_predict_proba(minute=gameMinute,
|
response = xgboost_predict_proba(minute=int(gameMinute), #minute=0,
|
||||||
position_name=position_name,
|
position_name=position_name,
|
||||||
shot_body_part_name=body_part,
|
shot_body_part_name=body_part,
|
||||||
shot_technique_name=technique,
|
shot_technique_name=technique,
|
||||||
|
1
app/src/flask-server/xgboost.json
Normal file
1
app/src/flask-server/xgboost.json
Normal file
File diff suppressed because one or more lines are too long
BIN
notebooks/labelEncoder.joblib
Normal file
BIN
notebooks/labelEncoder.joblib
Normal file
Binary file not shown.
1
notebooks/xgboost.json
Normal file
1
notebooks/xgboost.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user