Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<prepare_x_and_y>
plt.style.use('ggplot')
train_X = titanic_data.drop(['PassengerId', 'Survived', 'Name', 'Ticket', 'Cabin'], axis = 1)
 test_X = titanic_data_test.drop(['PassengerId', 'Name', 'Ticket', 'Cabin'], axis = 1)
 train_y = titanic_data.Survived<data_type_conversions>
train_df = pd.read_csv(".. /input/digit-recognizer/train.csv")
 test_df = pd.read_csv(".. /input/digit-recognizer/test.csv" )
train_X = train_X.fillna({'Age': train_X.Age.median() , 'Fare': train_X.Fare.median() })
 test_X = test_X.fillna({'Age': test_X.Age.median() , 'Fare': test_X.Fare.median() } )<categorify>
X =(train_df.iloc[:,1:].values ).astype('float32')
 Y = train_df.iloc[:,0].values.astype('int32')
 test = test_df.values.astype('float32' )
train_X = pd.get_dummies(train_X)
 test_X = pd.get_dummies(test_X )<count_missing_values>
X = X.reshape(X.shape[0], 28, 28, 1)
 Y = to_categorical(Y)
 test = test.reshape(test.shape[0], 28, 28, 1 )
test_X.isnull().sum()<choose_model_class>
X = X.astype("float32")/ 255
test = test.astype("float32")/ 255
clf_rf = RandomForestClassifier(n_jobs=-1,
criterion='entropy',
min_samples_split=2,
min_samples_leaf=1)
 parameters = {'n_estimators': range(3,40), 'max_depth': range(1,10)}
grid_search_cv_clf = GridSearchCV(clf_rf, parameters, cv = 5 )<train_on_grid>
X_train, X_val, Y_train, Y_val = train_test_split(X, Y, test_size = 0.1, random_state=0 )
grid_search_cv_clf.fit(train_X,train_y )<find_best_params>
datagen = ImageDataGenerator(
 featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
rotation_range=10,
zoom_range = 0.1,
width_shift_range=0.1,
height_shift_range=0.1,
horizontal_flip=False,
vertical_flip=False)
 datagen.fit(X_train )
best_clf = grid_search_cv_clf.best_estimator_
grid_search_cv_clf.best_params_<compute_test_metric>
model = Sequential()
model.add(Conv2D(32, kernel_size = 4, activation="relu", input_shape=(28,28,1)))
 model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Conv2D(64, kernel_size = 3, activation="relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Conv2D(64, kernel_size = 2, activation="relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Flatten())
 model.add(Dense(128, activation="relu"))
model.add(Dropout(0.25))
model.add(Dense(10, activation='softmax'))
model.compile(loss="mean_squared_error", optimizer="rmsprop", metrics=['accuracy'])
 model.summary()
best_clf.score(train_X, train_y )<save_to_csv>
learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc',
patience=3,
verbose=1,
factor=0.5,
min_lr=0.00001 )
test_y = best_clf.predict(test_X)
 test_ID= titanic_data_test.PassengerId
submission = pd.DataFrame({ "PassengerId": test_ID, "Survived": test_y})
 submission.to_csv('./gender_submission.csv', index=False )<import_modules>
batch_size = 100
epochs = 30
hist = model.fit_generator(datagen.flow(X_train,Y_train, batch_size=batch_size),
epochs = epochs, validation_data =(X_val,Y_val),
verbose = 2, steps_per_epoch=X_train.shape[0] // batch_size
, callbacks=[learning_rate_reduction] )
import numpy as np
import pandas as pd
from catboost import CatBoostClassifier
from sklearn.model_selection import train_test_split
import re
import matplotlib.pyplot as plt
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import accuracy_score
from sklearn.metrics import mean_absolute_error
from sklearn.ensemble import RandomForestClassifier
from catboost import CatBoostClassifier
from sklearn.preprocessing import OneHotEncoder
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from sklearn.linear_model import LogisticRegression 
<load_from_csv>
Y_pred_classes = np.argmax(pred,axis = 1)
 Y_true = np.argmax(Y_val,axis = 1 )
train_data = pd.read_csv("/kaggle/input/titanic/train.csv")
 train_data.info()<load_from_csv>
results = model.predict(test)
 results = np.argmax(results,axis = 1)
 results = pd.Series(results,name="Label" )
<feature_engineering><EOS> 
submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1)
 submission.to_csv("cnn_mnist_datagen.csv",index=False )