Kaggle competition: Santander Customer Transaction Prediction
results_xg.to_csv("xgboost_prediction.csv", index=False )<define_variables>
oof = pd.read_csv(".. /input/santander-outputs/Validation_Skfold.csv")['0']
oof_2 = pd.read_csv(".. /input/santander-outputs/Validation_kfold.csv")['0']
predictions = pd.read_csv(".. /input/santander-outputs/submission26_skfold.csv")["target"]
predictions_2 = pd.read_csv(".. /input/santander-outputs/submission26_kfold.csv")["target"]
path_to_train = '.. /input/train/train'
glob_train_imgs = os.path.join(path_to_train, '*.jpg')
 train_img_paths = glob(glob_train_imgs)
 print(train_img_paths[:10])
 path_to_test = '.. /input/test/test'
glob_test_imgs = os.path.join(path_to_test, '*.jpg')
 test_img_paths = glob(glob_test_imgs)
 print(test_img_paths[:10])
 def get_img_basename(img_path):
img_basename = os.path.basename(img_path)
 return img_basename
def get_img_id(img_path):
img_basename = os.path.basename(img_path)
 img_id = os.path.splitext(img_basename)[0]
return img_id
path = '.. /input/train/train/655c71d8c3f3d61f3797545e7d0414ce.jpg'
print(get_img_basename(path))<load_from_csv>
train = pd.read_csv('.. /input/santander-customer-transaction-prediction/train.csv')
 features = [c for c in train.columns if c not in ['ID_code', 'target']]
train = pd.read_csv('.. /input/train.csv')
 def get_class(img_path):
img_basename = get_img_basename(img_path)
 A = train[train['id'] == img_basename]
label = A['has_cactus'].values[0]
return label
def image_gen(img_paths, img_size=(32, 32)) :
for img_path in img_paths:
label = get_class(img_path)
 img = imread(img_path)
 img = resize(img, img_size, preserve_range=True)
 yield img, label 
<normalization>
target = train['target']
train = train.drop(["ID_code", "target"], axis=1 )
%matplotlib inline
def horizontal_augmentation(img):
aug = mx.image.HorizontalFlipAug(1)
 img = mx.nd.array(img)
 aug_img = aug(img)
 return aug_img.asnumpy()
def vertical_augmentation(img):
img = np.flipud(img)
 return img
def rotate_augmentation(img):
new_img = np.rot90(img)
 return new_img
def brightness_augmentation(img):
aug = mx.image.BrightnessJitterAug(brightness=.5)
 img = mx.nd.array(img)
 aug_img = aug(img)
 aug_img = aug_img.astype('int')
 return aug_img.asnumpy() 
<normalization>
train_stack = np.vstack([oof,oof_2] ).transpose()
test_stack = np.vstack([predictions, predictions_2] ).transpose()
folds_stack = RepeatedKFold(n_splits=5, n_repeats=2, random_state=15)
 oof_stack = np.zeros(train_stack.shape[0])
 predictions_3 = np.zeros(test_stack.shape[0])
 for fold_,(trn_idx, val_idx)in enumerate(folds_stack.split(train_stack,target)) :
print("fold {}".format(fold_))
trn_data, trn_y = train_stack[trn_idx], target.iloc[trn_idx].values
val_data, val_y = train_stack[val_idx], target.iloc[val_idx].values
clf_3 = BayesianRidge()
clf_3.fit(trn_data, trn_y)
 oof_stack[val_idx] = clf_3.predict(val_data)
 predictions_3 += clf_3.predict(test_stack)/ 10
<choose_model_class><EOS> 
sample_submission = pd.read_csv('.. /input/santander-customer-transaction-prediction/sample_submission.csv')
 sample_submission['target'] = predictions_3
sample_submission.to_csv('submission_ashish.csv', index=False )