Kaggle competition: Santander Customer Satisfaction
learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc',
patience=3,
verbose=1,
factor=0.5,
min_lr=0.00001 )<define_variables>
%matplotlib inline
pd.set_option('display.precision', 5)
 training = pd.read_csv(".. /input/train.csv", index_col=0)
 test = pd.read_csv(".. /input/test.csv", index_col=0)
 print(training.shape)
 print(test.shape)
 X = training.iloc[:,:-1]
y = training.TARGET
epochs = 30
batch_size = 64<train_model>
import xgboost as xgb
from sklearn.cross_validation import train_test_split
history = model.fit(X_train, Y_train, batch_size = batch_size, epochs = epochs,
validation_data =(X_val, Y_val),callbacks=[learning_rate_reduction] )<predict_on_test>
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1301)
 clf = xgb.XGBClassifier(max_depth=3, n_estimators=300, learning_rate=0.05)
 clf.fit(X_train, y_train, early_stopping_rounds=10, eval_metric="auc",
eval_set=[(X_test, y_test)])
 y_pred = clf.predict(test )
results = model.predict(test )<prepare_output>
y_pred = clf.predict_proba(test )
results = np.argmax(results,axis = 1)
<concatenate>
params = {"objective": "binary:logistic", "booster": "gbtree", "eval_metric":"auc"}
train_xgb = xgb.DMatrix(X, y)
 test_xgb = xgb.DMatrix(test)
 gbm = xgb.train(params, train_xgb, 20)
 y_pred = gbm.predict(test_xgb )
submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1 )<save_to_csv>
submission = pd.DataFrame({"ID":test.index, "TARGET":y_pred})
 submission.to_csv("submission.csv", index=False )
submission.to_csv("SM.csv",index=False )<import_modules>
remove = []
for col in training.columns:
if training[col].std() == 0:
remove.append(col)
 training.drop(remove, axis=1, inplace=True )
print(os.listdir(".. /input")) 
<normalization>
test.drop(remove, axis=1, inplace=True )
def preprocess(data):
for im in tqdm(range(data.shape[0])) :
im_array=data[im].reshape(28,28)
 im_array=exposure.adjust_sigmoid(exposure.adjust_sigmoid(exposure.adjust_sigmoid(exposure.adjust_sigmoid(im_array))))
data[im]=im_array.reshape(28,28,1)
 return data<load_from_csv>
X = training.iloc[:,:-1]
y = training.TARGET
train=pd.read_csv(".. /input/train.csv")
 test=pd.read_csv(".. /input/test.csv")
 testIndex=test.index
ylabel_train=train['label']
train=train.drop('label',axis=1 ).values.reshape(train.shape[0],28,28,1)
 test=test.values.reshape(test.shape[0],28,28,1)
 print('Adjusting training and test images')
 train=train/255.0
test=test/255.0<split>
params = {"objective": "binary:logistic", "booster": "gbtree", "eval_metric":"auc"}
train_xgb = xgb.DMatrix(X, y)
 test_xgb = xgb.DMatrix(test)
 gbm = xgb.train(params, train_xgb, 20)
 y_pred = gbm.predict(test_xgb )
<choose_model_class><EOS> 
submission = pd.DataFrame({"ID":test.index, "TARGET":y_pred})
 submission.to_csv("submission.csv", index=False )