Kaggle competition: Santander Customer Satisfaction
<SOS> metric: AUC Kaggle data source: santander-customer-satisfaction<load_from_csv>
tf.logging.set_verbosity(tf.logging.ERROR)
 pd.options.display.max_rows = 10
pd.options.display.float_format = '{:.1f}'.format
print(os.listdir(".. /input"))
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )<feature_engineering>
train_df = pd.read_csv(".. /input/train.csv",sep=",")
 test_df = pd.read_csv(".. /input/test.csv",sep="," )
X_train = X_train / 255.0
test = test / 255.0<train_model>
combined_df=pd.DataFrame()
combined_df=pd.concat([train_df,test_df] )
X_train = X_train.values.reshape(-1,28,28,1)
 test = test.values.reshape(-1,28,28,1 )<categorify>
num_df=pd.DataFrame.copy(combined_df)
 target_df=pd.DataFrame()
target_df["TARGET"]=num_df["TARGET"]
num_df=num_df.drop(["TARGET"],axis=1)
 ID_df=pd.DataFrame()
ID_df["ID"]=num_df["ID"]
num_df=num_df.drop(["ID"],axis=1 )
Y_train = to_categorical(Y_train, num_classes = 10)
<split>
clean_df=pd.DataFrame.copy(num_df)
 clean_df["var3"].value_counts()
clean_df.loc[clean_df['var3']==-999999,'var3']=2
clean_df["var3"].value_counts()
X_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train, test_size = 0.1, random_state=2 )<set_options>
clean_df[num_df==9999999999] = 100
clean_df.skew().sort_values(ascending=False )
sns.set(style='white', context='notebook', palette='deep' )<choose_model_class>
def preprocess_features(training_df):
selected_features = training_df[training_df.columns.difference(["TARGET","ID"])]
processed_features = selected_features.copy()
return processed_features
def preprocess_targets(training_df):
output_targets = pd.DataFrame()
output_targets["TARGET"] =(
 training_df["TARGET"])
 return output_targets
model = Sequential()
model.add(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu', input_shape =(28,28,1)))
 model.add(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu'))
model.add(AvgPool2D(pool_size=(2,2)))
 model.add(Dropout(0.25))<choose_model_class>
training_examples= preprocess_features(Eng_train_df)
 test_examples = preprocess_features(Eng_test_df)
 training_targets = preprocess_targets(Eng_train_df )
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(AvgPool2D(pool_size=(2,2)) )<choose_model_class>
model_lasso = LassoCV(cv=10 ).fit(training_examples, np.ravel(training_targets))
coef = pd.Series(model_lasso.coef_, index = training_examples.columns)
 print("Lasso picked " + str(sum(coef != 0)) + " variables and eliminated the other " + str(sum(coef == 0)) + " variables" )
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(AvgPool2D(pool_size=(2,2)))
 model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(AvgPool2D(pool_size=(2,2), strides=(2,2)))
 model.add(Dropout(0.25))<choose_model_class>
lasso_preds = model_lasso.predict(test_examples)
 solution = pd.DataFrame({"ID":test_df["ID"], "Target":np.abs(lasso_preds)})
 solution.to_csv("Lasso.csv", index = False )
model.add(Flatten())
 model.add(Dense(256, activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(10, activation = "softmax"))<choose_model_class>
lasso_features = coef.iloc[coef.nonzero() [0]].sort_values()
lasso_features=lasso_features.index
lasso_features
optimizer = RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0 )<choose_model_class>
model_xgb=xgb.XGBClassifier()
model_xgb.fit(training_examples, np.ravel(training_targets))
xgb_preds = model_xgb.predict_proba(test_examples)
 solution = pd.DataFrame({"ID":test_df["ID"], "Target":np.abs(xgb_preds[:,1])})
 solution.to_csv("XGB_v1.csv", index = False )
model.compile(optimizer = optimizer , loss = "categorical_crossentropy", metrics=["accuracy"] )<choose_model_class>
model_xgb2=xgb.XGBClassifier()
model_xgb2.fit(training_examples[lasso_features], np.ravel(training_targets))
xgb_preds2 = model_xgb2.predict_proba(test_examples[lasso_features])
 solution = pd.DataFrame({"ID":test_df["ID"], "Target":np.abs(xgb_preds2[:,1])})
 solution.to_csv("XGB_v2.csv", index = False )