Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<compute_test_metric>
%matplotlib inline
model = ridge = Ridge()
Ridge_preds, y_test = run_model(model, matrix_list=sparse_matrix_list)
 print("rmsle: "+str(rmsle(np.expm1(y_test), np.expm1(Ridge_preds))))<load_from_csv>
test = pd.read_csv("/kaggle/input/digit-recognizer/test.csv" )
submission = pd.read_csv('sample_submission_stg2.csv')
 submission
submission.loc[:, 'price'] = preds
submission<save_to_csv>
( x_train, y_train),(x_test, y_test)= mnist.load_data()
submission.to_csv('submission.csv', index=False )<save_to_csv>
pred_train = x_train.reshape(x_train.shape[0], 28, 28, 1)
 pred_test = x_test.reshape(x_test.shape[0], 28, 28, 1)
 pred_train = pred_train.astype('float32')
 pred_test = pred_test.astype('float32')
 pred_train /=255
pred_test /=255
class_train = np_utils.to_categorical(y_train, 10)
 class_test = np_utils.to_categorical(y_test, 10 )
submission.to_csv('submission.csv', index=False )<load_pretrained>
classifier = Sequential()
classifier.add(Conv2D(32,(3,3), input_shape =(28,28,1), activation = 'relu'))
classifier.add(BatchNormalization())
 classifier.add(MaxPooling2D(pool_size =(2,2)))
 classifier.add(Conv2D(32,(3,3), activation = 'relu'))
classifier.add(BatchNormalization())
 classifier.add(MaxPooling2D(pool_size =(2,2)))
 classifier.add(Flatten())
 classifier.add(Dense(units = 128, activation = 'relu'))
classifier.add(Dropout(0.2))
classifier.add(Dense(units = 128, activation = 'relu'))
classifier.add(Dropout(0.2))
classifier.add(Dense(units = 10, activation = 'softmax'))
classifier.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics=['accuracy'] )
!apt-get install p7zip
!p7zip -d -f -k /kaggle/input/mercari-price-suggestion-challenge/train.tsv.7z<compute_test_metric>
classifier.fit(pred_train,
class_train,
batch_size = 128,
epochs = 30,
validation_data =(pred_test, class_test))
def rmsle(y, y_pred):
assert len(y)== len(y_pred)
 to_sum = [(math.log(y_pred[i] + 1)- math.log(y[i] + 1)) ** 2.0 for i,pred in enumerate(y_pred)]
return(sum(to_sum)*(1.0/len(y)))** 0.5 
<load_from_csv>
X_test = test/255
X_test = X_test.values
X_test = X_test.reshape(X_test.shape[0], 28, 28, 1 ).astype('float32')
 pred = classifier.predict(X_test)
 pred.shape
print("Loading data...")
 train = pd.read_table("train.tsv", sep="\t")
 test = pd.read_csv(".. /input/mercari-price-suggestion-challenge/test_stg2.tsv.zip" , sep='\t')
 print(train.shape)
 print(test.shape )<categorify>
sample_submit = pd.read_csv("/kaggle/input/digit-recognizer/sample_submission.csv")
 sample_submit.head()
<categorify><EOS> 
y_pred = pred.argmax(axis=1)
 ImageID = np.arange(len(y_pred)) +1
submit = pd.DataFrame([ImageID,y_pred] ).T
submit.rename(columns = {0:'ImageId', 1:'Label'})
 submit.to_csv('submission.csv', header = ['ImageId', 'Label' ], index = None )