Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<init_hyperparams>
def load_data() :
data_train = pd.read_csv('.. /input/digit-recognizer/train.csv')
 X_test = pd.read_csv('/kaggle/input/digit-recognizer/test.csv' ).values.reshape(-1,28,28,1)
 sample_submission = pd.read_csv('/kaggle/input/digit-recognizer/sample_submission.csv')
 X = data_train.iloc[:,1:].values.reshape(-1,28,28,1)
 y = data_train.iloc[:,0].values
np.random.seed(2)
 np.random.shuffle(X)
 np.random.seed(2)
 np.random.shuffle(y)
 number_train = int(0.9*(X.shape[0]))
X_train = X[:number_train]
y_train = y[:number_train]
X_dev = X[number_train:]
y_dev=y[number_train:]
mean = X_train.mean()
std = X_train.std()
X_train =(X_train-mean)/std
X_dev =(X_dev-mean)/std
X_test =(X_test-mean)/std
return X_train, y_train, X_dev,y_dev, X_test
def submit(model):
pred=model.predict(X_test ).argmax(axis=1)
 df = pd.DataFrame({"ImageId": list(range(1,pred.shape[0]+1)) ,
"Label": pred})
 df.to_csv("submission_neuralnet.csv",index=False,header=True)
 X_train, y_train, X_dev, y_dev, X_test = load_data()
flag_lgbm=True
clfs = list()
params = {
'num_leaves': 350,
'max_bin':700,
'min_child_weight': 0.03454472573214212,
'feature_fraction': 0.58,
'bagging_fraction': 0.58,
'objective': 'binary',
'max_depth': -1,
'learning_rate': 0.05,
"boosting_type": "gbdt",
"bagging_seed": 11,
"metric": 'auc',
"verbosity": -1,
'reg_alpha': 0.3899927210061127,
'reg_lambda': 0.6485237330340494,
'random_state': 47
}
trains=list()
valids=list()
num=1
for i in range(0,num):
train_df_clf=train_df.sample(n=15000*1000)
 print('sample end')
 del train_df
users=train_df_clf['user_id'].drop_duplicates()
users=users.sample(frac=0.025)
 users_df=pd.DataFrame()
users_df['user_id']=users.values
valid_df_newuser = pd.merge(train_df_clf, users_df, on=['user_id'], how='inner',right_index=True)
 del users_df
del users
gc.collect()
train_df_clf.drop(valid_df_newuser.index, inplace=True)
 train_df_clf = pd.merge(train_df_clf, questions_df, on='content_id', how='left',right_index=True)
 valid_df_newuser = pd.merge(valid_df_newuser, questions_df, on='content_id', how='left',right_index=True)
 valid_df=train_df_clf.sample(frac=0.09)
 train_df_clf.drop(valid_df.index, inplace=True)
 valid_df = valid_df.append(valid_df_newuser)
 del valid_df_newuser
gc.collect()
trains.append(train_df_clf)
 valids.append(valid_df)
 print('valid_df length：',len(valid_df)) 
<drop_column>
model = Sequential([Conv2D(128,3, activation='relu',input_shape=(28,28,1)) ,
Conv2D(128,3, activation='relu'),
MaxPool2D() ,
Conv2D(128,3, activation='relu'),
BatchNormalization() ,
Dropout(0.25),
Conv2D(128,3, activation='relu'),
MaxPool2D() ,
Flatten() ,
Dense(512,activation='relu'),
BatchNormalization() ,
Dropout(0.25),
Dense(256,activation='relu'),
Dense(10,activation='softmax')
 ])
 model.compile(RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0),
loss=tf.keras.losses.SparseCategoricalCrossentropy() ,metrics=['sparse_categorical_accuracy'])
 lr_reducer = ReduceLROnPlateau(monitor='val_sparse_categorical_accuracy', patience=3,verbose=1,factor=0.5,min_lr=0.00001)
 plot_model(model, show_shapes=True, show_layer_names=True )
del train_df_clf
del valid_df
gc.collect()<prepare_x_and_y>
data_gen = ImageDataGenerator(rotation_range=15,zoom_range = 0.1,width_shift_range=0.1,height_shift_range=0.1)
 data_gen.fit(X_train)
 fig, axs = plt.subplots(3,5)
 axs[0,0].imshow(X_train[0].squeeze())
 axs[0,1].imshow(X_train[1].squeeze())
 result = data_gen.flow(X_train[[0,1]],y_train[[0,1]],batch_size=2)
 i=0
for x,y in result:
axs[1,i].imshow(x[0].squeeze())
 axs[2,i].imshow(x[1].squeeze())
 i=i+1
if i == 5:
break
<data_type_conversions><EOS> 
t = time.time()
batch_size=2*86
history = model.fit_generator(data_gen.flow(X_train,y_train,batch_size=batch_size),epochs=15, validation_data=(X_dev,y_dev),
steps_per_epoch=np.ceil(X_train.shape[0] / batch_size),use_multiprocessing=True,
callbacks=[lr_reducer])
 print("Time {}".format(time.time() -t))
submit(model )