Spaces:
Runtime error
Runtime error
Commit
•
c042fe2
1
Parent(s):
8ef9a22
Upload 4 files
Browse files- app.py +45 -0
- bb-player-salary-prediction.ipynb +1 -0
- model.sav +0 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pickle
|
3 |
+
import sklearn
|
4 |
+
import pandas as pd
|
5 |
+
import numpy as np
|
6 |
+
from PIL import Image
|
7 |
+
model = pickle.load(open('model.sav', 'rb'))
|
8 |
+
|
9 |
+
st.title('Player Salary Prediction')
|
10 |
+
st.sidebar.header('Player Data')
|
11 |
+
image = Image.open('bb.jpg')
|
12 |
+
st.image(image, '')
|
13 |
+
|
14 |
+
# FUNCTION
|
15 |
+
def user_report():
|
16 |
+
rating = st.sidebar.slider('Rating', 50,100, 1 )
|
17 |
+
jersey = st.sidebar.slider('Jersey', 0,100, 1 )
|
18 |
+
team = st.sidebar.slider('Team', 0,30, 1 )
|
19 |
+
position = st.sidebar.slider('Position', 0,10, 1 )
|
20 |
+
country = st.sidebar.slider('Country', 0,3, 1 )
|
21 |
+
draft_year = st.sidebar.slider('Draft Year', 2000,2020, 2000)
|
22 |
+
draft_round = st.sidebar.slider('Draft Round', 1,10, 1)
|
23 |
+
draft_peak = st.sidebar.slider('Draft Peak', 1,30, 1)
|
24 |
+
|
25 |
+
|
26 |
+
user_report_data = {
|
27 |
+
'rating':rating,
|
28 |
+
'jersey':jersey,
|
29 |
+
'team':team,
|
30 |
+
'position':position,
|
31 |
+
'country':country,
|
32 |
+
'draft_year':draft_year,
|
33 |
+
'draft_round':draft_round,
|
34 |
+
'draft_peak':draft_peak
|
35 |
+
}
|
36 |
+
report_data = pd.DataFrame(user_report_data, index=[0])
|
37 |
+
return report_data
|
38 |
+
|
39 |
+
user_data = user_report()
|
40 |
+
st.header('Player Data')
|
41 |
+
st.write(user_data)
|
42 |
+
|
43 |
+
salary = model.predict(user_data)
|
44 |
+
st.subheader('Player Salary')
|
45 |
+
st.subheader('$'+str(np.round(salary[0], 2)))
|
bb-player-salary-prediction.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nplt.style.use('dark_background')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('../input/nba2k20-player-dataset/nba2k20-full.csv')\ndf.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.dropna()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum().sum()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.drop(['full_name', 'b_day', 'height', 'weight', 'college'], axis = 1)\ndf.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def removehash(value):\n value = value[1:]\n return int(value)\n\ndf['jersey'] = df['jersey'].apply(removehash)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['salary'] = df['salary'].apply(removehash)\ndf.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['team'].value_counts()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['country'].value_counts()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def removecountryoutlier(value):\n if value not in ['USA', 'Canada', 'Australia']:\n return 'Others'\n else:\n return value\n\ndf['country'] = df['country'].apply(removecountryoutlier)\ndf['country'].value_counts()\n ","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['position'].value_counts()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['draft_round'].unique","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['draft_peak'].unique","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def removeundrafted(value):\n if value=='Undrafted':\n return \n else:\n return value\n \ndf['draft_round'] = df['draft_round'].apply(removeundrafted)\ndf['draft_peak'] = df['draft_peak'].apply(removeundrafted)\n\ndf = df.dropna()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nle = LabelEncoder()\ndf['position'] = le.fit_transform(df['position'])\ndf['country'] = le.fit_transform(df['country'])\ndf['team'] = le.fit_transform(df['team'])\n\ndf.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = df.drop(['salary'], axis = 1)\ny = df['salary']","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression\nlr = LinearRegression()\nlr.fit(x_train, y_train)\npredictions = lr.predict(x_test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"diff = y_test - predictions","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nsns.distplot(diff)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pickle\npickle.dump(lr, open('./model.sav', 'wb'))","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}
|
model.sav
ADDED
Binary file (664 Bytes). View file
|
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
numpy==1.21.5
|
2 |
+
pandas==1.4.4
|
3 |
+
Pillow==9.3.0
|
4 |
+
scikit_learn==1.2.0
|
5 |
+
streamlit==1.16.0
|