Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<count_missing_values>
import tensorflow as tf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
null_counts = object_columns_df.isnull().sum()
print("Number of null values in each column:
{}".format(null_counts))<data_type_conversions>
training_images = pd.read_csv('.. /input/train.csv')
 test_images = pd.read_csv('.. /input/test.csv')
 training_labels = training_images['label']
training_images = training_images.drop(labels = ['label'], axis = 1)
 training_images = training_images.values.reshape(42000, 28, 28, 1)
 test_images = test_images.values.reshape(28000, 28, 28, 1)
 training_images = training_images / 255.0
test_images = test_images / 255.0
columns_None = ['BsmtQual','BsmtCond','BsmtExposure','BsmtFinType1','BsmtFinType2','GarageType','GarageFinish','GarageQual','FireplaceQu','GarageCond']
object_columns_df[columns_None]= object_columns_df[columns_None].fillna('None' )<categorify>
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(32,(3, 3), activation='relu', input_shape=(28, 28, 1)) ,
tf.keras.layers.Conv2D(32,(3, 3), activation='relu', input_shape=(28, 28, 1)) ,
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Dropout(0.25),
tf.keras.layers.Conv2D(64,(3, 3), activation='relu', input_shape=(28, 28, 1)) ,
tf.keras.layers.Conv2D(64,(3, 3), activation='relu', input_shape=(28, 28, 1)) ,
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Dropout(0.25),
tf.keras.layers.Flatten() ,
tf.keras.layers.Dense(256, activation='relu'),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(10, activation='softmax')
 ])
 model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
 model.summary()
model.fit(training_images, training_labels, epochs=15 )
columns_with_lowNA = ['MSZoning','Utilities','Exterior1st','Exterior2nd','MasVnrType','Electrical','KitchenQual','Functional','SaleType']
object_columns_df[columns_with_lowNA] = object_columns_df[columns_with_lowNA].fillna(object_columns_df.mode().iloc[0] )<count_missing_values>
predict = model.predict(test_images)
 predict_array = np.argmax(predict, axis=1)
 predict_array = predict_array.tolist()
null_counts = numerical_columns_df.isnull().sum()
print("Number of null values in each column:
{}".format(null_counts))<feature_engineering>
image_set = pd.read_csv('.. /input/test.csv')
 for i in np.random.randint(28001, size=10):
print("Predicted : " + str(predict_array[i]))
image = image_set.iloc[i].values.reshape(28, 28)
 plt.imshow(image, cmap='gray')
 plt.show()
numerical_columns_df['GarageYrBlt'] = numerical_columns_df['GarageYrBlt'].fillna(numerical_columns_df['YrSold']-35)
 numerical_columns_df['LotFrontage'] = numerical_columns_df['LotFrontage'].fillna(68 )<drop_column>
data_to_submit = pd.DataFrame({
'ImageId': range(1, 28001),
'Label': predict_array
})
 data_to_submit.to_csv('csv_to_submit3.csv', index = False )