Kaggle competition: Kobe Bryant Shot Selection
val_preds = model.predict(dval )<compute_test_metric>
data=pd.read_csv('.. /input/data.csv' )
roc_auc_score(y_val, val_preds )<compute_test_metric>
object_vars=[var for var in data if data[var].dtype=='object']
numerical_vars=[var for var in data if data[var].dtype=='float' or data[var].dtype=='int']
for var in object_vars:
print(data[var].value_counts() )
log_loss(y_val, val_preds )<predict_on_test>
data=data.drop(['team_id','team_name'],axis=1)
%%time
val_shap_preds = model.predict(dval, pred_contribs=True )<predict_on_test>
data['home']=data['matchup'].apply(lambda x: 1 if 'vs' in x else 0)
 data=data.drop('matchup',axis=1 )
%%time
test_shap_preds = model.predict(dtest, pred_contribs=True)
<predict_on_test>
data=data.drop(['lon','lat'],axis=1 )
%%time
train_shap_preds = model.predict(dtrain, pred_contribs=True )<predict_on_test>
data['time_remaining_seconds']=data['minutes_remaining']*60+data['seconds_remaining']
data=data.drop(['minutes_remaining','seconds_remaining'],axis=1 )
test_preds = model.predict(dtest )<save_to_csv>
data['time_remaining_seconds']
data['last_3_seconds']=data.time_remaining_seconds.apply(lambda x: 1 if x<4 else 0 )
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()<import_modules>
data=data.drop('shot_id',axis=1 )
import numpy as np
import pandas as pd
import zipfile
from sklearn.model_selection import train_test_split, KFold
from sklearn.metrics import log_loss, roc_auc_score
from sklearn.experimental import enable_hist_gradient_boosting
from sklearn.ensemble import HistGradientBoostingClassifier
import os 
<load_from_csv>
data['game_date']=pd.to_datetime(data['game_date'])
 data['game_month']=data['game_date'].dt.month
data=data.drop('game_date',axis=1 )
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()<define_variables>
data=data.drop(['game_id','game_event_id'],axis=1 )
TRAIN_FOLDER = '.. /input/cats-and-dogs-embedded-data/train/train/'
TEST_FOLDER = '.. /input/cats-and-dogs-embedded-data/test/test/'
IMG_SIZE = 224<load_pretrained>
categorical_vars=['action_type','combined_shot_type','season','opponent','shot_type','period','shot_zone_basic','shot_zone_area','shot_zone_range','game_month']
for var in categorical_vars:
data=pd.concat([data,pd.get_dummies(data[var],prefix=var)], 1)
 data=data.drop(var,1 )
train_image_list = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/train_image_list.npy')
 test_image_list = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/test_image_list.npy' )<define_variables>
train=data[pd.notnull(data['shot_made_flag'])]
test=data[pd.isnull(data['shot_made_flag'])]
y_train=train['shot_made_flag']
train=train.drop('shot_made_flag',1)
 y_train=y_train.astype('int')
 test=test.drop('shot_made_flag',1 )
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]<load_pretrained>
def log_scorer(estimator, X, y):
pred_probs = estimator.predict_proba(X)[:, 1]
return log_loss(y, pred_probs )
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )<load_pretrained>
model=RandomForestClassifier(n_estimators=400,max_depth=5)
 model.fit(train, y_train)
 pred=model.predict_proba(train)[:,1]
log_loss(y_train,pred)
 target_y = model.predict_proba(test)[:,1]
train_InceptionResNetV2 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/train_InceptionResNetV2.npy')
 test_InceptionResNetV2 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/test_InceptionResNetV2.npy' )<split>
log_loss(y_train,pred)
X_train, X_val, y_train, y_val = train_test_split(train_InceptionResNetV2, target, test_size=0.1, random_state=42 )<train_model>
cv=cross_val_score(model,train,y_train,scoring=log_scorer,cv=5)
 cv
<predict_on_test><EOS> 
sub = pd.read_csv(".. /input/sample_submission.csv")
 sub['shot_made_flag'] = target_y
sub.to_csv("submission.csv", index=False )