Kaggle competition: MLH - Pokemon Challenge
train_df.Embarked.value_counts()<count_values>
battles = pd.read_csv('.. /input/battles.csv')
 pokemon = pd.read_csv('.. /input/pokemon.csv')
 test = pd.read_csv('.. /input/test.csv')
 pokemon = pokemon.drop(columns='Name', errors='ignore')
 pokemon.loc[:, 'Type 1'] = pokemon.loc[:, 'Type 1'].fillna('None')
 pokemon.loc[:, 'Type 2'] = pokemon.loc[:, 'Type 2'].fillna('None')
 pokemon.Legendary = pokemon.Legendary.astype(int)
 data = pd.merge(battles, pokemon, left_on='First_pokemon' ,right_on='
data = pd.merge(data, pokemon, left_on='Second_pokemon',right_on='
data = data.sort_values(['battle_number'])
 data = data.drop(columns=['
data = data.iloc[:, 3:]
data.head()
train_df.Sex.value_counts()<categorify>
tout = pd.merge(test, pokemon, left_on='First_pokemon' ,right_on='
tout = pd.merge(tout, pokemon, left_on='Second_pokemon',right_on='
tout = tout.sort_values(['battle_number'])
 tout = tout.drop(columns=['
tout = tout.iloc[:, 3:]
tout.head()
embarkedMap = {"S": 0, "C": 1, "Q": 2}
genderMap = {"male": 0, "female": 1}
for dataset in data:
dataset['Embarked'] = dataset['Embarked'].map(embarkedMap)
 dataset['Sex'] = dataset['Sex'].map(genderMap )<feature_engineering>
TEST_SIZE = 0.01
tr_idx, ts_idx = train_test_split(range(len(battles)) , test_size=TEST_SIZE)
 cat_names = ['Generation_A', 'Generation_B', 'Type 1_A', 'Type 1_B', 'Type 2_A', 'Type 2_B', 'Legendary_A', 'Legendary_B']
procs = [Categorify, Normalize]
db = TabularDataBunch.from_df(path='.', df=data, dep_var='Winner', valid_idx=ts_idx, procs=procs, test_df=tout, cat_names=cat_names, bs=1024)
 learn = tabular_learner(db, layers=[64, 32, 16, 8], metrics=accuracy)
 learn.lr_find()
learn.recorder.plot()
data = [train_df, test_df]
titles = {"Mr": 1, "Miss": 2, "Mrs": 3, "Master": 4, "Rare": 5}
for dataset in data:
dataset['Title'] = dataset['Name'].str.extract('([A-Za-z]+)\.')
 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')
 dataset['Title'] = dataset['Title'].map(titles)
 dataset['Title'] = dataset['Title'].fillna(0)
 train_df = train_df.drop(['Name'], axis=1)
 test_df = test_df.drop(['Name'], axis=1)
 train_df['Title'].value_counts()<drop_column>
learn.fit_one_cycle(50, 1e-1 )
train_df['Ticket'].value_counts()
train_df = train_df.drop(['Ticket'], axis=1)
 test_df = test_df.drop(['Ticket'], axis=1 )<drop_column>
preds, _ = learn.get_preds(ds_type=DatasetType.Test)
 preds = np.argmax(preds, axis=1 ).numpy()
submission = pd.DataFrame(test.iloc[:, 0])
 submission['Winner'] = preds
train_df = train_df.drop(['PassengerId'], axis=1 )<prepare_x_and_y>
print(submission.head())
 submission.to_csv('./submission.csv', index=False )
<drop_column><EOS> 
def create_download_link(df, title = "Download CSV file", filename = "data.csv"):
csv = df.to_csv(index=False)
 b64 = base64.b64encode(csv.encode())
 payload = b64.decode()
html = '<a download="{filename}" href="data:text/csv;base64,{payload}" target="_blank">{title}</a>'
html = html.format(payload=payload,title=title,filename=filename)
 return HTML(html)
 create_download_link(submission )