ibrahimnomad's picture
Update app.py
9b21761 verified
raw
history blame contribute delete
No virus
2.46 kB
import streamlit as st
import pickle
import numpy as np
# Load the saved SVC model
with open('svc_model.pkl', 'rb') as file:
svc_model = pickle.load(file)
# Define a function to make predictions
def predict_shot_accuracy(inputs):
# Reshape inputs for the model
inputs = np.array(inputs).reshape(1, -1)
# Predict probability of the shot being a basket
probability = svc_model.predict_proba(inputs)
return probability[0][1] # Probability of the positive class (making the basket)
# Streamlit app
st.title('Kobe Shot Accuracy Predictor 🏀')
st.image("https://img.bleacherreport.net/img/images/photos/003/159/114/hi-res-179796f005257238c44afad0c64e1432_crop_north.jpg?1416296596&w=3072&h=2048")
st.write('The model is trained with LinearSVC on 25K shots of Kobe Bryant.')
# Input fields for user to fill in shot details
shot_distance = st.number_input('Shot Distance in feet', min_value=0, max_value=30, value=24)
# Dropdown for combined shot type
combined_shot_type = st.selectbox('Combined Shot Type', [
'Bank Shot', 'Dunk', 'Hook Shot', 'Jump Shot', 'Layup', 'Tip Shot'
], index=3) # Default to 'Jump Shot'
# Convert the combined shot type to binary features
combined_shot_type_features = {
'Bank Shot': [True, False, False, False, False, False],
'Dunk': [False, True, False, False, False, False],
'Hook Shot': [False, False, True, False, False, False],
'Jump Shot': [False, False, False, True, False, False],
'Layup': [False, False, False, False, True, False],
'Tip Shot': [False, False, False, False, False, True]
}[combined_shot_type]
# Dropdown for shot type
shot_type = st.selectbox('Shot Type', ['2PT Field Goal', '3PT Field Goal'], index=1) # Default to '3PT Field Goal'
# Convert shot type to binary features
shot_type_2PT_Field_Goal = shot_type == '2PT Field Goal'
shot_type_3PT_Field_Goal = shot_type == '3PT Field Goal'
# Prepare the input data
input_data = [
shot_distance,
*combined_shot_type_features,
shot_type_2PT_Field_Goal,
shot_type_3PT_Field_Goal
]
# Make prediction when user submits
if st.button('Predict Shot Accuracy'):
probability = predict_shot_accuracy(input_data)
st.write(f'The probability of making the basket is {probability:.2f}%.')
# Display a title for the images
st.write("Here are some bonus data visualizations about Kobe's Shots ⛹🏾")
# Display images
for i in range(1, 11):
st.image(f'{i}.png')