Kaggle competition: Digit Recognizer
submission['id'] = id_list
submission.iloc[:,1:] =predictions
submission.head()<save_to_csv>
train_df = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
 test_df = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')
 X_train = train_df.iloc[:, 1:].values.astype('float32')
 y_train = train_df.iloc[:, 0].values.astype('int16')
 X_test = test_df.values.astype('float32' )
final_df = submission.set_index('id')
 final_df.to_csv('Submission.csv' )<set_options>
X_train = X_train / 255
X_test = X_test / 255
y_train = to_categorical(y_train)
 y_train.shape
%%time
%matplotlib inline<define_variables>
seed = 10
np.random.seed(seed )
%%time
train_dir = '.. /input/dog-breed-identification/train'
test_dir ='.. /input/dog-breed-identification/test'<load_from_csv>
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Convolution2D, MaxPooling2D, BatchNormalization, Dense, Flatten, Dropout
%%time
def append_ext(fn):
return fn+".jpg"
traindf = pd.read_csv('.. /input/dog-breed-identification/labels.csv',dtype=str)
 testdf = pd.read_csv('.. /input/dog-breed-identification/sample_submission.csv',dtype=str)
 traindf["id"] = traindf["id"].apply(append_ext)
 testdf["id"] = testdf["id"].apply(append_ext)
<define_variables>
train_x, val_x, train_y, val_y = train_test_split(X_train, y_train, test_size = 0.10, random_state = 42, stratify = y_train )
%%time
train_datagen=ImageDataGenerator(rescale=1./255.,
horizontal_flip = True,
validation_split=0.02
)<define_variables>
model = Sequential()
model.add(Convolution2D(32,(5, 5), activation = 'relu', padding = 'same', input_shape =(28, 28, 1)))
 model.add(MaxPooling2D(pool_size =(2, 2)))
 model.add(Convolution2D(64,(3, 3), activation = 'relu', padding = 'same'))
model.add(MaxPooling2D(pool_size =(2, 2)))
 model.add(Dropout(0.3))
model.add(Convolution2D(128,(3, 3), activation = 'relu', padding = 'same'))
model.add(MaxPooling2D(pool_size =(2, 2)))
 model.add(Dropout(0.25))
model.add(Convolution2D(256,(3, 3), activation = 'relu', padding = 'same'))
model.add(MaxPooling2D(pool_size =(2, 2)))
 model.add(Flatten())
 model.add(Dense(512, activation = 'relu'))
model.add(Dropout(0.25))
model.add(Dense(128, activation = 'relu'))
model.add(Dropout(0.3))
model.add(Dense(10, activation = 'softmax'))
model.compile(optimizer = 'Adam', loss = 'categorical_crossentropy', metrics = ['accuracy'] )
BATCH_SIZE = 32<define_search_space>
history = model.fit(train_x, train_y, epochs = 15, batch_size = 64, validation_data =(val_x, val_y))
<prepare_x_and_y><EOS> 
predictions = model.predict_classes(X_test, verbose = 0)
 submissions = pd.DataFrame({"ImageId": list(range(1,len(predictions)+1)) ,
"Label": predictions})
 submissions.to_csv("digit.csv", index = False, header = True )