In [1]:
# read the data into a DataFrame
import pandas as pd
url = 'https://raw.githubusercontent.com/kjones8812/DAT4-students/master/kerry/Final/NBA_players_2015.csv'
nba = pd.read_csv(url, index_col=0)
nba.head()
Out[1]:
In [2]:
# examine the columns
In [3]:
# examine the positions
In [4]:
# map positions to numbers
In [5]:
# create feature matrix (X) (use fields: 'ast', 'stl', 'blk', 'tov', 'pf')
In [6]:
# create response vector (y)
In [7]:
# import class
In [8]:
# instantiate with K=5
In [9]:
# fit with data
In [10]:
# create a list to represent a player
In [11]:
# make a prediction
In [12]:
# calculate predicted probabilities
In [13]:
# repeat for K=50
In [14]:
# calculate predicted probabilities
In [15]:
# allow plots to appear in the notebook
%matplotlib inline
import matplotlib.pyplot as plt
# increase default figure and font sizes for easier viewing
plt.rcParams['figure.figsize'] = (6, 4)
plt.rcParams['font.size'] = 14