Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<choose_model_class>
mnist_test = pd.read_csv(".. /input/mnist-in-csv/mnist_test.csv")
 mnist_train = pd.read_csv(".. /input/mnist-in-csv/mnist_train.csv" )
num_pipeline = Pipeline([ 
("imputer", SimpleImputer(strategy = "median")) , 
("scaler", StandardScaler()),
] )<categorify>
sample_submission = pd.read_csv(".. /input/digit-recognizer/sample_submission.csv")
 test = pd.read_csv(".. /input/digit-recognizer/test.csv")
 train = pd.read_csv(".. /input/digit-recognizer/train.csv" )
cat_pipeline = Pipeline([ 
("imputer", SimpleImputer(strategy = "most_frequent")) , 
("cat_encoder", OneHotEncoder(sparse = False)) ,
] )<feature_engineering>
test['dataset'] = 'test'
preprocess_pipeline = ColumnTransformer([ 
("num", num_pipeline, num_attribs), 
("cat", cat_pipeline, cat_attribs),
] )<normalization>
train['dataset'] = 'train'
X_train = preprocess_pipeline.fit_transform(train_data[num_attribs + cat_attribs])
 X_train<prepare_x_and_y>
dataset = pd.concat([train.drop('label', axis=1), test] ).reset_index()
y_train = train_data["Survived"]<train_model>
mnist = pd.concat([mnist_train, mnist_test] ).reset_index(drop=True)
 labels = mnist['label'].values
mnist.drop('label', axis=1, inplace=True)
 mnist.columns = cols
forest_clf = RandomForestClassifier(n_estimators = 100, random_state = 42)
 forest_clf.fit(X_train, y_train )<predict_on_test>
idx_mnist = mnist.sort_values(by=list(mnist.columns)).index
dataset_from = dataset.sort_values(by=list(mnist.columns)) ['dataset'].values
original_idx = dataset.sort_values(by=list(mnist.columns)) ['index'].values
X_test = preprocess_pipeline.fit_transform(test_data[num_attribs + cat_attribs])
 y_pred = forest_clf.predict(X_test )<compute_train_metric>
for i in range(len(idx_mnist)) :
if dataset_from[i] == 'test':
sample_submission.loc[original_idx[i], 'Label'] = labels[idx_mnist[i]]
forest_scores = cross_val_score(forest_clf, X_train, y_train, cv = 10)
 forest_scores.mean()<compute_train_metric>
sample_submission.to_csv('submission.csv', index=False )