pytorch-deep-learning icon indicating copy to clipboard operation
pytorch-deep-learning copied to clipboard

TypeError: __new__() missing 1 required positional argument: 'task'

Open levalencia opened this issue 2 years ago • 4 comments

On video: Evaluating Our Best Models Predictions with a Confusion Matrix

You show this line: confmat = ConfusionMatrix(num_classes=len(class_names))

But it throws above exception, task parameter is required (binary, multiclass, multilabel)

Maybe a note before the video is worth it

levalencia avatar Mar 29 '23 16:03 levalencia

Hello There,

I have used the Confusion Matrix from TorchMetrics as below

Create the Confusion Matrix Function

cm_fn = torchmetrics.ConfusionMatrix(task='multiclass', num_classes=3)

Pass the y_pred and y_true to the cm_fn to get the confusion matrix

confmat = cm_fn(y_pred, y_true)

Hope this helps.

Thanks.

vineetsharma14 avatar Mar 31 '23 13:03 vineetsharma14

Yeah I know I fixed it also on my notebook but I think it should be mentioned in a page before the video

Sent from Outlook for Androidhttps://aka.ms/AAb9ysg


From: Vineet Sharma @.> Sent: Friday, March 31, 2023 3:26:15 PM To: mrdbourke/pytorch-deep-learning @.> Cc: Luis Valencia @.>; Author @.> Subject: Re: [mrdbourke/pytorch-deep-learning] TypeError: new() missing 1 required positional argument: 'task' (Issue #377)

Hello There,

I have used the Confusion Matrix from TorchMetrics as below

Create the Confusion Matrix Function

cm_fn = torchmetrics.ConfusionMatrix(task='multiclass', num_classes=3)

Pass the y_pred and y_true to the cm_fn to get the confusion matrix

confmat = cm_fn(y_pred, y_true)

Hope this helps.

Thanks.

— Reply to this email directly, view it on GitHubhttps://github.com/mrdbourke/pytorch-deep-learning/issues/377#issuecomment-1491924147, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABVD5KPP4NMUHH3OIEGE4Z3W63LPNANCNFSM6AAAAAAWMDP3LY. You are receiving this because you authored the thread.Message ID: @.***>

levalencia avatar Mar 31 '23 13:03 levalencia

Hello my friend : I have encountered a problem with the following code, please tell me how to fix this error

from torchmetrics import ConfusionMatrix from mlxtend.plotting import plot_confusion_matrix

Setup confusion matrix instance

confmat = ConfusionMatrix(num_classes=len(class_names)) confmat_tensor = confmat(preds=test_preds, target=test_truth)

Plot the confusion matrix

fig, ax = plot_confusion_matrix( conf_mat=confmat_tensor.numpy(), # matplotlib likes working with NumPy class_names=class_names, figsize=(10, 7) )

Related error: TypeError: ConfusionMatrix.new() missing 1 required positional argument: 'task'

alireza32000 avatar Aug 25 '23 17:08 alireza32000

Check out https://torchmetrics.readthedocs.io/en/stable/classification/confusion_matrix.html. The task argument has been added since the course was recorded. I ran into the same issue.

otrturn avatar Aug 25 '23 18:08 otrturn