class_docstr: Calculate model-level model performance measures
  
  Parameters
  -----------
  model_type : {'regression', 'classification'}
      Model task type that is used to choose the proper performance measures.
  cutoff : float, optional
      Cutoff for predictions in classification models. Needed for measures like
      recall, precision, acc, f1 (default is `0.5`).
  
  Attributes
  -----------
  result : pd.DataFrame
      Main result attribute of an explanation.
  residuals : pd.DataFrame
      Residuals for `data`.
  model_type : {'regression', 'classification'}
      Model task type that is used to choose the proper performance measures.
  cutoff : float
      Cutoff for predictions in classification models.
  
  Notes
  --------
  - https://pbiecek.github.io/ema/modelPerformance.html
class_docstr_tok: ["Calculate","model-level","model","performance","measures","Parameters","--","--","--","--","--","-","model_type",":","{","'regression","'",",","'classification","'","}","Model","task","type","that","is","used","to","choose","the","proper","performance","measures",".","cutoff",":","float",",","optional","Cutoff","for","predictions","in","classification","models",".","Needed","for","measures","like","recall",",","precision",",","acc",",","f1","(","default","is","`","0.5","`",")",".","Attributes","--","--","--","--","--","-","result",":","pd.DataFrame","Main","result","attribute","of","an","explanation",".","residuals",":","pd.DataFrame","Residuals","for","`","data","`",".","model_type",":","{","'regression","'",",","'classification","'","}","Model","task","type","that","is","used","to","choose","the","proper","performance","measures",".","cutoff",":","float","Cutoff","for","predictions","in","classification","models",".","Notes","--","--","--","--","-","https",":","\/\/pbiecek.github.io\/ema\/modelPerformance.html"]
docstr: Calculate the result of explanation
  
  Fit method makes calculations in place and changes the attributes.
  
  Parameters
  -----------
  explainer : Explainer object
      Model wrapper created using the Explainer class.
  
  Returns
  -----------
  None
docstr_tok: ["Calculate","the","result","of","explanation","Fit","method","makes","calculations","in","place","and","changes","the","attributes",".","Parameters","--","--","--","--","--","-","explainer",":","Explainer","object","Model","wrapper","created","using","the","Explainer","class",".","Returns","--","--","--","--","--","-","None"]
code: def fit(self, explainer):
      """Calculate the result of explanation
  
      Fit method makes calculations in place and changes the attributes.
  
      Parameters
      -----------
      explainer : Explainer object
          Model wrapper created using the Explainer class.
  
      Returns
      -----------
      None
      """
  
      if explainer.y_hat is not None:
          y_pred = explainer.y_hat
      else:
          y_pred = explainer.predict(explainer.data)
  
      if explainer.residuals is not None:
          _residuals = explainer.residuals
      else:
          _residuals = explainer.residual(explainer.data, explainer.y)
  
      y_true = explainer.y
  
      if self.model_type == "regression":
          _mse = utils.mse(y_pred, y_true)
          _rmse = utils.rmse(y_pred, y_true)
          _r2 = utils.r2(y_pred, y_true)
          _mae = utils.mae(y_pred, y_true)
          _mad = utils.mad(y_pred, y_true)
  
          self.result = pd.DataFrame(
              {
                  "mse": [_mse],
                  "rmse": [_rmse],
                  "r2": [_r2],
                  "mae": [_mae],
                  "mad": [_mad],
              },
              index=[explainer.label],
          )
      elif self.model_type == "classification":
          tp = ((y_true == 1) * (y_pred >= self.cutoff)).sum()
          fp = ((y_true == 0) * (y_pred >= self.cutoff)).sum()
          tn = ((y_true == 0) * (y_pred < self.cutoff)).sum()
          fn = ((y_true == 1) * (y_pred < self.cutoff)).sum()
  
          _recall = utils.recall(tp, fp, tn, fn)
          _precision = utils.precision(tp, fp, tn, fn)
          _f1 = utils.f1(tp, fp, tn, fn)
          _accuracy = utils.accuracy(tp, fp, tn, fn)
          _auc = utils.auc(y_pred, y_true)
  
          self.result = pd.DataFrame(
              {
                  "recall": [_recall],
                  "precision": [_precision],
                  "f1": [_f1],
                  "accuracy": [_accuracy],
                  "auc": [_auc],
              },
              index=[explainer.label],
          )
      else:
          raise ValueError(
              "'model_type' must be 'regression' or 'classification'"
          )
  
      _residuals = pd.DataFrame(
          {
              "y_hat": y_pred,
              "y": y_true,
              "residuals": _residuals,
              "label": explainer.label,
          }
      )
  
      self.residuals = _residuals
  
file_path: DALEX/python/dalex/dalex/model_explanations/_model_performance/object.py
imports: import numpy
  import pandas
  from .None import plot, utils
  from ...None import _theme, _global_checks
  from ..._explanation import Explanation
label_desc: Use image node_id 3 for calling the ModelPerformance obj's underlying member method code with example usage: obj.fit(explainer) without return types