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)
                           .add_test(test, label=0)

After training i am

p = learn3.get_preds()

o/p is 2500 which is correct as


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()

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 ?


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