Kaggle competition: Digit Recognizer
data['MasVnrType'] = data['MasVnrType'].replace(np.nan, data.MasVnrType.value_counts().index[0])
 data['Electrical'] = data['Electrical'].replace(np.nan, data.Electrical.value_counts().index[0] )<categorify>
import keras
import plotly.express as px
from keras import backend as K
from keras.optimizers import Adam
import plotly.graph_objects as go
import plotly.figure_factory as ff
from keras.models import Sequential
from keras.layers import Activation
from keras.metrics import categorical_crossentropy
from sklearn.model_selection import train_test_split
from keras.preprocessing.image import ImageDataGenerator
from keras.layers import Dense,Flatten,Dropout,Conv2D,MaxPool2D
data = pd.get_dummies(data)
 tcol = data.columns<create_dataframe>
df_train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
 df_train.describe()
diffCols = [x for x in columns if x not in tcol]
data[diffCols] = 0
data = pd.DataFrame(data, columns = columns)
 data.drop(['SalePrice'], axis=1, inplace=True )<count_missing_values>
df_train_x = df_train.drop('label',axis =1)
 df_train_y = df_train[['label']]
for col in data.columns:
if(data[col].isna().sum() > 0):
print(col )<predict_on_test>
np_train_x = df_train_x.to_numpy().reshape(-1,28,28,1)
 np_train_y = df_train_y.to_numpy()
x_train,x_test,y_train,y_test = train_test_split(np_train_x, np_train_y,test_size=0.10,random_state=42 )
data = inScale.transform(data)
 y = vr.predict(data)
 Predicted_Values = outScale.inverse_transform(y.reshape(-1, 1))
Predicted_Values.shape<create_dataframe>
datagen = ImageDataGenerator(
 featurewise_center=False,
featurewise_std_normalization=False,
width_shift_range=0.1,
height_shift_range=0.1,
zoom_range=0.1,
horizontal_flip=False,
vertical_flip=False,
brightness_range = [0.8,1.])
 datagen.fit(x_train )
result = pd.DataFrame(id_values, columns=['Id'])
 result['SalePrice'] = Predicted_Values
result<save_to_csv>
model = Sequential()
model.add(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu', input_shape =(28,28,1)))
 model.add(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu'))
model.add(MaxPool2D(pool_size=(2,2)))
 model.add(Dropout(0.25))
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(MaxPool2D(pool_size=(2,2), strides=(2,2)))
 model.add(Dropout(0.25))
model.add(Flatten())
 model.add(Dense(256, activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(10, activation = "softmax"))
model.compile(Adam(lr = 0.0001),loss = 'sparse_categorical_crossentropy',
metrics = ['accuracy'])
 keras.utils.plot_model(model, "Neural_Network.png", show_shapes=True )
result.to_csv("Result.csv", index=False )<install_modules>
model.fit_generator(datagen.flow(x_train,y_train,batch_size = 30),
steps_per_epoch = 1000,validation_data =(x_test,y_test),
epochs = 50, verbose = 2 )
!pip install.. /input/python-datatable/datatable-0.11.0-cp37-cp37m-manylinux2010_x86_64.whl > /dev/null 2>&1<import_modules>
df_test = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')
 df_test.describe()
import pandas as pd
import numpy as np
import datatable as dt
from sklearn.metrics import roc_auc_score
from matplotlib import pyplot as plt
import riiideducation
from collections import defaultdict
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import StandardScaler
import tensorflow as tf
from tensorflow.keras import Sequential
from tensorflow.keras.layers import BatchNormalization,Dropout,Dense,Flatten,Conv1D
from tensorflow.keras.optimizers import Adam
from keras.metrics import BinaryAccuracy
from keras import backend as K<define_variables>
np_test = df_test.to_numpy().reshape(-1,28,28,1 )
data_types_dict = {
'user_id': 'int32',
'content_id': 'int16',
'answered_correctly': 'int8',
'prior_question_elapsed_time': 'float32',
'prior_question_had_explanation': 'bool'
}
target = 'answered_correctly'<load_from_csv>
df_test['label'] = model.predict_classes(np_test )
<groupby><EOS> 
df_test[['ImageId','label']].to_csv('submission.csv',index=False )