Comments (2)
I have the same issue ! Please fix this
from torcheval.
Hi @LittletreeZou and @MattBrth ! Thank you both for contributing to torcheval!
I think there is a misunderstanding of multi-class metrics going on here! In most cases Binary-X and Multiclass-X with 2 classes are not the same thing. In the binary setting there is only 1 class, and each example is either in or not in that class. In the multiclass setting, there are two classes and you compute the f1 score for each (first calling 0 a positive label and computing true positives, false positive, etc... against the label actual = 0
, then calling 1 a positive label and doing the same).
In other words, what you're getting is the average of two f1 scores here.
Note: if you pass average=None
to multiclass_f1_score
, you will recover the binary result for class 1 in one of the outputs
>>> metric = MulticlassF1Score(num_classes=2, average=None)
>>> metric.update(pred, actual)
>>> print(metric.compute())
tensor([0.6256, **0.5820**])
Also note, this is standard behavior, e.g. following sklearn
>>> actual = torch.repeat_interleave(torch.tensor([1, 0]), repeats=torch.tensor([100, 100]))
>>> pred = torch.repeat_interleave(torch.tensor([1, 0, 1, 0]), repeats=torch.tensor([55, 45, 34, 66]))
>>> input_tensors = [torch.argmax(t, dim=1) if t.ndim == 2 else t for t in pred]
>>> target_tensors = list(actual)
>>> target_np = torch.stack(target_tensors).flatten().numpy()
>>> input_np = torch.stack(input_tensors).flatten().numpy()
>>> f1_score(target_np, input_np, average='micro')
0.605
from torcheval.
Related Issues (20)
- RuntimeError: "bitwise_and_cpu" not implemented for 'Float' when using binary_precison & binary_recall HOT 2
- Error in masking in the function multiclass_recall HOT 2
- FLOPs and ModuleSummary Documentation HOT 2
- More precise definition of perplexity when ignore index is not None HOT 1
- Throughput metric is not taking into account the number of processes HOT 2
- Multiple metrics sharing the same state HOT 4
- Disagreement for macro f1 with torchmetrics and sklearn HOT 5
- Docs return description of binary_confusion_matrix incorrect HOT 2
- Updating `Mean` with 0 leads to 'No calls to update() have been made...' warning HOT 1
- RetrievalRecall, RetrievalPrecision require different, 1D input than MulticlassRecall, MulticlassPrecision which accept batch input HOT 2
- Bug in MulticlassRecall example from when adding one additional class HOT 1
- Disagreement for auroc1 with sklearn HOT 3
- The FID result cannot be aligned with pytorch-fid/torch-fidelity HOT 1
- Torcheval pointing to wrong directory for nvrtc-builtins64_121.dll file.
- Potentially Misleading Error Message for multiclass_precision
- metrics should have an unsafe option
- Discrepancy between code and documentation on official pytorch websit
- Stable version for Torcheval
- Mutliclass Precision Recall Curve, docs not consistent with execution HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torcheval.