Kaggle competition: Digit Recognizer
preds_set=pd.DataFrame({'preds_high':preds_high})
 preds_set['preds']=preds
preds_set['preds_low']=preds_low
preds_set['sigma_pred']=abs(preds_set['preds_high']-preds_set['preds_low'])
 preds_set.reset_index(inplace=True,drop=True)
 preds_set<save_to_csv>
print(K.image_data_format() )
submission=pd.DataFrame({'Patient_Week':test['Patient_Week'],'FVC': preds_set['preds'],'Confidence':preds_set['sigma_pred']})
 submission['FVC']=submission['FVC'].apply(lambda x: round(x, 4)) /1
submission['Confidence']=submission['Confidence'].apply(lambda x: round(x, 4))
submission.to_csv('submission.csv',index=False)
 submission.head()<load_pretrained>
( x_train, y_train),(x_test, y_test)= mnist.load_data()
train_arc = zipfile.ZipFile('/kaggle/input/whats-cooking/train.json.zip','r')
 train_data = pd.read_json(train_arc.read('train.json'))
train_data.head()<load_pretrained>
y_train = to_categorical(y_train, num_classes = 10)
 y_test = to_categorical(y_test, num_classes=10 )
test_arc = zipfile.ZipFile('/kaggle/input/whats-cooking/test.json.zip','r')
 test_data = pd.read_json(test_arc.read('test.json'))
test_data.head()<count_values>
x_train.astype('float32')
 x_test.astype('float32' )
train_data['cuisine'].value_counts()<feature_engineering>
x_train = x_train/255
x_test = x_test/255
train_ingredients_count = {}
for i in range(len(train_data)) :
for j in train_data['ingredients'][i]:
if j in train_ingredients_count.keys() :
train_ingredients_count[j]+=1
else:
train_ingredients_count[j] = 1<count_values>
input_shape =(28,28,1)
 model = Sequential()
model.add(Conv2D(96,(3, 3),
padding='Same',
activation='relu',
input_shape=input_shape))
model.add(BatchNormalization())
 model.add(Conv2D(96,(3, 3),
padding='Same',
activation='relu'))
model.add(BatchNormalization())
 model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Conv2D(192,(3,3), activation='relu', padding='same'))
model.add(BatchNormalization())
 model.add(Conv2D(256,(3,3), activation='relu', padding='same'))
model.add(BatchNormalization())
 model.add(MaxPooling2D(pool_size=(2,2)))
 model.add(Conv2D(256,(3,3), activation='relu', padding='same'))
model.add(BatchNormalization())
 model.add(Conv2D(256,(3,3), activation='relu', padding='same'))
model.add(Flatten())
 model.add(Dense(256, activation='relu'))
model.add(BatchNormalization())
 model.add(Dropout(0.25))
model.add(Dense(units=10, activation='softmax'))
train_ingredients_count['romaine lettuce']<feature_engineering>
call_back = keras.callbacks.EarlyStopping(monitor='val_acc', min_delta=0, patience=5, verbose=0, restore_best_weights=True)
 reduce_lr = keras.callbacks.ReduceLROnPlateau(monitor='val_acc',
factor=0.25,
verbose=1,
patience=2,
min_lr=0.000001 )
test_ingredients_count = {}
for i in range(len(test_data)) :
for j in test_data['ingredients'][i]:
if j in test_ingredients_count.keys() :
test_ingredients_count[j]+=1
else:
test_ingredients_count[j] = 1<define_variables>
model.compile(loss='categorical_crossentropy',
optimizer=keras.optimizers.Adam(lr=0.001),
metrics=['accuracy'])
 train_datagen = ImageDataGenerator(shear_range=0.2,
zoom_range=0.2,
featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
height_shift_range=.1,
rotation_range=10,
width_shift_range=.1)
 train_datagen.fit(x_train)
 history = model.fit_generator(
 train_datagen.flow(x_train,y_train, batch_size=128),
steps_per_epoch=x_train.shape[0] // 128,
epochs=32,
validation_data=(x_test,y_test),callbacks=[call_back, reduce_lr] )
train_ingred_miss = []
for i in test_ingredients_count.keys() :
if i not in train_ingredients_count.keys() :
train_ingred_miss.append(i )<feature_engineering>
xtest = pd.read_csv(".. /input/test.csv" )
<define_variables><EOS> 
submission = model.predict(xtest)
 submission = np.argmax(submission, axis = 1)
 submission = pd.Series(submission,name="Label")
 submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),submission],axis = 1)
 submission.to_csv("submission.csv",index=False )