Kaggle competition: Digit Recognizer
train_data['Sex'] = pd.get_dummies(train_data['Sex'])
 train_data<data_type_conversions>
train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
 x_test = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')
train_data['Sex'] = train_data['Sex'].astype('int')
 train_data.info()<categorify>
import matplotlib.pyplot as plt
import tensorflow as tf
import cv2
from collections import deque
import numpy as np
test_data['Sex'] = pd.get_dummies(test_data['Sex'])
 test_data['Sex'] = test_data['Sex'].astype('int')
 test_data<categorify>
y_train = train['label']
x_train = train.drop(labels = ['label'], axis=1 )
one_hot = pd.get_dummies(train_data['Embarked'],drop_first=True)
 train_data = train_data.drop('Embarked',axis = 1)
 train_data = train_data.join(one_hot)
 train_data<categorify>
x_train = x_train.values.reshape(x_train.shape[0], 28, 28, 1)
 x_test = x_test.values.reshape(x_test.shape[0], 28, 28, 1 )
one_hot = pd.get_dummies(test_data['Embarked'],drop_first=True)
 test_data = test_data.drop('Embarked',axis = 1)
 test_data = test_data.join(one_hot)
 test_data<count_duplicates>
input_shape =(28, 28, 1)
len(train_data.loc[train_data['Ticket'].duplicated() ==True][['Ticket','Cabin']].sort_values('Ticket'))<feature_engineering>
x_train = x_train.astype('float32')
 x_test = x_test.astype('float32' )
train_data['Name'] = train_data['Name'].str.lower() 
<feature_engineering>
x_train /= 255
x_test /= 255
<categorify>
from keras.models import Sequential
from keras.layers import Dense, Conv2D, Dropout, Flatten, MaxPooling2D
<drop_column>
model = Sequential()
model.add(Conv2D(256, kernel_size=(5, 5), activation='relu', input_shape=input_shape))
model.add(Conv2D(128, kernel_size=(5, 5), activation='relu'))
model.add(Conv2D(64, kernel_size=(3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Flatten())
 model.add(Dense(100, activation=tf.nn.relu))
model.add(Dropout(0.2))
model.add(Dense(10, activation=tf.nn.softmax))
test_data['Name'] = test_data['Name'].str.lower() 
<filter>
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'] )
train_data.loc[(train_data['Ticket']=='S.O.C.14879')]<filter>
model.fit(x=x_train,y=y_train,epochs=150, verbose = 1 )
train_data.loc[train_data['Cabin'].isnull() ==False]<create_dataframe>
pred = model.predict(x_test)
 results = np.argmax(pred,axis = 1)
 results = pd.Series(results,name = 'Label' )
<feature_engineering><EOS> 
sub = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1)
 sub.to_csv("cnn_best_model.csv",index=False )