Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behaviour of plot_decision_boundary() in 02_neural_network_classification_with_tensorflow.ipynb #320

Closed
donalhill opened this issue Jan 12, 2022 · 2 comments

Comments

@donalhill
Copy link

Hello,

I am working through video 76 on the "TensorFlow Developer Certificate in 2022: Zero to Mastery" course. The function plot_decision_boundary() has the following logic:

if len(y_pred[0]) > 1:
    print("doing multiclass classification...")
    # We have to reshape our predictions to get them ready for plotting
    y_pred = np.argmax(y_pred, axis=1).reshape(xx.shape)
  else:
    print("doing binary classifcation...")
    y_pred = np.round(y_pred).reshape(xx.shape) #rounding to give us a 0 or 1

When I check len(y_pred[0]) which comes from y_pred = model.predict(x_in), I get a length of 2. So the current function then follows the logic for multi-class classification, although the problem being worked on is binary. Can this be fixed?

Cheers!
Donal

@mrdbourke
Copy link
Owner

Hey @donalrinho, looks like this is closed, did you solve it?

You could solve it by checking the dimensions of y_pred[0].

It depends on the shape of your output predictions.

If you're getting something like:

y_pred = [[0, 1, 0],
                 [1, 0, 0]...

The above code should work.

If your y_pred looks different, have a play around with the dimension checking logic to see if you can adjust it for your own use case.

For example, you could check the shape or ndim of the output tensor too.

@donalhill
Copy link
Author

Hey @mrdbourke,

Thanks for getting back to me! The issue was transient it seems, and went away when I reran a bunch of cells. Perhaps it was something silly I did when fiddling with one of the inputs.

Really enjoying your material so far, thank you for providing this resource :)

Cheers,
Donal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants