|
import streamlit as st |
|
import pandas as pd |
|
import numpy as np |
|
import pickle |
|
import json |
|
|
|
|
|
with open('list_num_columns.txt', 'r') as file_1: |
|
list_num_cols = json.load(file_1) |
|
|
|
with open('list_cat_columns.txt', 'r') as file_2: |
|
list_cat_cols = json.load(file_2) |
|
|
|
with open('model_scaler.pkl', 'rb') as file_3: |
|
model_scaler = pickle.load(file_3) |
|
|
|
with open('model_encoder.pkl', 'rb') as file_4: |
|
model_encoder = pickle.load(file_4) |
|
|
|
with open('model_lin_reg.pkl', 'rb') as file_5: |
|
model_lin_reg = pickle.load(file_5) |
|
|
|
def run(): |
|
with st.form(key='Form Parameter'): |
|
name = st.text_input('Name', value='') |
|
age = st.number_input('Age', min_value=0, max_value=70, step=1) |
|
weight = st.number_input('Weight', min_value=0, max_value=150, step=1) |
|
height = st.slider('Height', 150, 225, 165) |
|
price = st.number_input('Price', min_value=0, max_value=1000000000, step=1000) |
|
st.markdown('---') |
|
AttackingWorkRate = st.selectbox('Attacking Work Rate', ('Low','Medium','High'),index=0) |
|
DefensiveWorkRate = st.selectbox('Defensive Work Rate', ('Low','Medium','High'),index=1) |
|
st.markdown('---') |
|
pace = st.number_input('Pace', min_value=0, max_value=100, step=1) |
|
shooting = st.number_input('Shooting Total', min_value=0, max_value=100, step=1) |
|
passing = st.number_input('Passing', min_value=0, max_value=100, step=1) |
|
dribbling = st.number_input('Dribbling', min_value=0, max_value=100, step=1) |
|
defending = st.number_input('Defending', min_value=0, max_value=100, step=1) |
|
physicality = st.number_input('Physicality', min_value=0, max_value=100, step=1) |
|
|
|
submitted = st.form_submit_button('Predict') |
|
|
|
data_inf = {'Name': name, |
|
'Age': age, |
|
'Height': height, |
|
'Weight': weight, |
|
'Price': price, |
|
'AttackRate':AttackingWorkRate, |
|
'DefenseRate': DefensiveWorkRate, |
|
'PaceTotal': pace, |
|
'ShootingTotal':shooting, |
|
'PassingTotal':passing , |
|
'DribblingTotal':dribbling, |
|
'DefendingTotal': defending, |
|
'PhysicalityTotal': physicality} |
|
|
|
df = pd.DataFrame([data_inf]) |
|
st.dataframe(df) |
|
|
|
|
|
if submitted: |
|
|
|
data_inf_num = df[list_num_cols] |
|
data_inf_cat = df[list_cat_cols] |
|
|
|
|
|
data_inf_num_scaled = model_scaler.transform(data_inf_num) |
|
data_inf_cat_encoded = model_encoder.transform(data_inf_cat) |
|
|
|
|
|
data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis=1) |
|
|
|
|
|
y_pred_inf = model_lin_reg.predict(data_inf_final) |
|
st.write('# Rating: ',str(np.round(y_pred_inf))[1:3]) |
|
|
|
if __name__ == '__main__': |
|
run() |