Lesson 1: name 'accuracy_np' is not defined

I am getting an error for the execution of the following statement:

accuracy_np(probs, y)

The Error is:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-75-98448a3af0e1> in <module>()
----> 1 accuracy_np(probs, y)

NameError: name 'accuracy_np' is not defined

Any help is appreciated!

have you run all the imports at the top? is everything else running?

go into the arguments and do shift-tab. Does it find anything?
it should - a file PATH\fastai\courses\dl1\fastai\metrics.py

is that on your machine?

That function should be defined in fastai/metrics.py. Maybe your local git repository is out of date? Try running git pull in your fastai directory to pull the latest changes.

You could also copy/paste this function from github into your notebook, althought this is a one time solution

I am running in Google Collab!

Everything else above is running perfectly!

and this part?

It gives: no docstring availble

I have just done !pip install --upgrade fastai

the file is not on the machine

Were you able to solve the error?
Can you share details/ notebook?

No not yet! not even sure what is the issue!

I am having a related issue.
Check this out. Wiki: Lesson 1 - #183 by nikhil_no_1
I am using accuracy function.
This is the source for it.

def accuracy(preds, targs):
preds = np.argmax(preds, axis=1)
return (preds==targs).mean()

Moreover I replaced probs with log_preds where ever it gave axis error. Just wanted to run through it once. Will now go through each line step by step to understand if that is the right thing to do.

-Nikhil

1 Like

This post here seems to work for me! Thanks to @paultimothymooney!

Get the Collab Notebook here!