Kaggle competition: Kobe Bryant Shot Selection
<SOS> metric: logloss Kaggle data source: kobe-bryant-shot-selection<compute_test_metric>
%matplotlib inline
py.init_notebook_mode(connected=True)
 warnings.filterwarnings('ignore' )
log_loss(y_val, val_preds )<predict_on_test>
dfBase = pd.read_csv('.. /input/kobe-bryant-shot-selection/data.csv')
 dfBase.dataframeName = 'kobe-bryant-shot-selection.csv'
test_preds = lr.predict_proba(test_EB3)[:,1]<save_to_csv>
print(f'Dataset de treino tem {dfBase.shape[0]} linhas por {dfBase.shape[1]} colunas({dfBase.shape[0] * dfBase.shape[1]} celulas)' )
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()<import_modules>
dfPreprocess = dfBase.copy()
dfPreprocess['dist'] = np.sqrt(dfPreprocess['loc_x']**2 + dfPreprocess['loc_y']**2)
 loc_x_zero = dfPreprocess['loc_x'] == 0
dfPreprocess['angle'] = np.array([0]*len(dfPreprocess))
dfPreprocess['angle'][~loc_x_zero] = np.arctan(dfPreprocess['loc_y'][~loc_x_zero] / dfPreprocess['loc_x'][~loc_x_zero])
 dfPreprocess['angle'][loc_x_zero] = np.pi / 2
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.linear_model import LogisticRegression
import os 
<load_from_csv>
dfPreprocess['remaining_time'] = dfPreprocess['minutes_remaining'] * 60 + dfPreprocess['seconds_remaining']
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()<define_variables>
dfPreprocess['match_elapsed_time'] =(dfPreprocess['period'] * 720)+(720 - dfPreprocess['remaining_time'] )
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>
dfPreprocess = dfPreprocess.drop(axis=1, columns=[
'shot_zone_range',
'shot_zone_area',
'shot_distance',
'lat',
'lon',
'loc_x',
'loc_y',
'shot_zone_basic',
'shot_type',
'team_name',
'team_id',
'matchup',
'game_event_id',
'game_id',
'season',
'game_date',
'seconds_remaining',
'minutes_remaining',
'period',
])
 dfPreprocess.set_index('shot_id', inplace=True )
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>
dfPreprocess = dfPreprocess[['dist','angle', 'action_type', 'combined_shot_type', 'playoffs', 'match_elapsed_time', 'remaining_time', 'opponent', 'shot_made_flag']]
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]<load_pretrained>
dfPreprocess.columns = [
'dist',
'angle',
'action_type_cat',
'combined_shot_type_cat',
'playoffs_cat',
'match_elapsed_time',
'remaining_time',
'opponent_cat',
'target'
]
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )<load_pretrained>
print(f'Antes - Preprocess tem {dfPreprocess.shape[0]} linhas por {dfPreprocess.shape[1]} colunas({dfPreprocess.shape[0] * dfPreprocess.shape[1]} celulas)')
 dfPreprocess.drop_duplicates()
print(f'Depois - Preprocess tem {dfPreprocess.shape[0]} linhas por {dfPreprocess.shape[1]} colunas({dfPreprocess.shape[0] * dfPreprocess.shape[1]} celulas)' )
train_EB6 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_3/cats_and_dogs_3/train_EB6.npy')
 test_EB6 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_3/cats_and_dogs_3/test_EB6.npy' )<split>
def generateMetadata(dfInput):
data = []
for f in dfInput.columns:
if f == 'target':
role = 'target'
elif f == 'id':
role = 'id'
else:
role = 'input'
if f == 'target':
level = 'binary'
elif 'cat' in f or f == 'id':
level = 'nominal'
elif dfInput[f].dtype == float or dfInput[f].dtype == np.float64:
level = 'interval'
elif dfInput[f].dtype == int or dfInput[f].dtype == np.int64:
level = 'ordinal'
keep = True
if f == 'id':
keep = False
dtype = dfInput[f].dtype
f_dict = {
'varname': f,
'role': role,
'level': level,
'keep': keep,
'dtype': dtype
}
data.append(f_dict)
 meta = pd.DataFrame(data, columns=['varname', 'role', 'level', 'keep', 'dtype'])
 meta.set_index('varname', inplace=True)
 return meta
X_train, X_val, y_train, y_val = train_test_split(train_EB6, target, test_size=0.1, random_state=42 )<train_model>
meta_preprocess = generateMetadata(dfPreprocess )
%%time
lr = LogisticRegression(C=0.02, max_iter=10000)
 lr.fit(X_train, y_train )<predict_on_test>
print('Metadados categoricos da base pré processada')
 print(meta_preprocess[(meta_preprocess.level == 'nominal')&(meta_preprocess.keep)].index )
val_preds = lr.predict_proba(X_val)[:,1]<compute_test_metric>
print('Tipos e quantidade de features do dataset')
 display(pd.DataFrame({'count' : meta_preprocess.groupby(['role', 'level'])['role'].size() } ).reset_index() )
roc_auc_score(y_val, val_preds )<compute_test_metric>
def getMissingAttributes(dfInput):
atributos_missing = []
return_missing = []
for f in dfInput.columns:
missings = dfInput[f].isna().sum()
if missings > 0:
atributos_missing.append(f)
 missings_perc = missings/dfInput.shape[0]
return_missing.append([f, missings, missings_perc])
 print('Atributo {} tem {} amostras({:.2%})com valores faltantes'.format(f, missings, missings_perc))
print('No total, há {} atributos com valores faltantes'.format(len(atributos_missing)))
 return pd.DataFrame(return_missing ).rename(index=str, columns={0: "column_name", 1: "column_nulls", 2: "column_percentage"} )
log_loss(y_val, val_preds )<predict_on_test>
missing = getMissingAttributes(dfPreprocess[meta_preprocess[(meta_preprocess.role != 'target')].index])
 display(missing )
test_preds = lr.predict_proba(test_EB6)[:,1]<save_to_csv>
remove_threshold = 0.425
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()<import_modules>
if(len(missing)> 0):
columns_to_remove = np.array(missing.column_name[(missing.column_percentage >= remove_threshold)])
 else:
columns_to_remove = None
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.linear_model import LogisticRegression
import os 
<load_from_csv>
if(columns_to_remove != None):
dfTreino = dfPreprocess.drop(columns_to_remove, axis=1)
 meta_preprocess.loc[(columns_to_remove),'keep'] = False
missing.drop(missing[(np.isin(missing.column_name, columns_to_remove)) ].index )
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()<define_variables>
def fillNullNumbers(dfInput, dfMetadata, dfMissing, missing_default, label):
media_imp = SimpleImputer(missing_values=missing_default, strategy='mean')
 moda_imp = SimpleImputer(missing_values=missing_default, strategy='most_frequent')
 for index,row in dfMissing.iterrows() :
columnName = row['column_name']
columnType = dfMetadata.level[(dfMetadata.index == columnName)][0]
if(columnType == 'interval'):
imputerToUse = media_imp
imputerString = 'media_imp'
elif(columnType == 'ordinal'):
imputerToUse = moda_imp
imputerString = 'moda_imp'
else:
imputerToUse = None
imputerString = None
if(imputerToUse != None):
dfInput[columnName] = imputerToUse.fit_transform(dfInput[[columnName]] ).ravel()
print(f"{label} - Preenchida coluna {columnName}, cujo tipo é {columnType}, usando o Imputer {imputerString}")
 return dfInput
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>
dfPreprocess = fillNullNumbers(dfPreprocess, meta_preprocess, missing, -1, 'Pré Processado' )
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>
def performOneHotEncoding(dfInput, meta_generic, dist_limit):
v = meta_generic[(meta_generic.level == 'nominal')&(meta_generic.keep)].index
display(v)
 for f in v:
dist_values = dfInput[f].value_counts().shape[0]
print('Atributo {} tem {} valores distintos'.format(f, dist_values))
if(dist_values > dist_limit):
print('Atributo {} tem mais de {} valores distintos e por isso será ignorado'.format(f, dist_limit))
dfInput.drop([f], axis=1)
 v = v.drop([f])
 print('Antes do one-hot encoding tinha-se {} atributos'.format(dfInput.shape[1]))
dfInput = pd.get_dummies(dfInput, columns=v, drop_first=True)
 print('Depois do one-hot encoding tem-se {} atributos'.format(dfInput.shape[1]))
return dfInput
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]<load_pretrained>
dfPreprocess = performOneHotEncoding(dfPreprocess, meta_preprocess, 200 )
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )<load_pretrained>
min_max_scaler = MinMaxScaler()
dfPreprocess[dfPreprocess.columns] = min_max_scaler.fit_transform(dfPreprocess[dfPreprocess.columns] )
train_EB2 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_3/cats_and_dogs_3/train_EB2.npy')
 test_EB2 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_3/cats_and_dogs_3/test_EB2.npy' )<split>
from xgboost import XGBClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV, cross_val_score, ShuffleSplit, KFold, train_test_split, StratifiedKFold
from sklearn.metrics import recall_score
from sklearn.metrics import accuracy_score
from sklearn.metrics import log_loss
from sklearn.metrics import confusion_matrix
from sklearn.metrics import precision_score
from sklearn.metrics import f1_score
X_train, X_val, y_train, y_val = train_test_split(train_EB2, target, test_size=0.1, random_state=42 )<train_model>
def showDistribution(val_classes, targetName):
nonUsed, used = pd.DataFrame(val_classes ).groupby(targetName ).size()
print('---')
 print(f'Das {pd.DataFrame(val_classes ).shape[0]} entradas no dataset, {nonUsed} foram de lances não convertidos e {used} foram de lances convertidos.')
 print(f'Temos assim {round(( used/len(val_classes)) * 100,6)}% de lances que foram convertidos em pontos.')
 print('---' )
%%time
lr = LogisticRegression(C=0.015, max_iter=10000)
 lr.fit(X_train, y_train )<predict_on_test>
def logisticRegression(X_Train, y_Train, X_Val, y_Val):
model = LogisticRegression(solver='lbfgs')
 model.fit(X_Train, y_Train)
 y_pred_class = model.predict(X_Val)
 y_pred_proba = model.predict_proba(X_Val)
 recall = recall_score(y_Val, y_pred_class)
 accuracy = accuracy_score(y_Val, y_pred_class)
 logloss = log_loss(y_Val, y_pred_proba)
 precision = precision_score(y_Val, y_pred_class)
 f1 = f1_score(y_Val, y_pred_class)
 print(f'Baseline - Regressão Logistica')
 print('---')
 print(f'Acurácia: {round(accuracy, 6)}%')
 print(f'Recall: {round(recall, 6)}%')
 print(f'Precisão: {round(precision, 6)}%')
 print(f'Log Loss: {round(logloss, 6)}')
 print(f'F1 Score: {round(f1, 6)}')
 print('---')
 print('Matriz de Confusão')
 display(pd.DataFrame(confusion_matrix(y_Val, y_pred_class)))
 print('---')
 return model, 'Baseline - Regressão Logistica'
val_preds = lr.predict_proba(X_val)[:,1]<compute_test_metric>
def xGBClassifier(X_Train, y_Train, X_Val, y_Val, modelName, modelParams):
if(modelParams == None):
clf = XGBClassifier()
else:
clf = XGBClassifier(**modelParams)
 modelName = modelName + ' - Parameters: ' + str(modelParams)
 clf.fit(X_Train, y_Train)
 y_pred_class = clf.predict(X_Val)
 y_pred_proba = clf.predict_proba(X_Val)
 recall = recall_score(y_Val, y_pred_class)
 accuracy = accuracy_score(y_Val, y_pred_class)
 logloss = log_loss(y_Val, y_pred_proba)
 precision = precision_score(y_Val, y_pred_class)
 f1 = f1_score(y_Val, y_pred_class)
 print(modelName)
 print('---')
 print(f'Acurácia: {round(accuracy, 6)}%')
 print(f'Recall: {round(recall, 6)}%')
 print(f'Precisão: {round(precision, 6)}%')
 print(f'Log Loss: {round(logloss, 6)}')
 print(f'F1 Score: {round(f1, 6)}')
 print('---')
 print('Matriz de Confusão')
 display(pd.DataFrame(confusion_matrix(y_Val, y_pred_class)))
 print('---')
 return clf, modelName
roc_auc_score(y_val, val_preds )<compute_test_metric>
def xGB_KFold(X, y, kfoldAmount, modelName, modelParams):
if(modelParams == None):
clf = XGBClassifier()
else:
clf = XGBClassifier(**modelParams)
 modelName = modelName + ' - Parameters: ' + str(modelParams)
 clf_score = []
iterator = 1
for train_index, test_index in KFold(shuffle=True, n_splits=kfoldAmount, random_state=42 ).split(X):
X_train, X_test = X.iloc[train_index], X.iloc[test_index]
y_train, y_test = y.iloc[train_index], y.iloc[test_index]
print(f'Processando Fold {iterator}/{kfoldAmount}')
 clf.fit(X_train, y_train)
 y_pred_class = clf.predict(X_test)
 y_pred_proba = clf.predict_proba(X_test)
 recall = recall_score(y_test, y_pred_class)
 accuracy = accuracy_score(y_test, y_pred_class)
 logloss = log_loss(y_test, y_pred_proba)
 precision = precision_score(y_test, y_pred_class)
 f1 = f1_score(y_test, y_pred_class)
 print(f'Fold {iterator}/{kfoldAmount} - Resultados')
 print('---')
 print(f'Acurácia: {round(accuracy, 6)}%')
 print(f'Recall: {round(recall, 6)}%')
 print(f'Precisão: {round(precision, 6)}%')
 print(f'Log Loss: {round(logloss, 6)}')
 print(f'F1 Score: {round(f1, 6)}')
 print('---')
 print('Matriz de Confusão')
 display(pd.DataFrame(confusion_matrix(y_test, y_pred_class)))
 print('---')
 clf_score.append(logloss)
 iterator += 1
print('Score Médio = ', round(np.array(clf_score ).mean() , 6))
return clf, modelName
log_loss(y_val, val_preds )<predict_on_test>
def decisionTreeClassifier(X_Train, y_Train, X_Val, y_Val):
clf = DecisionTreeClassifier()
clf.fit(X_Train, y_Train)
 y_pred_class = clf.predict(X_Val)
 y_pred_proba = clf.predict_proba(X_Val)
 recall = recall_score(y_Val, y_pred_class)
 accuracy = accuracy_score(y_Val, y_pred_class)
 logloss = log_loss(y_Val, y_pred_proba)
 precision = precision_score(y_Val, y_pred_class)
 f1 = f1_score(y_Val, y_pred_class)
 print(f'Decision Tree - Default Parameters')
 print('---')
 print(f'Acurácia: {round(accuracy, 6)}%')
 print(f'Recall: {round(recall, 6)}%')
 print(f'Precisão: {round(precision, 6)}%')
 print(f'Log Loss: {round(logloss, 6)}')
 print(f'F1 Score: {round(f1, 6)}')
 print('---')
 print('Matriz de Confusão')
 display(pd.DataFrame(confusion_matrix(y_Val, y_pred_class)))
 print('---')
 return clf, f'Decision Tree - Default Parameters'
test_preds = lr.predict_proba(test_EB2)[:,1]<save_to_csv>
def gridSearchKNN(X_Train, y_Train, X_Val, y_Val, k_range):
clf=KNeighborsClassifier()
param_grid=dict(n_neighbors=k_range)
 scores = ['neg_log_loss']
for sc in scores:
grid=GridSearchCV(clf,param_grid,cv=2,scoring=sc,n_jobs=-1)
 print("K-Nearest Neighbors - Tuning hyper-parameters for %s" % sc)
 grid.fit(X_Train,y_Train)
 print(grid.best_params_)
 print(np.round(grid.best_score_,3))
y_pred_class = grid.predict(X_Val)
 y_pred_proba = grid.predict_proba(X_Val)
 recall = recall_score(y_Val, y_pred_class)
 accuracy = accuracy_score(y_Val, y_pred_class)
 logloss = log_loss(y_Val, y_pred_proba)
 precision = precision_score(y_Val, y_pred_class)
 f1 = f1_score(y_Val, y_pred_class)
 print(f'KNN with recall-maxing hyperparameters - {grid.best_params_}')
 print('---')
 print(f'Acurácia: {round(accuracy, 6)}%')
 print(f'Recall: {round(recall, 6)}%')
 print(f'Precisão: {round(precision, 6)}%')
 print(f'Log Loss: {round(logloss, 6)}')
 print(f'F1 Score: {round(f1, 6)}')
 print('---')
 print('Matriz de Confusão')
 display(pd.DataFrame(confusion_matrix(y_Val, y_pred_class)))
 print('---')
 return grid, f'KNN with recall-maxing hyperparameters - {grid.best_params_}'
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()<install_modules>
def gridSearchSVC(X_Train, y_Train, X_Val, y_Val):
svc=SVC()
param_grid = [{'kernel': ['rbf'], 'gamma': [1e-3, 1e-4, 1e-5],'C': [1, 10, 100, 1000]},
{'kernel': ['linear'], 'C': [1, 10, 100, 1000]}]
scores = ['neg_log_loss']
for sc in scores:
grid=GridSearchCV(svc,param_grid,cv=4,scoring=sc,n_jobs=-1)
 print("Support Vector Classifier - Tuning hyper-parameters for %s" % sc)
 grid.fit(X_Train,y_Train)
 print(grid.best_params_)
 print(np.round(grid.best_score_,3))
y_pred_class = grid.predict(X_Val)
 recall = recall_score(y_Val, y_pred_class)
 accuracy = accuracy_score(y_Val, y_pred_class)
 precision = precision_score(y_Val, y_pred_class)
 f1 = f1_score(y_Val, y_pred_class)
 print(f'SVC with recall-maxing hyperparameters - {grid.best_params_}')
 print('---')
 print(f'Acurácia: {round(accuracy, 6)}%')
 print(f'Recall: {round(recall, 6)}%')
 print(f'Precisão: {round(precision, 6)}%')
 print(f'F1 Score: {round(f1, 6)}')
 print('---')
 print('Matriz de Confusão')
 display(pd.DataFrame(confusion_matrix(y_Val, y_pred_class)))
 print('---')
 return grid, f'SVC with recall-maxing hyperparameters - {grid.best_params_}'
!pip install --use-feature=2020-resolver https://s3-us-west-2.amazonaws.com/xgboost-nightly-builds/xgboost-1.3.0_SNAPSHOT%2B00b0ad1293b4fa74d6aca5da4e9ab7a9d16777f0-py3-none-manylinux2010_x86_64.whl<import_modules>
def predictTestDataset(X_Test, y_Test, clfModel, clfName):
y_pred_class = clfModel.predict(X_Test)
 y_pred_proba = clfModel.predict_proba(X_Test)
 recall = recall_score(y_Test, y_pred_class)
 accuracy = accuracy_score(y_Test, y_pred_class)
 logloss = log_loss(y_Test, y_pred_proba)
 precision = precision_score(y_Test, y_pred_class)
 f1 = f1_score(y_Test, y_pred_class)
 print(clfName)
 print('---')
 print(f'Acurácia: {round(accuracy, 6)}%')
 print(f'Recall: {round(recall, 6)}%')
 print(f'Precisão: {round(precision, 6)}%')
 print(f'Log Loss: {round(logloss, 6)}')
 print(f'F1 Score: {round(f1, 6)}')
 print('---')
 print('Matriz de Confusão')
 display(pd.DataFrame(confusion_matrix(y_Test, y_pred_class)))
 print('---' )
xgb.__version__<import_modules>
def predictContestDataset(X_Test, clfModel, clfName):
print(clfName)
 print('---')
 y_pred_class = clfModel.predict(X_Test)
 y_pred_proba = clfModel.predict_proba(X_Test)
 pd_prediction = pd.DataFrame(y_pred_class)
 pd_prediction.columns = ['target']
showDistribution(pd_prediction, 'target')
 return y_pred_class, y_pred_proba
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
import gc
import os 
<load_from_csv>
def performSubSampling(sample_size_target, sample_size_non_target, dfInput, targetValue):
target_indices = dfInput[dfInput.target == targetValue].index
target_values = dfInput.loc[np.random.choice(activated_indices, sample_size, replace=False)]
non_target_indices = dfInput[dfInput.target != targetValue].index
non_target_values = dfInput.loc[np.random.choice(inactive_indices, sample_size_non_target, replace=False)]
subsampled = pd.concat([target_values, non_target_values])
 subsampled.sort_index(inplace=True)
 return subsampled
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()<define_variables>
dfPredict = dfPreprocess[dfPreprocess['target'].isnull() ]
dfPreprocess = dfPreprocess.dropna()
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>
X = dfPreprocess.drop(['target'], axis=1)
 y = dfPreprocess['target']
y.columns = ['target']
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>
X_predict = dfPredict.drop(['target'], axis=1 )
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]<load_pretrained>
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.30, random_state=42, stratify=y )
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )<load_pretrained>
logRegModel, logRegName = logisticRegression(X_train, y_train, X_val, y_val )
train_NAS_large = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_2/train_NAS_large.npy')
 test_NAS_large = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_2/test_NAS_large.npy' )<split>
xgbPureModel, xgbPureName = xGBClassifier(X_train, y_train, X_val, y_val, 'XGBoost - Base', None)
 xgbPresetModel, xgbPresetName = xGBClassifier(X_train, y_train, X_val, y_val, 'XGBoost - Preset', {'n_estimator':400, 'learning_rate' : 0.5,'random_state' : 0,'max_depth':70,'objective':"binary:logistic",'subsample':.8,'min_child_weig':6,'colsample_bytr':.8,'scale_pos_weight':1.6, 'gamma':10, 'reg_alph':8, 'reg_lambda':1})
 xgbHyperParametrizedModel, xgbHyperParametrizedName = xGBClassifier(X_train, y_train, X_val, y_val, 'XGBoost - Grid Search Outputted',{'colsample_bytree': 0.6, 'gamma': 9, 'learning_rate': 0.01, 'max_depth': 7, 'n_estimators': 500, 'subsample': 0.6, 'random_state': 42})
 decTreeModel, decTreeName = decisionTreeClassifier(X_train, y_train, X_val, y_val )
X_train, X_val, y_train, y_val = train_test_split(train_NAS_large, target, test_size=0.1, random_state=42 )<train_model>
xgb_params = {
'eta': 0.05,
'max_depth': 4,
'subsample': 0.8,
'colsample_bytree': 0.7,
'objective': 'reg:logistic',
'eval_metric': 'auc',
'verbosity': 0,
'tree_method': 'hist',
'predictor': 'cpu_predictor'
}
dtrain = xgb.DMatrix(X_train, y_train)
 dval = xgb.DMatrix(X_val, y_val)
 dtest = xgb.DMatrix(test_NAS_large )<drop_column>
showDistribution(y, 'target')
 xgbGSModel, xgbGSName = xGB_KFold(X, y, 10, 'XGBoost - KFolded',
{'colsample_bytree': 0.6,
'gamma': 9,
'learning_rate': 0.01,
'max_depth': 7,
'n_estimators': 500,
'subsample': 0.6,
'random_state': 42
} )
del train_NAS_large, test_NAS_large, X_train, X_val
gc.collect()<train_model>
contest_prediction, contest_prediction_probability = predictContestDataset(X_predict, xgbGSModel, xgbGSName )
%%time
model = xgb.train(xgb_params, dtrain, num_boost_round=110 )<predict_on_test>
sample = pd.read_csv('.. /input/kobe-bryant-shot-selection/sample_submission.csv', low_memory=False)
 sample.shot_made_flag = contest_prediction_probability
sample.shot_made_flag = 1 - sample.shot_made_flag
sample.to_csv("submission.csv", float_format='%.6f', index=False )