Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<define_variables>
import pandas as pd
combine = [train_data, test_data]<feature_engineering>
mnist_test = pd.read_csv("/kaggle/input/mnist-fashion-data-classification/mnist_test.csv")
 mnist_train = pd.read_csv("/kaggle/input/mnist-fashion-data-classification/mnist_train.csv")
for dataset in combine:
dataset['Title'] = dataset.Name.str.extract('([A-Za-z]+)\.', expand=False)
 pd.crosstab(train_data['Title'], train_data['Sex'] )<feature_engineering>
sample_submission = pd.read_csv("/kaggle/input/digit-recognizer/sample_submission.csv")
 train = pd.read_csv("/kaggle/input/digit-recognizer/train.csv")
 test = pd.read_csv("/kaggle/input/digit-recognizer/test.csv" )
for dataset in combine:
dataset['Title'] = dataset['Title'].replace(['Lady', 'Countess','Capt', 'Col',\
	'Don', 'Dr', 'Major', 'Rev', 'Sir', 'Jonkheer', 'Dona'], 'Rare')
 dataset['Title'] = dataset['Title'].replace('Mlle', 'Miss')
 dataset['Title'] = dataset['Title'].replace('Ms', 'Miss')
 dataset['Title'] = dataset['Title'].replace('Mme', 'Mrs')
 train_data[['Title', 'Survived']].groupby(['Title'], as_index=False ).mean()<categorify>
test['dataset'] = 'test'
title_mapping = {"Mr": 1, "Miss": 2, "Mrs": 3, "Master": 4, "Rare": 5}
for dataset in combine:
dataset['Title'] = dataset['Title'].map(title_mapping)
 dataset['Title'] = dataset['Title'].fillna(0)
 train_data.head()<concatenate>
train['dataset'] = 'train'
train_data = train_data.drop(['Name', 'PassengerId'], axis=1)
 test_data = test_data.drop(['Name'], axis=1)
 combine = [train_data, test_data]
train_data.shape, test_data.shape<categorify>
dataset = pd.concat([train.drop('label', axis=1), test] ).reset_index()
for dataset in combine:
dataset['Sex'] = dataset['Sex'].map({'female': 1, 'male': 0} ).astype(int)
 train_data.head()<define_variables>
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
guess_ages = np.zeros(( 2,3))
guess_ages<find_best_params>
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
for dataset in combine:
for i in range(0, 2):
for j in range(0, 3):
guess_df = dataset[(dataset['Sex'] == i)& \ 
(dataset['Pclass'] == j+1)]['Age'].dropna()
age_guess = guess_df.median()
guess_ages[i,j] = int(age_guess/0.5 + 0.5)* 0.5
for i in range(0, 2):
for j in range(0, 3):
dataset.loc[(dataset.Age.isnull())&(dataset.Sex == i)&(dataset.Pclass == j+1),\
'Age'] = guess_ages[i,j]
dataset['Age'] = dataset['Age'].astype(int)
 train_data.head()<sort_values>
for i in range(len(idx_mnist)) :
if dataset_from[i] == 'test':
sample_submission.loc[original_idx[i], 'Label'] = labels[idx_mnist[i]]
<feature_engineering><EOS> 
sample_submission.to_csv('submission.csv', index=False )