class_docstr: Callback that performs generic scoring on batches.
  
  This callback determines the score after each batch and stores it
  in the net's history in the column given by ``name``. At the end
  of the epoch, the average of the scores are determined and also
  stored in the history. Furthermore, it is determined whether this
  average score is the best score yet and that information is also
  stored in the history.
  
  In contrast to :class:`.EpochScoring`, this callback determines
  the score for each batch and then averages the score at the end of
  the epoch. This can be disadvantageous for some scores if the
  batch size is small -- e.g. area under the ROC will return
  incorrect scores in this case. Therefore, it is recommnded to use
  :class:`.EpochScoring` unless you really need the scores for each
  batch.
  
  If ``y`` is None, the ``scoring`` function with signature (model, X, y)
  must be able to handle ``X`` as a ``Tensor`` and ``y=None``.
  
  Parameters
  ----------
  scoring : None, str, or callable
    If None, use the ``score`` method of the model. If str, it should
    be a valid sklearn metric (e.g. "f1_score", "accuracy_score"). If
    a callable, it should have the signature (model, X, y), and it
    should return a scalar. This works analogously to the ``scoring``
    parameter in sklearn's ``GridSearchCV`` et al.
  
  lower_is_better : bool (default=True)
    Whether lower (e.g. log loss) or higher (e.g. accuracy) scores
    are better.
  
  on_train : bool (default=False)
    Whether this should be called during train or validation.
  
  name : str or None (default=None)
    If not an explicit string, tries to infer the name from the
    ``scoring`` argument.
  
  target_extractor : callable (default=to_numpy)
    This is called on y before it is passed to scoring.
  
  use_caching : bool (default=True)
    Re-use the model's prediction for computing the loss to calculate
    the score. Turning this off will result in an additional inference
    step for each batch. Note that the net may override the use of
    caching.
class_docstr_tok: ["Callback","that","performs","generic","scoring","on","batches",".","This","callback","determines","the","score","after","each","batch","and","stores","it","in","the","net","'s","history","in","the","column","given","by","``","name","``",".","At","the","end","of","the","epoch",",","the","average","of","the","scores","are","determined","and","also","stored","in","the","history",".","Furthermore",",","it","is","determined","whether","this","average","score","is","the","best","score","yet","and","that","information","is","also","stored","in","the","history",".","In","contrast","to",":","class",":","`",".EpochScoring","`",",","this","callback","determines","the","score","for","each","batch","and","then","averages","the","score","at","the","end","of","the","epoch",".","This","can","be","disadvantageous","for","some","scores","if","the","batch","size","is","small","--","e.g",".","area","under","the","ROC","will","return","incorrect","scores","in","this","case",".","Therefore",",","it","is","recommnded","to","use",":","class",":","`",".EpochScoring","`","unless","you","really","need","the","scores","for","each","batch",".","If","``","y","``","is","None",",","the","``","scoring","``","function","with","signature","(","model",",","X",",","y",")","must","be","able","to","handle","``","X","``","as","a","``","Tensor","``","and","``","y=None","``",".","Parameters","--","--","--","--","--","scoring",":","None",",","str",",","or","callable","If","None",",","use","the","``","score","``","method","of","the","model",".","If","str",",","it","should","be","a","valid","sklearn","metric","(","e.g",".","``","f1_score","''",",","``","accuracy_score","''",")",".","If","a","callable",",","it","should","have","the","signature","(","model",",","X",",","y",")",",","and","it","should","return","a","scalar",".","This","works","analogously","to","the","``","scoring","``","parameter","in","sklearn","'s","``","GridSearchCV","``","et","al",".","lower_is_better",":","bool","(","default=True",")","Whether","lower","(","e.g",".","log","loss",")","or","higher","(","e.g",".","accuracy",")","scores","are","better",".","on_train",":","bool","(","default=False",")","Whether","this","should","be","called","during","train","or","validation",".","name",":","str","or","None","(","default=None",")","If","not","an","explicit","string",",","tries","to","infer","the","name","from","the","``","scoring","``","argument",".","target_extractor",":","callable","(","default=to_numpy",")","This","is","called","on","y","before","it","is","passed","to","scoring",".","use_caching",":","bool","(","default=True",")","Re-use","the","model","'s","prediction","for","computing","the","loss","to","calculate","the","score",".","Turning","this","off","will","result","in","an","additional","inference","step","for","each","batch",".","Note","that","the","net","may","override","the","use","of","caching","."]
code: def on_epoch_end(self, net, **kwargs):
      history = net.history
      try:  # don't raise if there is no valid data
          history[-1, "batches", :, self.name_]
      except KeyError:
          return
  
      score_avg = self.get_avg_score(history)
      is_best = self._is_best_score(score_avg)
      if is_best:
          self.best_score_ = score_avg
  
      history.record(self.name_, score_avg)
      if is_best is not None:
          history.record(self.name_ + "_best", bool(is_best))
  
imports: from contextlib import contextmanager
  from contextlib import suppress
  from functools import partial
  import warnings
  import numpy
  import sklearn
  from sklearn.metrics import make_scorer, check_scoring
  from skorch.callbacks import Callback
  from skorch.dataset import unpack_data
  from sklearn.metrics._scorer import _BaseScorer
  from skorch.utils import data_from_dataset
  from skorch.utils import is_skorch_dataset
  from skorch.utils import to_numpy
  from skorch.utils import check_indexing
  from skorch.utils import to_device
label_desc: Use image node_id 3 for calling the BatchScoring obj's underlying member method code with example usage: obj.on_epoch_end(net) without return types