Repository: pytorch/ignite

Issue:
[docs] Add doctests for metrics
### 📚 Documentation

Following #2230 , I listed the metrics places (suggested by @sdesrozis) where doctests can be added.

#### Metrics

- [x] Average (#2332)
- [x] GeometricAverage (#2332)
- [x] VariableAccumulation (This class is an helper, no test needed)
- [x] Accuracy (#2345)
- [x] ConfusionMatrix (#2336)
- [x] ClassificationReport (#2346)
- [x] DiceCoefficient (#2336)
- [x] JaccardIndex (#2336)
- [x] IoU (#2336)
- [x] mIoU (#2336)
- [x] EpochMetric (#2351)
- [x] Fbeta (#2340)
- [x] Loss (#2335)
- [x] MeanAbsoluteError (#2280)
- [x] MeanPairwiseDistance (#2307)
- [x] MeanSquaredError (#2280)
- [x] MetricsLambda (#2352)
- [x] MultiLabelConfusionMatrix (#2347)
- [x] Precision (#2340)
- [x] PSNR (#2311)
- [x] Recall (#2340)
- [x] RootMeanSquaredError (#2307)
- [x] RunningAverage (#2348)
- [x] SSIM (#2241)
- [x] TopKCategoricalAccuracy (#2284)
- [x] Bleu (#2317)
- [x] Rouge (#2317)
- [x] RougeL (#2317)
- [x] RougeN (#2317)
- [x] InceptionScore (#2349)
- [x] FID (#2349)

#### Contrib Metrics

- [x] AveragePrecision (#2341)
- [x] CohenKappa (#2321)
- [x] PrecisionRecallCurve (#2341)
- [x] ROC_AUC (#2341)
- [x] RocCurve (#2341)
- [x] CanberraMetric (#2323)
- [x] FractionalAbsoluteError (#2323)
- [x] FractionalBias (#2323)
- [x] GeometricMeanAbsoluteError (#2323)
- [x] GeometricMeanRelativeAbsoluteError (#2324)
- [x] ManhattanDistance (#2324)
- [x] MaximumAbsoluteError (#2324)
- [x] MeanAbsoluteRelativeError (#2324)
- [x] MeanError (#2324)
- [x] MeanNormalizedBias (#2324)
- [x] MedianAbsoluteError (#2324)
- [x] MedianAbsolutePercentageError (#2324) 
- [x] MedianRelativeAbsoluteError (#2324)
- [x] R2Score (#2324)
- [x] WaveHedgesDistance (#2324) 

This is a great issue for first comers and those who want to learn more about Sphinx. This issue is the community effort.
If you want to contribute, please comment on this issue with the metric you want to add doctest (one by one).

Example on how to add doctest, see #2241 

Thanks!


Discussion:
Hello,

May I take up `Average`?
Sure @wanjuntham , go for it, thanks!
Hi, everyone

I'm coming from `PyData Global 2021`'s sprint.

I'll work on `Precision`, if it isn't taken yet. 


Hello 
This is my first contribution :-)

can I work on `Loss` ?
> Hello 
> 
> This is my first contribution :-)
> 
> 
> 
> can I work on `Loss` ?

@Eunjnnn thank you ! Yes you can 😉 
@vfdev-5 Hey, I actually didnt have time to work on this. Could you unassign me?
@Eunjnnn Are you still working on `Loss` ? Or do you need help ?
@sdesrozis Hi I'm trying to work on it, but actually i'm not sure where to start,,
> @sdesrozis Hi I'm trying to work on it, but actually i'm not sure where to start,,

First, take a look to our [contribution guide](https://github.com/pytorch/ignite/blob/master/CONTRIBUTING.md). Then, you will have to set up your environment (testing, building the doc).

And finally, you will find [here](https://github.com/pytorch/ignite/blob/master/CONTRIBUTING.md#writing-documentation) what is needed to write the doc and doctests according to our guidelines :)

I'll add some of the contrib regression metrics ``FractionalBias``, ``FractionalAbsoluteError``, ``CanberraMetric``, ``GeometricMeanAbsoluteError``

Resolving patch:
diff --git a/ignite/metrics/loss.py b/ignite/metrics/loss.py
--- a/ignite/metrics/loss.py
+++ b/ignite/metrics/loss.py
@@ -42,35 +42,24 @@ class Loss(Metric):
         and the Loss metric using an ``evaluator`` created with
         :meth:`~ignite.engine.create_supervised_evaluator` method.
 
-        .. code-block:: python
+        .. testsetup:: *
 
-            import torch
-            import torch.nn as nn
-            from torch.nn.functional import nll_loss
+            default_trainer = get_default_trainer()
 
-            from ignite.metrics import Accuracy, Loss
-            from ignite.engine import create_supervised_evaluator
+        .. testcode::
 
-            model = ...
+            model = default_model
+            criterion = nn.NLLLoss()
+            metric = Loss(criterion)
+            metric.attach(default_evaluator, 'loss')
+            y_pred = torch.tensor([[0.1, 0.4, 0.5], [0.1, 0.7, 0.2]])
+            y_true = torch.tensor([2, 2]).long()
+            state = default_evaluator.run([[y_pred, y_true]])
+            print(state.metrics['loss'])
 
-            criterion = nll_loss
+        .. testoutput::
 
-            metrics = {
-                "Accuracy": Accuracy(),
-                "Loss": Loss(criterion)
-            }
-
-            # global criterion kwargs
-            criterion_kwargs = {...}
-
-            evaluator = create_supervised_evaluator(
-                model,
-                metrics=metrics,
-                output_transform=lambda x, y, y_pred: {
-                    "x": x, "y": y, "y_pred": y_pred, "criterion_kwargs": criterion_kwargs}
-            )
-
-            res = evaluator.run(data)
+            -0.3499999...
 
     """
 


Test patch: