Kaggle competition: Digit Recognizer
result=pd.read_csv('/kaggle/input/GiveMeSomeCredit/sampleEntry.csv')
 result['Probability'] = pre_y2
result.to_csv('./submit.csv',index=False)
 reload = pd.read_csv('./submit.csv')
 reload<load_from_csv>
train = pd.read_csv("/kaggle/input/digit-recognizer/train.csv")
 test = pd.read_csv("/kaggle/input/digit-recognizer/test.csv" )
train = pd.read_csv('/kaggle/input/GiveMeSomeCredit/cs-training.csv',index_col=0)
 test = pd.read_csv('/kaggle/input/GiveMeSomeCredit/cs-test.csv',index_col=0)
 sample = pd.read_csv('/kaggle/input/GiveMeSomeCredit/sampleEntry.csv')
 train.shape, test.shape, sample.shape<count_missing_values>
X = train.drop("label", axis = 1)
 y = train["label"]
train.MonthlyIncome.fillna(train_default_dict['MonthlyIncome'][0], inplace=True)
 test.MonthlyIncome.fillna(train_default_dict['MonthlyIncome'][0], inplace=True)
 train.NumberOfDependents.fillna(test_default_dict['NumberOfDependents'][1], inplace=True)
 test.NumberOfDependents.fillna(test_default_dict['NumberOfDependents'][1], inplace=True)
 train.isnull().sum() , '*'*50, test.isnull().sum() 
<prepare_x_and_y>
X_train, X_test, y_train, y_test = train_test_split(X,
y,
test_size = 0.25 )
X_train = train.iloc[:,1:].values
y_train = train.iloc[:,0].values
X_test = test.iloc[:,1:].values
X_train.shape, y_train.shape, X_test.shape<normalization>
X_train = X_train / 255
X_test = X_test / 255
test = test / 255
train_scaler = preprocessing.StandardScaler().fit(X_train)
 print(train_scaler.mean_ , '
'+'-'*50+'
', train_scaler.scale_)
 print('='*50)
 test_scaler = preprocessing.StandardScaler().fit(X_test)
 print(test_scaler.mean_ , '
'+'-'*50+'
', test_scaler.scale_)
<normalization>
y_train = to_categorical(y_train)
 y_test = to_categorical(y_test )
X_train_scaled = train_scaler.transform(X_train)
 X_test_scaled = test_scaler.transform(X_test)
 X_train_scaled.mean(axis=0), X_train_scaled.std(axis=0), X_test_scaled.mean(axis=0), X_test_scaled.std(axis=0)
<split>
X_train = X_train.values.reshape(-1, 28, 28, 1)
 X_test = X_test.values.reshape(-1, 28, 28, 1)
 test = test.values.reshape(-1, 28, 28, 1 )
X_learn, X_valid, y_learn, y_valid = train_test_split(X_train_scaled, y_train, random_state=0)
 X_learn.shape, X_valid.shape, y_learn.shape, y_valid.shape<import_modules>
model = Sequential()
model.add(Conv2D(64, kernel_size =(3, 3), activation = "relu", padding = "same", input_shape =(28, 28, 1)))
 model.add(BatchNormalization())
 model.add(Conv2D(64, kernel_size =(3, 3), activation = "relu", padding = "same"))
model.add(BatchNormalization())
 model.add(MaxPooling2D(pool_size =(2, 2)))
 model.add(Dropout(0.2))
model.add(Conv2D(128, kernel_size =(3, 3), activation = "relu", padding = "same"))
model.add(BatchNormalization())
 model.add(Conv2D(128, kernel_size =(3, 3), activation = "relu", padding = "same"))
model.add(BatchNormalization())
 model.add(MaxPooling2D(pool_size =(2, 2)))
 model.add(Dropout(0.3))
model.add(Conv2D(256, kernel_size =(3, 3), activation = "relu", padding = "same"))
model.add(BatchNormalization())
 model.add(Conv2D(256, kernel_size =(3, 3), activation = "relu", padding = "same"))
model.add(BatchNormalization())
 model.add(MaxPooling2D(pool_size =(2, 2)))
 model.add(Dropout(0.4))
model.add(Flatten())
 model.add(Dense(512, activation = "relu"))
model.add(Dense(10, activation = "softmax"))
model.compile(optimizer = tf.keras.optimizers.RMSprop(lr = 0.0001, centered = True, momentum = 0),
loss = "categorical_crossentropy",
metrics = ["accuracy"])
 history = model.fit(X_train,
y_train,
validation_split = 0.2,
epochs = 80,
batch_size = 64,
shuffle = True,
verbose = 0)
 print("Test score :" + str(model.evaluate(X_test, y_test)))
 print("")
 print("Train score :" + str(model.evaluate(X_train, y_train)))
 print(model.summary() )
from sklearn.metrics import roc_auc_score<choose_model_class>
y_sub = pd.Series(np.argmax(model.predict(test), axis = 1), name = "Label")
 submission = pd.concat([pd.Series(range(1, 28001), name = "ImageId"), y_sub], axis = 1)
 submission.to_csv("submission.csv", index = False)
 submission.head()