Kaggle competition: Santander Customer Satisfaction
<SOS> metric: AUC Kaggle data source: santander-customer-satisfaction<choose_model_class>
train=pd.read_csv(".. /input/train.csv")
 test=pd.read_csv(".. /input/test.csv")
model=Sequential()
model.add(Conv2D(64,3,activation='relu',input_shape=(28,28,1)))
 model.add(Conv2D(128,3,activation='relu'))
model.add(MaxPooling2D(( 3,3),strides=(3,3)))
 model.add(Dropout(0.25))
model.add(Conv2D(256,3,activation='relu'))
model.add(Conv2D(512,1,activation='relu'))
model.add(MaxPooling2D(( 3,3),strides=(3,3)))
 model.add(Dropout(0.25))
model.add(Flatten())
 model.add(Dense(100,activation='relu'))
model.add(Dense(100,activation='relu'))
model.add(Dense(10,activation='softmax'))<choose_model_class>
colsToRemove = []
for col in train.columns:
if train[col].std() == 0:
colsToRemove.append(col)
 train.drop(colsToRemove, axis=1, inplace=True)
 test.drop(colsToRemove, axis=1, inplace=True)
 colsToRemove = []
columns = train.columns
for i in range(len(columns)-1):
v = train[columns[i]].values
for j in range(i+1,len(columns)) :
if np.array_equal(v,train[columns[j]].values):
colsToRemove.append(columns[j])
 train.drop(colsToRemove, axis=1, inplace=True)
 test.drop(colsToRemove, axis=1, inplace=True)
 train.shape
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'] )<choose_model_class>
target=train.TARGET.values
train.drop(['ID','TARGET'],axis=1,inplace = True)
 ids=test.ID.values
test.drop(['ID'],axis=1,inplace = True)
 print(train.shape,'
',test.shape)
estop=EarlyStopping(monitor='val_acc',patience=10,verbose=1)
 lrreduce=ReduceLROnPlateau(monitor='val_acc',verbose=1,factor=0.5,min_lr=1e-10,patience=3 )<train_model>
slct = SelectFpr(alpha = 0.000001)
 trainFeatures = slct.fit_transform(train, target)
 print(trainFeatures.shape )
bSize=128
model.fit_generator(trainDatagen.flow(x=X_train,y=y_train,batch_size=bSize),steps_per_epoch=X_train.shape[0]*20/bSize,epochs=500,validation_data=(X_test,y_test),callbacks=[estop,lrreduce] )<save_to_csv>
colsToRetain = slct.get_support(indices = True)
predictions=model.predict(test)
 predictions_df=pd.DataFrame({'ImageId':testIndex+1,'Label':np.argmax(predictions,axis=1)})
 predictions_df[['ImageId','Label']].to_csv('Submission_CNN_LargeAugmentation.csv',index=False )<save_model>
clf = xgb.XGBClassifier(missing=np.nan, max_depth=5, n_estimators=550, learning_rate=0.03, nthread=4, subsample=0.95, colsample_bytree=0.85, seed=4242)
 X_train, X_test, y_train, y_test = train_test_split(trainFeatures, target, test_size=0.3 )
model.save('MNIST_CNN_LargeAugmentation.kps' )<prepare_x_and_y>
X_fit, X_eval, y_fit, y_eval= train_test_split(trainFeatures, target, test_size=0.3 )
data_dir = '.. /input/'
train_path = os.path.join(data_dir, 'train.csv')
 test_path = os.path.join(data_dir, 'test.csv')
 train = pd.read_csv(train_path)
 test = pd.read_csv(test_path)
 print(len(train), len(test))
y_train = train['label']
x_train = train.drop(labels=['label'], axis=1)
 del train
x_train /= 255.
 test /= 255.
 x_train = x_train.values.reshape(-1, 28, 28, 1)
 test = test.values.reshape(-1, 28, 28, 1)
 y_train = to_categorical(y_train)
 random_seed = 2
x_train, x_val, y_train, y_val = train_test_split(x_train, y_train, test_size=0.1, random_state=random_seed)
 x_train, y_train 
<choose_model_class>
clf = xgb.XGBClassifier(missing=np.nan, max_depth=5, n_estimators=350, learning_rate=0.03, nthread=4,
subsample=0.95, colsample_bytree=0.85, seed=4242)
 clf.fit(trainFeatures, target, early_stopping_rounds=365, eval_metric="auc", eval_set=[(X_eval, y_eval)])
model = models.Sequential()
model.add(layers.Conv2D(filters=32, kernel_size=(5, 5), padding='Same',
activation='relu', input_shape=(28, 28, 1)))
 model.add(layers.Conv2D(filters=32, kernel_size=(5, 5), padding='Same',
activation='relu'))
model.add(layers.MaxPool2D(pool_size=(2, 2)))
 model.add(layers.Dropout(0.25))
model.add(layers.Conv2D(filters=64, kernel_size=(3, 3), padding='Same',
activation='relu'))
model.add(layers.Conv2D(filters=64, kernel_size=(3, 3), padding='Same',
activation='relu'))
model.add(layers.MaxPool2D(pool_size=(2, 2), strides=(2, 2)))
 model.add(layers.Dropout(0.25))
model.add(layers.Flatten())
 model.add(layers.Dense(256, activation="relu"))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(10, activation="softmax"))
optimizer = optimizers.RMSprop(lr=0.001, rho=0.9, epsilon=1e-8, decay=0.0)
 model.compile(
 optimizer=optimizer,
loss=losses.categorical_crossentropy,
metrics=['acc'])
 model.summary() 
<train_model>
print('Overall AUC:', roc_auc_score(target, clf.predict_proba(trainFeatures)[:,1]))
<save_to_csv><EOS> 
y_pred= clf.predict_proba(testFeatures)[:,1]
submission = pd.DataFrame({"ID":ids, "TARGET":y_pred})
 submission.to_csv("submission.csv", index=False)
 print('done !' )