Kaggle competition: Don't Get Kicked!
num_epochs = 5
batch_size = 32
skf = StratifiedKFold(n_splits=10, shuffle=True, random_state=seed )<load_from_csv>
train_data=pd.read_csv('/kaggle/input/DontGetKicked/training.csv')
 train_data.head()
%%time
train_df = pd.read_csv('.. /input/tweet-sentiment-extraction/train.csv')
 train_df['text'] = train_df['text'].astype(str)
 train_df['selected_text'] = train_df['selected_text'].astype(str)
 for fold,(train_idx, val_idx)in enumerate(skf.split(train_df, train_df.sentiment), start=1):
print(f'Fold: {fold}')
 model = TweetModel()
optimizer = optim.AdamW(model.parameters() , lr=2e-5, betas=(0.9, 0.999))
criterion = loss_fn
dataloaders_dict = get_train_val_loaders(train_df, train_idx, val_idx, batch_size)
 train_model(
 model,
dataloaders_dict,
criterion,
optimizer,
num_epochs,
f'roberta_fold{fold}.pth' )<load_from_csv>
test_data=pd.read_csv('/kaggle/input/DontGetKicked/test.csv')
 test_data.head()
%%time
test_df = pd.read_csv('.. /input/tweet-sentiment-extraction/test.csv')
 test_df['text'] = test_df['text'].astype(str)
 test_loader = get_test_loader(test_df)
 predictions = []
models = []
for fold in range(skf.n_splits):
model = TweetModel()
model.cuda()
model.load_state_dict(torch.load(f'roberta_fold{fold+1}.pth'))
model.eval()
models.append(model)
 for data in test_loader:
ids = data['ids'].cuda()
masks = data['masks'].cuda()
tweet = data['tweet']
offsets = data['offsets'].numpy()
start_logits = []
end_logits = []
for model in models:
with torch.no_grad() :
output = model(ids, masks)
 start_logits.append(torch.softmax(output[0], dim=1 ).cpu().detach().numpy())
 end_logits.append(torch.softmax(output[1], dim=1 ).cpu().detach().numpy())
 start_logits = np.mean(start_logits, axis=0)
 end_logits = np.mean(end_logits, axis=0)
 for i in range(len(ids)) :
start_pred = np.argmax(start_logits[i])
 end_pred = np.argmax(end_logits[i])
 if start_pred > end_pred:
pred = tweet[i]
else:
pred = get_selected_text(tweet[i], start_pred, end_pred, offsets[i])
 predictions.append(pred )<save_to_csv>
train_data.isnull().sum()
sub_df = pd.read_csv('.. /input/tweet-sentiment-extraction/sample_submission.csv')
 sub_df['selected_text'] = predictions
sub_df['selected_text'] = sub_df['selected_text'].apply(lambda x: x.replace('!!!!', '!')if len(x.split())==1 else x)
 sub_df['selected_text'] = sub_df['selected_text'].apply(lambda x: x.replace('.. ', '.')if len(x.split())==1 else x)
 sub_df['selected_text'] = sub_df['selected_text'].apply(lambda x: x.replace('...', '.')if len(x.split())==1 else x)
 sub_df.to_csv('submission.csv', index=False)
 sub_df.head()<import_modules>
test_data.isnull().sum()
import pandas as pd
import numpy as np
from keras.datasets import mnist
from keras.utils import to_categorical
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D,AveragePooling2D,Average, Flatten, Dense, Dropout, Activation , Concatenate, Input , BatchNormalization
from keras.optimizers import SGD
from keras.utils import plot_model
from matplotlib import pyplot as plt
from keras.callbacks import EarlyStopping
from keras.callbacks import ReduceLROnPlateau
from keras import Model
from keras.preprocessing.image import ImageDataGenerator
from sklearn.utils import class_weight<load_from_csv>
train_data['IsBadBuy'].value_counts()
df_train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
 df_test = pd.read_csv('/kaggle/input/digit-recognizer/test.csv' )<prepare_x_and_y>
train_data['Model'].value_counts()
trainX = df_train.drop('label', axis=1 ).values
trainy = df_train['label'].values.reshape(-1,1)
 testX = df_test.values<train_model>
train_data.drop('Model',axis=1,inplace=True)
 test_data.drop("Model",axis=1,inplace=True )
print('Train: X=%s, y=%s' %(trainX.shape, trainy.shape))
print('Test: X=%s, y=%s' %(testX.shape))<categorify>
train_data['Trim'].value_counts()
trainX = trainX.reshape(( trainX.shape[0], 28, 28, 1))
testX = testX.reshape(( testX.shape[0], 28, 28, 1))
trainy = to_categorical(trainy )<data_type_conversions>
train_data.drop('Trim',inplace=True,axis=1)
 test_data.drop('Trim',inplace=True,axis=1 )
trainX = trainX.astype('float32')
 testX = testX.astype('float32')
 trainX = trainX / 255.0
testX = testX / 255.0<init_hyperparams>
train_data['SubModel'].value_counts()
datagen = ImageDataGenerator(
 validation_split = 0.2,
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 )<train_model>
train_data.drop('SubModel',inplace=True,axis=1)
 test_data.drop('SubModel',inplace=True,axis=1 )
batch_size = 128
Training_data = datagen.flow(trainX,
y=trainy,
batch_size = batch_size,
subset = 'training')
 Validation_data = datagen.flow(trainX,
y=trainy,
batch_size = batch_size,
subset = 'validation' )<normalization>
train_data['Color'].value_counts()
class_weights = class_weight.compute_class_weight(
 'balanced',
np.unique(Training_data.classes),
Training_data.classes )<choose_model_class>
test_data['Color'].value_counts()
es = EarlyStopping(monitor='val_loss',
mode='auto',
verbose=1,
patience=15)
 lrr= ReduceLROnPlateau(monitor='val_loss',
factor=0.1,
patience=4,
min_lr=1e-6 )<choose_model_class>
train_data['Color'].fillna(value='Color_Unknown',inplace=True)
 test_data['Color'].fillna(value='Color_Unknown',inplace=True )
input_model = Input(( trainX.shape[1],trainX.shape[2],trainX.shape[3]))
model1 = Conv2D(32,(5,5), activation='relu' )(input_model)
 model1 = BatchNormalization()(model1)
 model1 = Conv2D(32,(5,5), activation='relu', padding='same' )(model1)
 model1 = BatchNormalization()(model1)
 model1 = MaxPooling2D(( 2, 2))(model1)
 model1 = Conv2D(64,(3,3), activation='relu' ,padding='same' )(model1)
 model1 = BatchNormalization()(model1)
 model1 = Conv2D(64,(3,3), activation='relu' ,padding='valid' )(model1)
 model1 = BatchNormalization()(model1)
 model1 = AveragePooling2D(( 2, 2))(model1)
 model1 = Flatten()(model1)
 model1 = Dense(units = 512, activation = 'relu' )(model1)
 model1 = Dropout(rate = 0.4 )(model1)
 model1 = BatchNormalization()(model1)
 model1 = Dense(units = 20, activation = 'relu' )(model1)
 model1 = BatchNormalization()(model1)
 model1 = Dense(units = 15, activation = 'relu' )(model1)
 model1 = BatchNormalization()(model1)
 output1 = Dense(units = 10, activation = 'softmax' )(model1)
 model2 = Conv2D(32,(4,4), activation='relu' )(input_model)
 model2 = BatchNormalization()(model2)
 model2 = Conv2D(32,(4,4), activation='relu', padding='same' )(model2)
 model2 = BatchNormalization()(model2)
 model2 = MaxPooling2D(( 2, 2))(model2)
 model2 = Conv2D(32,(3,3), activation='relu', padding='same' )(model2)
 model2 = BatchNormalization()(model2)
 model2 = Conv2D(32,(3,3), activation='relu', padding='same' )(model2)
 model2 = BatchNormalization()(model2)
 model2 = AveragePooling2D(( 2, 2))(model2)
 model2 = Conv2D(32,(2,2), activation='relu' ,padding='same' )(model2)
 model2 = BatchNormalization()(model2)
 model2 = Conv2D(32,(2,2), activation='relu' ,padding='valid' )(model2)
 model2 = BatchNormalization()(model2)
 model2 = AveragePooling2D(( 2, 2))(model2)
 model2 = Flatten()(model2)
 model2 = Dense(units = 1024, activation = 'relu' )(model2)
 model2 = Dropout(rate = 0.5 )(model2)
 model2 = BatchNormalization()(model2)
 model2 = Dense(units = 64, activation = 'relu' )(model2)
 model2 = BatchNormalization()(model2)
 output2 = Dense(units = 10, activation = 'softmax' )(model2)
 model3 = Conv2D(32,(3,3), activation='relu' )(input_model)
 model3 = BatchNormalization()(model3)
 model3 = Conv2D(32,(3,3), activation='relu', padding='same' )(model3)
 model3 = BatchNormalization()(model3)
 model3 = MaxPooling2D(( 2, 2))(model3)
 model3 = Conv2D(32,(3,3), activation='relu', padding='same' )(model3)
 model3 = BatchNormalization()(model3)
 model3 = Conv2D(32,(3,3), activation='relu', padding='same' )(model3)
 model3 = BatchNormalization()(model3)
 model3 = Conv2D(64,(2,2), activation='relu' ,padding='valid' )(model3)
 model3 = BatchNormalization()(model3)
 model3 = Conv2D(128,(2,2), activation='relu' ,padding='valid' )(model3)
 model3 = BatchNormalization()(model3)
 model3 = MaxPooling2D(( 2, 2))(model3)
 model3 = Flatten()(model3)
 model3 = Dense(units = 512, activation = 'relu' )(model3)
 model3 = Dropout(rate = 0.2 )(model3)
 model3 = BatchNormalization()(model3)
 model3 = Dense(units = 64, activation = 'relu' )(model3)
 model3 = BatchNormalization()(model3)
 output3 = Dense(units = 10, activation = 'softmax' )(model3)
 output = Average()([output1, output2 , output3])
 model = Model(inputs= [input_model], outputs=[output] )<choose_model_class>
print("Number of null values in Color column "+str(train_data['Color'].isnull().sum()))
print("Number of null values in Color column "+str(test_data['Color'].isnull().sum()))
sgd = SGD(lr=0.1, momentum=0.99)
 model.compile(optimizer=sgd, loss='categorical_crossentropy', metrics=['accuracy'] )<train_model>
train_data['Transmission'].value_counts()
history = model.fit_generator(Training_data,
epochs= 400,
validation_data= Validation_data,
class_weight=class_weights,
verbose=1,
callbacks=[es , lrr] )<load_pretrained>
test_data['Transmission'].value_counts()
model.save_weights("MNIST_weights.h5" )<predict_on_test>
train_data[train_data['Transmission']=='Manual']
pred = model.predict(testX)
 pred = pd.DataFrame(pred)
 pred['Label'] = pred.idxmax(axis=1)
 pred.head(5 )<feature_engineering>
train_data['Transmission'].replace("Manual","MANUAL",inplace=True )
pred['index'] = list(range(1,len(pred)+1))
pred.head()<rename_columns>
train_data['Transmission'].value_counts()
submission.rename(columns={'index':'ImageId'},inplace = True)
 submission.head()<save_to_csv>
train_data['Transmission'].fillna(value="Transmission_unk",inplace=True)
 test_data['Transmission'].fillna(value="Transmission_unk",inplace=True )
submission.to_csv('submission.csv',index=False )<set_options>
train_data['WheelTypeID'].value_counts()
%matplotlib inline 
<load_from_csv>
train_data.drop('WheelTypeID',inplace=True,axis=1)
 test_data.drop('WheelTypeID',inplace=True,axis=1 )
train = pd.read_csv(".. /input/digit-recognizer/train.csv")
 test = pd.read_csv(".. /input/digit-recognizer/test.csv" )<data_type_conversions>
train_data['WheelType'].value_counts()
y_train = train["label"].astype('float32')
 x_train = train.drop(labels = ["label"],axis = 1 ).astype('float32')
 y_train.value_counts()<feature_engineering>
test_data['WheelType'].value_counts()
x_train = x_train / 255.0
test = test / 255.0<categorify>
train_data['WheelType'].fillna(value='WheelType_unk',inplace=True)
 test_data['WheelType'].fillna(value='WheelType_unk',inplace=True )
y_train = keras.utils.to_categorical(y_train, 10 )<choose_model_class>
train_data['WheelType'].value_counts()
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(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu'))
model.add(BatchNormalization())
 model.add(MaxPooling2D(pool_size=(2,2)))
 model.add(Dropout(0.25))
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(BatchNormalization())
 model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(BatchNormalization())
 model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2)))
 model.add(Dropout(0.25))
model.add(Flatten())
 model.add(Dense(512, activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(10, activation = "softmax"))<choose_model_class>
train_data['Nationality'].value_counts()
optimizer = RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0 )<choose_model_class>
test_data['Nationality'].value_counts()
model.compile(optimizer = optimizer , loss = "categorical_crossentropy", metrics=["accuracy"] )<init_hyperparams>
train_data['Nationality'].fillna(value='Nationality_unk',inplace=True)
 test_data['Nationality'].fillna(value='Nationality_unk',inplace=True )
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_data['Size'].value_counts()
model.fit_generator(datagen.flow(x_train,y_train, batch_size = 86),epochs = 30, steps_per_epoch = x_train.shape[0]//64)
<predict_on_test>
test_data['Size'].value_counts()
pred = model.predict(test)
 final_pred = np.argmax(pred,axis = 1 )<load_from_csv>
train_data['Size'].fillna(value='Size_unk',inplace=True)
 test_data['Size'].fillna(value="Size_unk",inplace=True )
sample_sub = pd.read_csv('.. /input/digit-recognizer/sample_submission.csv' )<save_to_csv>
train_data['TopThreeAmericanName'].value_counts()
sample_sub = pd.DataFrame({"ImageId": list(range(1,len(final_pred)+1)) ,
"Label": final_pred})
 sample_sub.to_csv('CNN_submission1.csv', index=False)
 sample_sub.head()<import_modules>
test_data['TopThreeAmericanName'].value_counts()
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
from keras import datasets
from keras import backend as K
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Dense, Conv2D, MaxPooling2D, Flatten, Dropout, BatchNormalization
from keras.utils.vis_utils import plot_model<load_from_csv>
train_data['TopThreeAmericanName'].fillna(value='Top_unk',inplace=True)
 test_data['TopThreeAmericanName'].fillna(value='Top_unk',inplace=True )
train_df = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
 test_df = pd.read_csv('/kaggle/input/digit-recognizer/test.csv' )<count_missing_values>
train_data['PRIMEUNIT'].value_counts()
print(f"Missing values in the train set: {train_df.isnull().any(axis=None)}",
f"Missing values in the test set: {test_df.isnull().any(axis=None)}", sep='
' )<prepare_x_and_y>
test_data['PRIMEUNIT'].value_counts()
y_train = pd.get_dummies(train_df['label'] ).values
X_train = train_df.values[:,1:] / 255.0
X_train = X_train.reshape(( -1, 28, 28, 1))
X_test = test_df.values / 255.0
X_test = X_test.reshape(( -1, 28, 28, 1))<train_model>
train_data['PRIMEUNIT'].fillna(value="Prime_unk",inplace=True)
 test_data['PRIMEUNIT'].fillna(value="Prime_unk",inplace=True )
show_some_img(X_train, y_train, 10 )<split>
train_data['AUCGUART'].replace("AGREEN","GREEN",inplace=True)
 test_data['AUCGUART'].replace("ARED","RED",inplace=True )
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size = 0.05, random_state=1)
 X_train, X_local_test, y_train, y_local_test = train_test_split(X_train, y_train, test_size = 0.02, random_state=2 )<train_model>
train_data['AUCGUART'].fillna(value="AUC_unk",inplace=True)
 test_data['AUCGUART'].fillna(value="AUC_unk",inplace=True )
print(f"Train set size: {len(X_train)}", f"Validation set size: {len(X_val)}", f"Test set size: {len(X_local_test)}", sep='
' )<choose_model_class>
train_data.drop(['MMRAcquisitionAuctionAveragePrice','MMRAcquisitionAuctionCleanPrice',
'MMRAcquisitionRetailAveragePrice','MMRAcquisitonRetailCleanPrice',
'MMRCurrentAuctionAveragePrice','MMRCurrentAuctionCleanPrice',
'MMRCurrentRetailAveragePrice','MMRCurrentRetailCleanPrice'],
inplace=True,axis=1)
 test_data.drop(['MMRAcquisitionAuctionAveragePrice','MMRAcquisitionAuctionCleanPrice',
'MMRAcquisitionRetailAveragePrice','MMRAcquisitonRetailCleanPrice',
'MMRCurrentAuctionAveragePrice','MMRCurrentAuctionCleanPrice',
'MMRCurrentRetailAveragePrice','MMRCurrentRetailCleanPrice'],
inplace=True,axis=1 )
img_rows, img_cols = 28, 28
model = Sequential()
model.add(Conv2D(32, kernel_size=5, activation='relu', padding='same', input_shape=(img_rows, img_cols, 1)))
 model.add(BatchNormalization())
 model.add(Conv2D(32, kernel_size=5, activation='relu', padding='same'))
model.add(MaxPooling2D(pool_size=(2, 2), padding="same"))
model.add(Dropout(0.2))
model.add(Conv2D(64, kernel_size=3, activation='relu', padding='same'))
model.add(BatchNormalization())
 model.add(Conv2D(64, kernel_size=3, activation='relu', padding='same'))
model.add(MaxPooling2D(pool_size=(2, 2), padding="same"))
model.add(Dropout(0.2))
model.add(Flatten())
 model.add(Dense(256, activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'] )<train_model>
train_data.drop('PurchDate',axis=1,inplace=True)
 test_data.drop("PurchDate",axis=1,inplace=True )
datagen = ImageDataGenerator(
 rotation_range=15,
zoom_range = 0.15,
width_shift_range=0.1,
height_shift_range=0.1)
 datagen.fit(X_train )<train_model>
train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes!='object'
augmented_images, augmented_labels = datagen.flow(X_train, y_train, batch_size=10 ).next()
show_some_img(augmented_images, augmented_labels, 10 )<train_model>
not_categorical=train_data.drop(['RefId','IsBadBuy'],axis=1 ).columns[train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes!='object']
batch_size = 400
training = model.fit_generator(datagen.flow(X_train, y_train, batch_size=batch_size),
validation_data=(X_val, y_val), epochs=70, steps_per_epoch=X_train.shape[0] // batch_size )<compute_test_metric>
for i in not_categorical:
maximum=np.max(train_data[i])
 train_data[i]=train_data[i]/maximum
maximum_test=np.max(test_data[i])
 test_data[i]=test_data[i]/maximum_test
model.evaluate(X_local_test, y_local_test, batch_size=batch_size )<predict_on_test>
categorical=train_data.drop(['RefId','IsBadBuy'],axis=1 ).columns[train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes=='object']
y_local_pred = model.predict(X_local_test )<compute_test_metric>
train_data[categorical[0]]
show_some_wrong_img(X_local_test, y_local_test, y_local_pred, 10 )<predict_on_test>
pd.get_dummies(train_data[categorical[0]] )
y_pred = np.argmax(model.predict(X_test), axis=1)
 result = pd.DataFrame({'ImageId':range(1, len(y_pred)+1), 'Label':y_pred})
 result.head()<save_to_csv>
for i in categorical:
dummies=pd.get_dummies(train_data[i])
 dummies.columns=str(i)+'_'+dummies.columns
train_data=pd.concat([train_data,dummies],axis=1)
 train_data.drop(i,inplace=True,axis=1)
 dummies=pd.get_dummies(test_data[i])
 dummies.columns=str(i)+'_'+dummies.columns
test_data=pd.concat([test_data,dummies],axis=1)
 test_data.drop(i,inplace=True,axis=1 )
result.to_csv('my_submission.csv', index=False )<import_modules>
for i in train_data.drop('IsBadBuy',axis=1 ).columns:
if i not in test_data.columns:
test_data[i]=np.zeros(len(test_data))
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Conv2D, Flatten, Dropout, MaxPool2D, BatchNormalization
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.losses import categorical_crossentropy
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import EarlyStopping<define_variables>
for i in test_data.columns:
if i not in train_data.columns:
train_data[i]=np.zeros(len(train_data))
train_path = '.. /input/digit-recognizer/train.csv'
test_path = '.. /input/digit-recognizer/test.csv'<load_from_csv>
test_data=test_data[train_data.drop("IsBadBuy",axis=1 ).columns]
train_data = pd.read_csv(train_path)
 test_data = pd.read_csv(test_path )<count_unique_values>
X=train_data.drop(['RefId','IsBadBuy'],axis=1)
 y=train_data['IsBadBuy']
img_rows, img_cols = 28, 28
num_classes = train_data.label.nunique()<categorify>
X_train,X_test,y_train,y_test=train_test_split(X,y,random_state=42 )
def data_prep(raw_data, img_row, img_col, num_classes):
out_y = to_categorical(raw_data.label, num_classes)
 num_images = raw_data.shape[0]
x_as_array = raw_data.values[:, 1:]
x_as_matrix = x_as_array.reshape(num_images, img_row, img_col, 1)
 out_x = x_as_matrix/255.0
return out_x, out_y<prepare_x_and_y>
from sklearn.neighbors import KNeighborsClassifier
X, y = data_prep(train_data, img_rows, img_cols, num_classes )<choose_model_class>
from sklearn.neighbors import KNeighborsClassifier
model = Sequential()<choose_model_class>
from sklearn.neighbors import KNeighborsClassifier
model.add(Conv2D(filters=40, kernel_size=(3,3), padding='Same', activation='relu', input_shape=(img_rows, img_cols, 1)))
 model.add(MaxPool2D(2,2))
model.add(BatchNormalization(axis=1))
model.add(Conv2D(filters=60, kernel_size=(3,3), padding='Same', activation='relu'))
model.add(MaxPool2D(pool_size=(2,2)))
 model.add(BatchNormalization(axis=1))
model.add(Dropout(0.25))
model.add(Conv2D(filters=80, kernel_size=(3,3), padding='Same', activation='relu'))
model.add(MaxPool2D(pool_size=(2,2), strides=(2,2)))
 model.add(BatchNormalization(axis=1))
model.add(Dropout(0.25))
model.add(Flatten())
 model.add(BatchNormalization(axis=1))
model.add(Dense(256, activation='relu'))
model.add(BatchNormalization(axis=1))
model.add(Dropout(0.50))
model.add(BatchNormalization(axis=1))
model.add(Dense(10, activation='softmax'))
model.summary()<choose_model_class>
KNN=KNeighborsClassifier(n_neighbors=11)
 KNN.fit(X_train,y_train )
model.compile(loss=categorical_crossentropy,
optimizer=Adam(0.001),
metrics=['accuracy'] )<train_model>
KNN.score(X_test,y_test )
<train_model>
predict=KNN.predict(test_data.drop('RefId',axis=1))
history = model.fit(X, y, epochs=20, validation_split=0.2 )<train_model>
Submission=pd.DataFrame(data=predict,columns=['IsBadBuy'])
 Submission.head()
test_num_img = test_data.shape[0]
test_data_array = test_data.values
test_data_matrix = test_data_array.reshape(test_num_img, 28,28,1)
 test_data_matrix = test_data_matrix/255<predict_on_test>
Submission['RefId']=test_data['RefId']
Submission.set_index('RefId',inplace=True )
preds = model.predict_classes(test_data_matrix )<save_to_csv>
Submission.head()
Submission.to_csv('Submission.csv' )