How to get predictions on dataframe in fastai

I have defined databunch as

data = (TabularList.from_df(train_df, path='./', cont_names=cont_names, procs=procs)
                           .split_by_idx(list(range(500,3000)))
                           .label_from_df(cols=dep_var)
                           .add_test(test, label=0)
                           .databunch())

After training i am

p = learn3.get_preds()
len(p[1])

o/p is 2500 which is correct as

                       .split_by_idx(list(range(500,3000)))

this is 2500 numbers


But now i have other data of around few thousand inputs and if i do
for index in range(len(test_df)):
    predictions = learn3.predict(test_df.iloc[index])
    predictions = predictions[1].tolist()
    print(index)

It will take really huge amount of time. I want to pass test_df and get the predictions as was as

p = learn3.get_preds()

How can i do that ?

                       .split_by_idx(list(range(500,3000)))

Do we have way to replace this and pass data from other file ?

I think the best way to do to this would be to add your data frame as another dataset to the model and label it as the “test” dataset. Then just run get_preds(ds_type=DatasetType.Test) l

Check this thread to see if that helps you.

1 Like