Tabular learner Titanic dataset

Hi all. I am brand new user of Fastai library. I am trying to use tabular learner.

I am using Titanic dataset as a toy example.

I am using this code.

from fastai import *
train = pd.read_csv('train.csv')

test = pd.read_csv("test.csv")

# Fast ai sometimes wants us to
# fix the na manually in test

test["Fare"] = test["Fare"].fillna(value=0)

dep_var = 'Survived'
#cat_names = data.select_dtypes(exclude=['int', 'float']).columns
cat_names = [ 'Sex', 'Ticket', 'Cabin', 'Embarked']

#cont_names = data.select_dtypes([np.number]).columns
cont_names = [ 'Age', 'SibSp', 'Parch', 'Fare']

# Transformations
procs = [FillMissing, Categorify, Normalize]

# Test Tabular List
test = TabularList.from_df(test, cat_names=cat_names, cont_names=cont_names, procs=procs)

# Train Data Bunch
data = (TabularList.from_df(train, path='.', cat_names=cat_names, cont_names=cont_names, procs=procs)
                        .label_from_df(cols = dep_var)
                        .add_test(test, label=0)


# Create deep learning model

learn = tabular_learner(data, layers=[1000, 200, 15], metrics=fbeta, emb_drop=0.1, callback_fns=ShowGraph)

#Fit the model based on selected learning rate
learn.fit_one_cycle(15, max_lr=slice(1e-04))

I stumble upon this error: RuntimeError: The size of tensor a (2) must match the size of tensor b (64) at non-singleton dimension 1

I fully understand that there are mismatch between the dimension of tensors. I suppose that my batch size maybe cause it.

If I change metrics to be accuracy it works.

Would like to help me to understand what I am doing wrong? How I can use recall in metrics I do not know how?

I found my mistake. I need to initiate the Class metrics before I can use. As Sylvain mention some post on Github.

Please see this snippet as reference:
learn = tabular_learner(data, layers=[1000, 200, 15], metrics=Recall(), emb_drop=0.1, callback_fns=ShowGraph)