class_docstr: A class for temperature calibration for binary and multi-class classification problems.
  
  For binary classification, Platt Scaling is used for calibration. Platt Scaling was
  proposed in the paper Probabilistic outputs for support vector machines and comparisons to regularized
  likelihood methods, J. C. Platt, Advances in large margin classifiers, 10(3): 61-74, 1999.
  
  For multi-class classification, Temperature Calibration is used. It is an extension of Platt Scaling
  and it was proposed in the paper On Calibration of Modern Neural Networks, C. Guo et. al., ICML, 2017.
  
  In Temperature Calibration, a classifier's non-probabilistic outputs, i.e., logits, are
  scaled by a trainable parameter called Temperature. The softmax is applied to the rescaled
  logits to calculate the probabilistic output. As noted in the cited paper, Temperature
  Scaling does not change the maximum of the softmax function so the classifier's prediction
  remain the same.
  
  .. seealso::
  
     `Examples using calibration <https://stellargraph.readthedocs.io/en/stable/demos/calibration/index.html>`__.
  
     Related functionality: :func:`.expected_calibration_error`, :func:`.plot_reliability_diagram`, :class:`.IsotonicCalibration`.
class_docstr_tok: ["A","class","for","temperature","calibration","for","binary","and","multi-class","classification","problems",".","For","binary","classification",",","Platt","Scaling","is","used","for","calibration",".","Platt","Scaling","was","proposed","in","the","paper","Probabilistic","outputs","for","support","vector","machines","and","comparisons","to","regularized","likelihood","methods",",","J.","C.","Platt",",","Advances","in","large","margin","classifiers",",","10","(","3",")",":","61-74",",","1999",".","For","multi-class","classification",",","Temperature","Calibration","is","used",".","It","is","an","extension","of","Platt","Scaling","and","it","was","proposed","in","the","paper","On","Calibration","of","Modern","Neural","Networks",",","C.","Guo","et",".","al.",",","ICML",",","2017",".","In","Temperature","Calibration",",","a","classifier","'s","non-probabilistic","outputs",",","i.e.",",","logits",",","are","scaled","by","a","trainable","parameter","called","Temperature",".","The","softmax","is","applied","to","the","rescaled","logits","to","calculate","the","probabilistic","output",".","As","noted","in","the","cited","paper",",","Temperature","Scaling","does","not","change","the","maximum","of","the","softmax","function","so","the","classifier","'s","prediction","remain","the","same",".","..","seealso",":",":","`","Examples","using","calibration","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/calibration\/index.html",">","`","__",".","Related","functionality",":",":","func",":","`",".expected_calibration_error","`",",",":","func",":","`",".plot_reliability_diagram","`",",",":","class",":","`",".IsotonicCalibration","`","."]
docstr: Train the calibration model.
  
  For temperature scaling of a multi-class classifier, If validation data is given, then
  training stops when the validation accuracy starts increasing. Validation data are ignored for Platt scaling
  
  Args:
      x_train (numpy array): The training data that should be a classifier's non-probabilistic outputs. For
          calibrating a binary classifier it should have shape (N,) where N is the number of training samples.
          For calibrating a multi-class classifier, it should have shape (N, C) where N is the number of samples
          and C is the number of classes.
      y_train (numpy array): The training data class labels. For
          calibrating a binary classifier it should have shape (N,) where N is the number of training samples.
          For calibrating a multi-class classifier, it should have shape (N, C) where N is the number of samples
          and C is the number of classes and the class labels are one-hot encoded.
      x_val (numpy array or None): The validation data used only for calibrating multi-class classification
          models. It should have shape (M, C) where M is the number of validation samples and C is the number of
          classes and the class labels are one-hot encoded.
          that should be the classifier's non-probabilistic outputs.
      y_val (numpy array or None): The validation data class labels used only for calibrating multi-class
          classification models. It should have shape (M, C) where M is the number of validation samples and C
          is the number of classes and the class labels are one-hot encoded.
docstr_tok: ["Train","the","calibration","model",".","For","temperature","scaling","of","a","multi-class","classifier",",","If","validation","data","is","given",",","then","training","stops","when","the","validation","accuracy","starts","increasing",".","Validation","data","are","ignored","for","Platt","scaling","Args",":","x_train","(","numpy","array",")",":","The","training","data","that","should","be","a","classifier","'s","non-probabilistic","outputs",".","For","calibrating","a","binary","classifier","it","should","have","shape","(","N",",",")","where","N","is","the","number","of","training","samples",".","For","calibrating","a","multi-class","classifier",",","it","should","have","shape","(","N",",","C",")","where","N","is","the","number","of","samples","and","C","is","the","number","of","classes",".","y_train","(","numpy","array",")",":","The","training","data","class","labels",".","For","calibrating","a","binary","classifier","it","should","have","shape","(","N",",",")","where","N","is","the","number","of","training","samples",".","For","calibrating","a","multi-class","classifier",",","it","should","have","shape","(","N",",","C",")","where","N","is","the","number","of","samples","and","C","is","the","number","of","classes","and","the","class","labels","are","one-hot","encoded",".","x_val","(","numpy","array","or","None",")",":","The","validation","data","used","only","for","calibrating","multi-class","classification","models",".","It","should","have","shape","(","M",",","C",")","where","M","is","the","number","of","validation","samples","and","C","is","the","number","of","classes","and","the","class","labels","are","one-hot","encoded",".","that","should","be","the","classifier","'s","non-probabilistic","outputs",".","y_val","(","numpy","array","or","None",")",":","The","validation","data","class","labels","used","only","for","calibrating","multi-class","classification","models",".","It","should","have","shape","(","M",",","C",")","where","M","is","the","number","of","validation","samples","and","C","is","the","number","of","classes","and","the","class","labels","are","one-hot","encoded","."]
code: def fit(self, x_train, y_train, x_val=None, y_val=None):
      """
      Train the calibration model.
  
      For temperature scaling of a multi-class classifier, If validation data is given, then
      training stops when the validation accuracy starts increasing. Validation data are ignored for Platt scaling
  
      Args:
          x_train (numpy array): The training data that should be a classifier's non-probabilistic outputs. For
              calibrating a binary classifier it should have shape (N,) where N is the number of training samples.
              For calibrating a multi-class classifier, it should have shape (N, C) where N is the number of samples
              and C is the number of classes.
          y_train (numpy array): The training data class labels. For
              calibrating a binary classifier it should have shape (N,) where N is the number of training samples.
              For calibrating a multi-class classifier, it should have shape (N, C) where N is the number of samples
              and C is the number of classes and the class labels are one-hot encoded.
          x_val (numpy array or None): The validation data used only for calibrating multi-class classification
              models. It should have shape (M, C) where M is the number of validation samples and C is the number of
              classes and the class labels are one-hot encoded.
              that should be the classifier's non-probabilistic outputs.
          y_val (numpy array or None): The validation data class labels used only for calibrating multi-class
              classification models. It should have shape (M, C) where M is the number of validation samples and C
              is the number of classes and the class labels are one-hot encoded.
      """
      if not isinstance(x_train, np.ndarray) or not isinstance(
          y_train, np.ndarray
      ):
          raise ValueError("x_train and y_train must be numpy arrays")
  
      if (x_val is not None and y_val is None) or (
          x_val is None and y_val is not None
      ):
          raise ValueError(
              "Either both x_val and y_val should be None or both should be numpy arrays."
          )
  
      if x_val is not None and y_val is not None:
          if not isinstance(x_val, np.ndarray) or not isinstance(
              y_val, np.ndarray
          ):
              raise ValueError(
                  "x_train and y_train must be numpy arrays"
              )
  
          self.early_stopping = True
          print(
              "Using Early Stopping based on performance evaluated on given validation set."
          )
  
      if len(x_train.shape) == 1:
          self.n_classes = 1
      else:
          self.n_classes = x_train.shape[1]
  
      if self.n_classes > 1:
          self._fit_temperature_scaling(x_train, y_train, x_val, y_val)
      else:
          self._fit_platt_scaling(
              x_train.reshape(-1, 1), y_train.reshape(-1, 1)
          )
  
imports: import numpy
  import matplotlib.pyplot
  import tensorflow
  from sklearn.isotonic import IsotonicRegression
  from sklearn.linear_model import LogisticRegression
label_desc: Use image node_id 4 for calling the TemperatureCalibration obj's underlying member method code with example usage: obj.fit(x_train, y_train, x_val, y_val) without return types