Using Indices of Classes to Grade Test Set?

Hi all, I am close to figuring this out but not quite. I’m trying to grade the accuracy of predictions from a predicted dataframe, and so I gather the predictions into a DataFrame like so:

predictions = learn.get_preds(DatasetType.Test)[1].numpy()
preds = pd.DataFrame(predictions)

The result of this is a location of the proper label from learn.data.classes, so I saved that array as arr. Let truth be the test dataframe:

i = 0
predictions = learn.get_preds(DatasetType.Test)[1].numpy()
preds = pd.DataFrame(predictions)
arr = learn.data.classes
for x in range(len(preds)):
  if(arr[int(preds.iloc[x])] == truth.iloc[x]):
    i+=1
print(i/len(truth))

This should be working for generating an overall accuracy, but it reports back 44%. When I verify what the accuracy should be via learn.predict() over the entire dataframe I report an accuracy of 94.3%. Did I do something wrong with the above?

Thank you very much for your help!

Zach

I wound up using the API to make a new tabular list built from my test df, and calling learn.validate.

testData = (TabularList.from_df(test, path=path, cat_names=cat_vars, cont_names=cont_vars, procs=procs)
       .split_none()
       .label_from_df(cols=dep_var)
       .databunch())

learn.validate(testData.train_dl)