modyfikacja XG boosta

This commit is contained in:
unknown 2024-01-07 20:17:06 +01:00
parent edde8cf6be
commit ebedecbd4d
4 changed files with 125 additions and 46 deletions

View File

@ -20,7 +20,7 @@ const Hero = () => {
let number_of_defenders = 0;
let number_of_strikers = 0;
let number_of_goalkeepers = 0;
let numer_od_shooters = 0;
var numer_od_shooters = 0;
var eX = " ";
@ -122,7 +122,10 @@ const Hero = () => {
var possitionList = document.getElementById('possitionList')
var shootTypeList = document.getElementById('shootTypeList')
bodyPart = bodyPartList.value
bodyPart = bodyPartList.getAttribute('value')
alert(bodyPart)
actionType = actionTypeList.value
shooterPossition = possitionList.value
technique = shootTypeList.value
@ -261,7 +264,7 @@ const Hero = () => {
function sentQuestion() {
loadPlayers()
alert(bodyPart)
if (numer_od_shooters > 0) {
// Użyj backticksów zamiast zwykłych cudzysłowów

View File

@ -12,8 +12,7 @@ def LogisticRegression_predict_proba(position_x, position_y, distance_to_goalM,
X_new.loc[len(X_new.index)] = [position_x, position_y, distance_to_goalM, angle, match_minute, Number_Intervening_Opponents, Number_Intervening_Teammates, isFoot, isHead]
return model.predict_proba(X_new)[0][1].round(2)
#kolejne modele
#xgBoost
def xgboost_predict_proba(minute, position_name, shot_body_part_name, shot_technique_name,
shot_type_name, shot_first_time, shot_one_on_one,
shot_aerial_won, shot_deflected, shot_open_goal,
@ -88,5 +87,65 @@ def xgboost_predict_proba(minute, position_name, shot_body_part_name, shot_techn
shot_kick_off]
return model.predict_proba(X_new)[0][1].round(2)
#XgBoost_2
def xgboost_predict_proba_v2(minute, position_name, shot_body_part_name, shot_technique_name,
shot_type_name, shot_first_time, shot_one_on_one,
shot_aerial_won, shot_deflected, shot_open_goal,
shot_follows_dribble, shot_redirect, x1, y1,
number_of_players_opponents, number_of_players_teammates,
angle, distance):
model = load('xgboost.joblib')
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_aerial_won', 'shot_deflected', 'shot_open_goal',
'shot_follows_dribble', 'shot_redirect', 'x1', 'y1',
'number_of_players_opponents', 'number_of_players_teammates',
'angle', 'distance', 'x_player_opponent_Goalkeeper',
'x_player_opponent_8', 'x_player_opponent_1', 'x_player_opponent_2',
'x_player_opponent_3', 'x_player_teammate_1', 'x_player_opponent_4',
'x_player_opponent_5', 'x_player_opponent_6', 'x_player_teammate_2',
'x_player_opponent_9', 'x_player_opponent_10', 'x_player_opponent_11',
'x_player_teammate_3', 'x_player_teammate_4', 'x_player_teammate_5',
'x_player_teammate_6', 'x_player_teammate_7', 'x_player_teammate_8',
'x_player_teammate_9', 'x_player_teammate_10',
'y_player_opponent_Goalkeeper', 'y_player_opponent_8',
'y_player_opponent_1', 'y_player_opponent_2', 'y_player_opponent_3',
'y_player_teammate_1', 'y_player_opponent_4', 'y_player_opponent_5',
'y_player_opponent_6', 'y_player_teammate_2', 'y_player_opponent_9',
'y_player_opponent_10', 'y_player_opponent_11', 'y_player_teammate_3',
'y_player_teammate_4', 'y_player_teammate_5', 'y_player_teammate_6',
'y_player_teammate_7', 'y_player_teammate_8', 'y_player_teammate_9',
'y_player_teammate_10', 'x_player_opponent_7', 'y_player_opponent_7',
'x_player_teammate_Goalkeeper', 'y_player_teammate_Goalkeeper',
'shot_kick_off'])
X_new.loc[len(X_new.index)] = [minute, position_name, shot_body_part_name, shot_technique_name,
shot_type_name, shot_first_time, shot_one_on_one,
shot_aerial_won, shot_deflected, shot_open_goal,
shot_follows_dribble, shot_redirect, x1, y1,
number_of_players_opponents, number_of_players_teammates,
angle, distance, x_player_opponent_Goalkeeper,
x_player_opponent_8, x_player_opponent_1, x_player_opponent_2,
x_player_opponent_3, x_player_teammate_1, x_player_opponent_4,
x_player_opponent_5, x_player_opponent_6, x_player_teammate_2,
x_player_opponent_9, x_player_opponent_10, x_player_opponent_11,
x_player_teammate_3, x_player_teammate_4, x_player_teammate_5,
x_player_teammate_6, x_player_teammate_7, x_player_teammate_8,
x_player_teammate_9, x_player_teammate_10,
y_player_opponent_Goalkeeper, y_player_opponent_8,
y_player_opponent_1, y_player_opponent_2, y_player_opponent_3,
y_player_teammate_1, y_player_opponent_4, y_player_opponent_5,
y_player_opponent_6, y_player_teammate_2, y_player_opponent_9,
y_player_opponent_10, y_player_opponent_11, y_player_teammate_3,
y_player_teammate_4, y_player_teammate_5, y_player_teammate_6,
y_player_teammate_7, y_player_teammate_8, y_player_teammate_9,
y_player_teammate_10, x_player_opponent_7, y_player_opponent_7,
x_player_teammate_Goalkeeper, y_player_teammate_Goalkeeper,
shot_kick_off]
return model.predict_proba(X_new)[0][1].round(2)

View File

@ -1,6 +1,6 @@
from flask import Flask, request, jsonify
from flask_cors import CORS
from modele.modele import LogisticRegression_predict_proba, xgboost_predict_proba
from modele.modele import LogisticRegression_predict_proba, xgboost_predict_proba, xgboost_predict_proba_v2
import math
app = Flask(__name__)
@ -31,51 +31,66 @@ def konwertujDoListy(listaString):
# @app.route("/LRegresion<x>&<y>")
@app.route("/get_model", methods = ['GET'])
# def get_model():
def get_model():
# # x = int(x[0:2])
# # y = int(y[0:2])
# x = request.args.get('x', type=float)
# y = request.args.get('y', type=float)
# ## change model on xgboost
# ## add angle, match minutes and number of players
# Pozycja strzelca
shooter = request.args.get('shooter')
shooter = konwertujDoListy(shooter)
# angle = loc2angle(x = x, y = y)
# dist = loc2distance(x = x, y = y)
print("wprowadzone dane:")
print("x strzelca: " + str(shooter[0]))
print("y strzelca: " + str(shooter[1]))
# if y is None and x is None:
# return jsonify({"error": "Brak wymaganych parametrów"}), 400
if shooter[0] is None and shooter[1] is None:
return jsonify({"error": "Brak wymaganych parametrów"}), 400
# Kąt oraz dystans od bramki
angle = loc2angle(x = shooter[0], y = shooter[1])
dist = loc2distance(x = shooter[0], y = shooter[1])
# response = xgboost_predict_proba(minute = 20, position_name, shot_body_part_name, shot_technique_name,
# shot_type_name, shot_first_time, shot_one_on_one,
# shot_aerial_won, shot_deflected, shot_open_goal,
# shot_follows_dribble, shot_redirect, x1 = x, y1 = y,
# number_of_players_opponents, number_of_players_teammates,
# angle = angle, distance = dist, x_player_opponent_Goalkeeper,
# x_player_opponent_8, x_player_opponent_1, x_player_opponent_2,
# x_player_opponent_3, x_player_teammate_1, x_player_opponent_4,
# x_player_opponent_5, x_player_opponent_6, x_player_teammate_2,
# x_player_opponent_9, x_player_opponent_10, x_player_opponent_11,
# x_player_teammate_3, x_player_teammate_4, x_player_teammate_5,
# x_player_teammate_6, x_player_teammate_7, x_player_teammate_8,
# x_player_teammate_9, x_player_teammate_10,
# y_player_opponent_Goalkeeper, y_player_opponent_8,
# y_player_opponent_1, y_player_opponent_2, y_player_opponent_3,
# y_player_teammate_1, y_player_opponent_4, y_player_opponent_5,
# y_player_opponent_6, y_player_teammate_2, y_player_opponent_9,
# y_player_opponent_10, y_player_opponent_11, y_player_teammate_3,
# y_player_teammate_4, y_player_teammate_5, y_player_teammate_6,
# y_player_teammate_7, y_player_teammate_8, y_player_teammate_9,
# y_player_teammate_10, x_player_opponent_7, y_player_opponent_7,
# x_player_teammate_Goalkeeper, y_player_teammate_Goalkeeper,
# shot_kick_off)
# #print(x)
# #print(y)
# #print(response)
# res = str(response)
# #return {"response":res}
# return jsonify({"response":res})
print("kąt: " + str(angle))
print("dystans: " + str(dist) )
# Elementy z list: czesc ciała,rodzaj uderzenia,pozycja strzelca oraz typ akcji
position_name = request.args.get('shooter')
body_part = request.args.get('bodyPart')
technique = request.args.get('technique')
acionType = request.args.get('actionType')
print("pozycja strzelca: " + position_name)
print("czesc ciala: " + body_part)
print("technika: " + technique)
print("typ akcji: " + acionType)
# lista wspolzawodnikow oraz przeciwnikow
teamMatesList = request.args.get('defenders')
opponentsList = request.args.get('strickers')
teamMatesList = konwertujDoListy(teamMatesList)
opponentsList = konwertujDoListy(opponentsList)
print("wspolrzedne obroncow: " + teamMatesList)
print("wspolrzedne przeciwnikow: " + opponentsList)
# Bramkarz
goalkepper = request.args.get('goalkeeper')
goalkepper = konwertujDoListy(goalkepper)
print("bramkarz: " + str(goalkepper) )
response = xgboost_predict_proba_v2(minute = 20, position_name = position_name, shot_body_part_name = body_part, shot_technique_name = technique,
shot_type_name = acionType, shot_first_time = False,
shot_aerial_won = False, shot_deflected = False, shot_open_goal = False,
shot_follows_dribble = False, shot_redirect = False, shooter = shooter,
opponentsList = opponentsList, teamMatesList = teamMatesList,
angle = angle, distance = dist)
#print(response)
res = str(response)
#return {"response":res}
return jsonify({"response":res})
""""
def get_model():
# x = int(x[0:2])
@ -111,5 +126,7 @@ def get_model():
#return {"response":res}
return jsonify({"response":res})
# uruchomienie serwera
"""
if __name__ == "__main__":
app.run(debug = True)