Kaggle competition: Digit Recognizer
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from lightgbm import LGBMRegressor
from xgboost import XGBRegressor
import sklearn.metrics as metrics
import math<load_from_csv>
train_df = pd.read_csv('.. /input/train.csv')
 test_df = pd.read_csv('.. /input/test.csv')
 train_df.head(5 )
sample_submission = pd.read_csv(".. /input/house-prices-advanced-regression-techniques/sample_submission.csv")
 test = pd.read_csv(".. /input/house-prices-advanced-regression-techniques/test.csv")
 train = pd.read_csv(".. /input/house-prices-advanced-regression-techniques/train.csv")
 c_test = test.copy()
c_train = train.copy()<concatenate>
train = train_df.values
test = test_df.values
trainX = train[:, 1:].reshape(train.shape[0], 28, 28, 1)
 trainX = trainX.astype(float)
 trainX /= 255.0
c_train['train'] = 1
c_test['train'] = 0
df = pd.concat([c_train, c_test], axis=0,sort=False )<create_dataframe>
trainY = kutils.to_categorical(train[:, 0])
 class_num = trainY.shape[1]
print(class_num )
NAN = [(c, df[c].isna().mean() *100)for c in df]
NAN = pd.DataFrame(NAN, columns=["column_name", "percentage"] )<sort_values>
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D
NAN = NAN[NAN.percentage > 50]
NAN.sort_values("percentage", ascending=False )<drop_column>
model = Sequential()
model.add(Conv2D(16,(3, 3), padding='same', activation='relu', input_shape=(28, 28, 1)))
 model.add(Conv2D(32,(5, 5), padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=(3, 3), strides=(1, 1)))
 model.add(Conv2D(32,(3, 3), padding='same', activation='relu'))
model.add(Conv2D(64,(5, 5), padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=(3, 3), strides=(1, 1)))
 model.add(Conv2D(64,(3, 3), padding='same', activation='relu'))
model.add(Conv2D(128,(5, 5), padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
 model.add(Conv2D(128,(3, 3), padding='same', activation='relu'))
model.add(Conv2D(256,(5, 5), padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
 model.add(Flatten())
 model.add(Dense(128, activation='sigmoid'))
model.add(Dense(class_num, activation='softmax'))
model.compile(loss="categorical_crossentropy", optimizer="sgd", metrics=["accuracy"] )
df = df.drop(['Alley','PoolQC','Fence','MiscFeature'],axis=1 )<count_missing_values>
model.fit(trainX, trainY, batch_size=64, epochs=100, verbose=2 )
null_counts = object_columns_df.isnull().sum()
print("Number of null values in each column:
{}".format(null_counts))<data_type_conversions>
testX = test.reshape(test.shape[0], 28, 28, 1)
 testX = testX.astype(float)
 testX /= 255.0
yPred = model.predict_classes(testX)
 np.savetxt('mnist-cnn.csv', np.c_[range(1,len(yPred)+1),yPred], delimiter=',', header = 'ImageId,Label', comments = '', fmt='%d' )