Kaggle competition: Digit Recognizer
num_epochs = 50
net_trained = train_model(net, dataloaders_dict,
criterion, optimizer, num_epochs=num_epochs )<load_from_csv>
%matplotlib inline
sample_submission = pd.read_csv(".. /input/nlp-getting-started/sample_submission.csv")
 sample_submission["target"] = ans_list
sample_submission<save_to_csv>
train = pd.read_csv(".. /input/digit-recognizer/train.csv")
 test = pd.read_csv(".. /input/digit-recognizer/test.csv" )
sample_submission.to_csv("submission_plus.csv", index=False )<import_modules>
Y_train = train['label']
X_train = train.drop(labels=['label'], axis=1)
 del train
import pandas as pd
import numpy as np
import spacy
import re
import string<load_from_csv>
X_train = X_train / 255
test = test / 255
train = pd.read_csv(".. /input/nlp-getting-started/train.csv")
 test = pd.read_csv(".. /input/nlp-getting-started/test.csv")
 submission = pd.read_csv(".. /input/nlp-getting-started/sample_submission.csv" )<categorify>
X_train = X_train.values.reshape(-1, 28, 28, 1)
 test = test.values.reshape(-1, 28, 28, 1)
 Y_train = to_categorical(Y_train, num_classes = 10 )
def clean_text(text):

 text = str(text ).lower()
text = re.sub('[%s]' % re.escape(string.punctuation), '', text)
 text = re.sub('
', '', text)
 return text<feature_engineering>
model = Sequential()
model.add(Conv2D(input_shape=(28,28,1), kernel_size=(5,5),
filters=20, activation = "relu"))
model.add(MaxPooling2D(pool_size=(2,2), strides=2, padding='same'))
model.add(Conv2D(kernel_size=(5,5), filters=50, activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2), strides=2, padding='same'))
model.add(Flatten())
 model.add(Dense(500, activation='relu'))
model.add(Dense(10, activation='softmax'))
train["text"] = train["text"].apply(lambda x:clean_text(x))
test["text"] = test["text"].apply(lambda x:clean_text(x))<count_unique_values>
model.compile(optimizer='adam', loss='categorical_crossentropy',
metrics=['accuracy'] )
len(train["keyword"].unique() )<count_unique_values>
history = model.fit(X_train, Y_train, validation_split=0.1,
epochs=100, batch_size=64 )
len(train["location"].unique() )<load_pretrained>
results = model.predict(test)
 results = np.argmax(results,axis = 1)
 results = pd.Series(results,name="Label" )
<define_variables><EOS> 
submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),
results],axis = 1)
 submission.to_csv("cnn_mnist_datagen20210209.csv",index=False )