Kaggle competition: IEEE-CIS Fraud Detection
<SOS> metric: AUC Kaggle data source: ieee-cis-fraud-detection<choose_model_class>
RANDOM_SEED = 314
rcParams['figure.figsize'] = 14, 8.7
LABELS = ["Normal","Fraud"]
sns.set()
model = Sequential()
model.add(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu', input_shape =(28,28,1)))
 model.add(BatchNormalization())
 model.add(AveragePooling2D(pool_size=(2,2)))
 model.add(Dropout(0.1))
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(AveragePooling2D(pool_size=(2,2), strides=(2,2)))
 model.add(BatchNormalization())
 model.add(Dropout(0.1))
model.add(Flatten())
 model.add(Dense(256, activation = "relu"))
model.add(Dropout(0.25))
model.add(Dense(10, activation = "softmax"))<choose_model_class>
path = '.. /input'
name=[]
for i in os.listdir(path):
name.append(i)
 print(name)
 for j in name:
new_j = j.replace('.csv','')
 print('Creating {} DataFrame'.format(new_j))
new_j=exec('{} = pd.read_csv(os.path.join(path,j)) '.format(new_j))
print('Done creating.' )
optimizer = Adam(
 learning_rate=0.001,
beta_1=0.9,
beta_2=0.999,
epsilon=1e-07)
 learning_rate_reduction = ReduceLROnPlateau(monitor='val_Accuracy',
patience=3,
verbose=1,
factor=5e-7,
min_lr=0.00001 )<choose_model_class>
train_transaction = reduce_mem_usage(train_transaction )
model.compile(optimizer = optimizer , loss = "categorical_crossentropy", metrics=["accuracy"])
 epochs = 20
batch_size = 128 
<init_hyperparams>
obj_cols = train_transaction.dtypes
obj_cols[obj_cols=='object']
datagen = ImageDataGenerator(
 featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
rotation_range=10,
zoom_range = 0.1,
width_shift_range=0.1,
height_shift_range=0.1,
horizontal_flip=False,
vertical_flip=False)
 datagen.fit(X_train )<train_model>
train_transaction.isna().sum()
history = model.fit_generator(datagen.flow(X_train,Y_train, batch_size=batch_size),
epochs = epochs, validation_data =(X_val,Y_val),
verbose = 2, steps_per_epoch=X_train.shape[0] // batch_size, callbacks=[learning_rate_reduction]
)<predict_on_test>
count = train_transaction.isFraud.value_counts()
regular = count[0]
frauds = count[1]
total= frauds + regular
perc_reg =(regular/total)*100
perc_frauds =(frauds/total)*100
print('There were {} non-fraudulent transactions({:.3f}%)and {} fraudulent transactions({:.3f}% ).'.format(regular, perc_reg, frauds, perc_frauds))
results = model.predict(test)
 results = np.argmax(results,axis = 1)
 results = pd.Series(results,name="Label" )<save_to_csv>
frauds = train_transaction[train_transaction['isFraud']==1]
submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1)
 submission.to_csv("cnn_mnist_datagen.csv",index=False)
<import_modules>
notfrauds= train_transaction[train_transaction['isFraud']==0]
import numpy as np
import pandas as pd 
<load_from_csv>
<train_model><EOS> 
feats= ['TransactionID',
'C14',
'C13',
'C12',
'C11',
'C10',
'C8',
'C7',
'C6',
'C5',
'C4',
'C3',
'C2',
'C1',
'C9',
'isFraud',
'TransactionDT',
'TransactionAmt',
'ProductCD',
'card1']