-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
55 lines (50 loc) · 2.35 KB
/
Copy pathapp.py
File metadata and controls
55 lines (50 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import streamlit as st
from main import predict_match, club_name_to_id, le_hosting, le_result, model, \
recent_club_position, recent_opponent_position, club_win_rate, opponent_win_rate, \
accuracy_score, y_test, y_pred
translations = {
'English': {
'title': 'Football Predict Machine Learning',
'team': 'Select a team:',
'opponent': 'Select an opponent:',
'hosting': 'Is team 1 hosting or away?',
'accuracy': 'Model accuracy:',
'win': 'is predicted to Win!',
'loss': 'is predicted to Loss!',
'draw': 'is predicted to Draw!'
},
'Português': {
'title': 'Previsor de Futebol - Aprendizado de Maquina(Machine Learning)',
'team': 'Selecione um clube:',
'opponent': 'Selecione um oponente:',
'hosting': 'O primeiro clube esta em casa ou fora?',
'accuracy': 'Precisão do modelo:',
'win': 'esta previsto para Vencer!',
'loss': 'esta previsto para Perder!',
'draw': 'esta previsto para Empatar!'
}
}
hosting_options = ['home', 'away']
with st.container(border=True):
language = st.selectbox('Language/Idioma', options=['English', 'Português'])
tr = translations[language]
st.title(tr['title'])
input_team_one = st.selectbox(tr['team'], list(club_name_to_id.keys()), index=None)
input_opponent = st.selectbox(tr['opponent'], list(club_name_to_id.keys()), index=None)
hosting = st.selectbox(tr['hosting'], list(hosting_options), index=None)
if (input_team_one is not None and input_opponent is not None and hosting is not None):
hosting = hosting.strip().title()
club_id = club_name_to_id[input_team_one]
opponent_id = club_name_to_id[input_opponent]
hosting = hosting
accuracy = accuracy_score(y_test, y_pred)
accuracy = accuracy * 100
with st.container(border=True):
predicted_result = predict_match(club_id, opponent_id, hosting, recent_club_position, recent_opponent_position, club_win_rate, opponent_win_rate)
st.write(f'{tr['accuracy']} {accuracy:.2f}%')
if predicted_result == 'win':
st.success(f'{input_team_one} {tr['win']}')
elif predicted_result == 'loss':
st.error(f'{input_team_one} {tr['loss']}')
else:
st.warning(f'{input_team_one} {tr['draw']}')