Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<correct_missing_values>
test_df = pd.read_csv('.. /input/digit-recognizer/test.csv')
 train_df = pd.read_csv('.. /input/digit-recognizer/train.csv')
 print('Shape of the testing dataset:', test_df.shape)
 print('Shape of the training dataset:', train_df.shape )
fill_missing_values(train_data)
 fill_missing_values(validation_data )<load_from_csv>
train_labels = train_df['label']
train_images = train_df.drop('label', axis=1)
 train_images = train_images.astype('float32')/255
test_images = test_df.astype('float32')/255
train_images = np.array(train_images ).reshape(42000,28,28,1)
 test_images = np.array(test_images ).reshape(28000,28,28,1)
 train_images, validation_images, train_labels, validation_labels = train_test_split(train_images, train_labels, test_size=0.1, random_state=0)
 train_labels = to_categorical(train_labels)
 validation_labels = to_categorical(validation_labels )
test_data = pd.read_csv('test_stg2.tsv',sep='\t')
 test = test_data.copy()<count_missing_values>
datagen = ImageDataGenerator(rotation_range=10,
width_shift_range=0.05,
height_shift_range=0.05,
shear_range=0.1,
zoom_range=0.05,
horizontal_flip=False,
fill_mode='nearest')
 datagen.fit(train_images )
test_data.isnull().sum()<string_transform>
model = models.Sequential()
model.add(layers.Conv2D(32,(3, 3), activation='relu', padding='same', input_shape=(28, 28, 1)))
 model.add(layers.BatchNormalization())
 model.add(layers.MaxPooling2D(( 2, 2)))
 model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(64,(3, 3), activation='relu', padding='same'))
model.add(layers.BatchNormalization())
 model.add(layers.MaxPooling2D(( 2, 2)))
 model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(128,(3, 3), activation='relu', padding='same'))
model.add(layers.BatchNormalization())
 model.add(layers.MaxPooling2D(( 2, 2)))
 model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(256,(3, 3), activation='relu', padding='same'))
model.add(layers.BatchNormalization())
 model.add(layers.MaxPooling2D(( 2, 2)))
 model.add(layers.Dropout(0.2))
model.add(layers.Flatten())
 model.add(layers.Dense(512, activation='relu'))
model.add(layers.Dense(256, activation='relu'))
model.add(layers.Dense(10, activation='softmax'))
model.compile(optimizer=optimizers.Adam(lr=1e-3),
loss='categorical_crossentropy',
metrics=['acc'] )
create_split_categories(test_data)
 fill_missing_values(test_data )<feature_engineering>
lr_reduction = ReduceLROnPlateau(monitor = 'val_acc', factor = 0.5, min_lr = 1e-6)
 checkpoint = ModelCheckpoint('./trainedModel.hdf5',monitor = 'val_acc', mode = "max", save_best_model = True )
train_data['log_prices']= np.log(train_data['price']+1 )<feature_engineering>
history = model.fit(datagen.flow(train_images, train_labels, batch_size=100),
epochs=50,
validation_data=(validation_images, validation_labels),
callbacks = [lr_reduction, checkpoint] )
validation_data['log_prices']= np.log(validation_data['price']+1 )<load_pretrained>
pred = model.predict(test_images )
nltk.download('stopwords' )<string_transform>
pred = np.argmax(pred, axis=-1)
 sub = pd.read_csv('.. /input/digit-recognizer/sample_submission.csv')
 sub['Label'] = pred
sub.head()
stop = stopwords.words('english')
 def remove_stop_words(x):
x = ' '.join([i for i in x.lower().split(' ')if i not in stop])
 return x<feature_engineering>
sub.to_csv('submission.csv', index=False )
<categorify><EOS> 
sub.to_csv('submission.csv', index=False )