Kaggle competition: Santander Customer Satisfaction
<SOS> metric: AUC Kaggle data source: santander-customer-satisfaction<prepare_x_and_y>
warnings.filterwarnings("ignore")
 sns.set(style="white", color_codes=True)
scaler = MinMaxScaler()
X = train_encoded.drop(['SalePrice'], axis=1 ).values
y = train_encoded.SalePrice.values
X_scaled = scaler.fit_transform(X)
 test_scaled = scaler.transform(test_encoded.values)
 tf.random.set_seed(0)
 model = Sequential()
model.add(Dense(193, activation='relu'))
model.add(BatchNormalization())
 model.add(Dropout(0.2))
model.add(Dense(256, activation='relu'))
model.add(BatchNormalization())
 model.add(Dropout(0.2))
model.add(Dense(128, activation='relu'))
model.add(BatchNormalization())
 model.add(Dropout(0.2))
model.add(Dense(512, activation='relu'))
model.add(BatchNormalization())
 model.add(Dropout(0.2))
model.add(Dense(1))
model.compile(loss='mse', optimizer='adam')
 model.fit(X_scaled, y,
batch_size=64,
epochs=400,
validation_split = 0.2,
verbose = 0)
 losses = pd.DataFrame(model.history.history)
 losses.plot()
preds_test = np.expm1(model.predict(test_scaled))
output = pd.DataFrame({'Id': test_ID,
'SalePrice': preds_test.flatten() })
 output.to_csv('submission_TensorFlow.csv', index=False )<choose_model_class>
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv')
 submission = pd.read_csv('.. /input/sample_submission.csv')
 train.head()
%f using %s" %(grid_result.best_score_, grid_result.best_params_))
%f(%f)with: %r" %(mean, stdev, param))<set_options>
df = pd.DataFrame(train.TARGET.value_counts())
 df['Percentage'] =(df['TARGET']/df['TARGET'].sum())*100
df
%matplotlib inline
sns.set(style='white', context='notebook', palette='deep')
 np.random.seed(9 )<import_modules>
display(train.shape)
 display(train.duplicated(train.columns[1:],keep=False ).value_counts() [1])
 display(train.duplicated(train.columns[1:],keep='first' ).value_counts() [1])
 train = train.drop(train[train.duplicated(train.columns[1:],keep='first')].index)
 train.reset_index(drop=True,inplace=True)
 display(train.shape )
import matplotlib.image as mpimg
from sklearn.metrics import confusion_matrix
import itertools
import tensorflow as tf
from keras.utils.np_utils import to_categorical
from keras.models import Sequential
from keras.layers import Dense,Dropout,Flatten,Conv2D,MaxPool2D,BatchNormalization
from keras.optimizers import RMSprop
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import ReduceLROnPlateau
from keras.callbacks import LearningRateScheduler 
<import_modules>
noise_indices = train[train.duplicated(train.columns[1:-1],keep=False)&~train.duplicated(train.columns[1:],keep=False)].index
non_noise_indices = train.index.difference(noise_indices)
 f'We have {len(noise_indices)} instances of noise, {len(non_noise_indices)} non_noise'
if tf.test.gpu_device_name() :
print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
print("Please install GPU version of TF")
 print(tf.test.is_built_with_cuda() )<load_from_csv>
train=pd.read_csv('.. /input/digit-recognizer/train.csv')
 test=pd.read_csv('.. /input/digit-recognizer/test.csv' )<prepare_x_and_y>
trainNTP1_y = trainNTP1.TARGET
trainNTP1_X = trainNTP1.drop(['ID','TARGET'],axis=1)
 trainNTP1_xgb = XGBClassifier(n_estimators=100, max_depth=10, n_jobs=-1, seed=42)
 trainNTP1_xgb.fit(trainNTP1_X, trainNTP1_y)
 trainNTP2_y = trainNTP2.TARGET
trainNTP2_X = trainNTP2.drop(['ID','TARGET'],axis=1)
 trainNTP2_xgb = XGBClassifier(n_estimators=100, max_depth=10, n_jobs=-1, seed=42)
 trainNTP2_xgb.fit(trainNTP2_X, trainNTP2_y)
 trainNTP3_y = trainNTP3.TARGET
trainNTP3_X = trainNTP3.drop(['ID','TARGET'],axis=1)
 trainNTP3_xgb = XGBClassifier(n_estimators=100, max_depth=10, n_jobs=-1, seed=42)
 trainNTP3_xgb.fit(trainNTP3_X, trainNTP3_y)
 trainNTP4_y = trainNTP4.TARGET
trainNTP4_X = trainNTP4.drop(['ID','TARGET'],axis=1)
 trainNTP4_xgb = XGBClassifier(n_estimators=100, max_depth=10, n_jobs=-1, seed=42)
 trainNTP4_xgb.fit(trainNTP4_X, trainNTP4_y)
 trainNTP5_y = trainNTP5.TARGET
trainNTP5_X = trainNTP5.drop(['ID','TARGET'],axis=1)
 trainNTP5_xgb = XGBClassifier(n_estimators=100, max_depth=10, n_jobs=-1, seed=42)
 trainNTP5_xgb.fit(trainNTP5_X, trainNTP5_y )
y_train=train['label']
X_train=train.drop(columns='label' )<drop_column>
noise_y = noise.TARGET
noise_X = noise.drop(['ID','TARGET'],axis=1)
 pred1 = trainNTP1_xgb.predict(noise_X)
 display(pred1)
 pred2 = trainNTP2_xgb.predict(noise_X)
 pred3 = trainNTP3_xgb.predict(noise_X)
 pred4 = trainNTP3_xgb.predict(noise_X)
 pred5 = trainNTP3_xgb.predict(noise_X)
 pd.DataFrame({'pred1':pred1} )
del train<count_missing_values>
remove = []
for col in train.columns:
if(train[col].std() ==0):
remove.append(col)
 print(remove)
 print(len(remove))
train.drop(remove, axis=1, inplace=True)
 test.drop(remove, axis=1, inplace=True)
 train.shape
X_train.isna().any().sum()<count_missing_values>
remove = []
cols = train.columns
for i in range(len(cols)-1):
v = train[cols[i]].values
for j in range(i+1, len(cols)) :
if np.array_equal(v,train[cols[j]].values):
remove.append(cols[j])
 print(remove)
 print(len(remove))
train.drop(remove, axis=1, inplace=True)
 test.drop(remove, axis=1, inplace=True)
 train.shape
test.isna().any().sum()<feature_engineering>
test_ids = test.ID
test.drop(['ID'], axis=1, inplace=True)
 X = train.drop(['ID','TARGET'], axis=1)
 y = train.TARGET
X_train /=255.0
test /=255.0<categorify>
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42)
 print(X_train.shape, X_test.shape, test.shape )
y_train=to_categorical(y_train,num_classes=10 )<split>
etc = ExtraTreesClassifier(random_state=42)
 selector = etc.fit(X_train,y_train )
<choose_model_class>
fs = SelectFromModel(selector, prefit=True)
 X_train = fs.transform(X_train)
 X_test = fs.transform(X_test)
 test = fs.transform(test)
 print(X_train.shape, X_test.shape, test.shape)
nets=6
model=[0]*nets
optimizer = RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0)
<choose_model_class>
m_xgb = XGBClassifier(n_estimators=100, max_depth=3, n_jobs=-1, seed=42)
 m_xgb.fit(X_train, y_train, eval_set=[(X_test, y_test)], eval_metric='auc')
model[0]=Sequential()
model[0].add(Conv2D(filters=32,kernel_size=(5,5),padding='Same',activation='relu',input_shape=(28,28,1)))
 model[0].add(Conv2D(filters=32,kernel_size=(5,5),padding='Same',activation='relu',input_shape=(28,28,1)))
 model[0].add(MaxPool2D(pool_size=(2,2)))
 model[0].add(Dropout(0.25))
model[0].add(Conv2D(filters=64,kernel_size=(3,3),padding='Same',activation='relu',input_shape=(28,28,1)))
 model[0].add(Conv2D(filters=64,kernel_size=(3,3),padding='Same',activation='relu',input_shape=(28,28,1)))
 model[0].add(MaxPool2D(pool_size=(2,2)))
 model[0].add(Dropout(0.25))
model[0].add(Flatten())
 model[0].add(Dense(256,activation='relu'))
model[0].add(Dropout(0.5))
model[0].add(Dense(10,activation='softmax'))
model[0].compile(optimizer=optimizer,loss="categorical_crossentropy",metrics=['accuracy'] )<choose_model_class>
m_xgb.predict_proba(X_test)
model[1]=Sequential()
model[1].add(Conv2D(filters=32,kernel_size=(5,5),padding='Same',activation='relu',input_shape=(28,28,1)))
 model[1].add(Conv2D(filters=32,kernel_size=(5,5),padding='Same',activation='relu',input_shape=(28,28,1)))
 model[1].add(MaxPool2D(pool_size=(2,2)))
 model[1].add(Dropout(0.25))
model[1].add(Conv2D(filters=64,kernel_size=(3,3),padding='Same',activation='relu',input_shape=(28,28,1)))
 model[1].add(Conv2D(filters=64,kernel_size=(3,3),padding='Same',activation='relu',input_shape=(28,28,1)))
 model[1].add(MaxPool2D(pool_size=(2,2)))
 model[1].add(Dropout(0.25))
model[1].add(Flatten())
 model[1].add(Dense(256,activation='relu'))
model[1].add(Dropout(0.5))
model[1].add(Dense(10,activation='softmax'))
model[1].compile(optimizer=optimizer,loss="categorical_crossentropy",metrics=['accuracy'] )<choose_model_class>
print('ROC AUC score', roc_auc_score(y_true=y_test, y_score=m_xgb.predict_proba(X_test)[:,1], average='macro'))
<choose_model_class><EOS> 
submission = pd.DataFrame({'ID':test_ids,'TARGET': m_xgb.predict_proba(test)[:,1]})
 submission.to_csv('submission.csv',index=False )