Jovian
⭐️
Sign In
In [2]:
import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt

Read the file

In [3]:
data = pd.read_csv('../project-kobe/data.csv')
In [4]:
data.head()
Out[4]:
In [5]:
#Classify shot_made_flag as a null value as a test set
test=data[data['shot_made_flag'].isnull()]
test.shape
test
Out[5]:
In [6]:
#categorize Shot_made_flag as a test set
train=data[data['shot_made_flag'].notnull()]
train.shape
train
Out[6]:
In [7]:
# check for missing data
nan = pd.concat([train.isnull().sum(), test.isnull().sum()], axis=1, keys=['Train', 'Test'])
nan[nan.sum(axis=1) > 0]
Out[7]:
In [8]:
# how many of each data type there are in our data set
train.get_dtype_counts()
Out[8]:
float64     3
int64      11
object     11
dtype: int64
In [10]:
# cheak effeicency of each shot type using mean
train[['combined_shot_type', 'shot_made_flag']].groupby(['combined_shot_type'], 
        as_index=False).mean().sort_values(by='shot_made_flag', ascending=False)
Out[10]:
In [7]:
#action_type  VS shot_made_flag
train[['action_type', 'shot_made_flag']].groupby(['action_type'], 
      as_index=False).mean().sort_values(by='shot_made_flag', ascending=False)
train.head()
Out[7]:
In [10]:
# average per season
train[['season', 'shot_made_flag']].groupby(['season'], 
       as_index=False).mean().sort_values(by='shot_made_flag', ascending=False)
Out[10]:
In [14]:
#measure values without missing data
shot_made_flag = data['shot_made_flag']
no_missing_values = data[pd.notnull(shot_made_flag)]
In [15]:
no_missing_values.filter(items=['shot_id', 'shot_made_flag']).head()
Out[15]:
In [21]:
plt.figure(figsize=(10,10))

# Plot using following data fields loc_x und loc_y 
plt.subplot(121)
plt.scatter(no_missing_values.loc_x, no_missing_values.loc_y, color='red', alpha=0.01)
plt.title('loc_x and loc_y')

# Plotten der lon und lat Koordinaten von gemessenen Würfen
plt.subplot(122)
plt.scatter(no_missing_values.lon, no_missing_values.lat, color='green', alpha=0.01)
plt.title('lat and lon')


Out[21]:
Text(0.5, 1.0, 'lat and lon')
Notebook Image
In [ ]: