docstr: Partial dependence plot per protected group.
  
  :param model: H2O Model Object
  :param frame: H2OFrame
  :param column: String containing column name.
  :param protected_columns: List of categorical columns that contain sensitive information
                                such as race, gender, age etc.
  :param figsize: Tuple with figure size; passed directly to matplotlib.
  :param autoscale: If ``True``, try to guess when to use log transformation on X axis.
  :param save_plot_path: A path to save the plot via using matplotlib function savefig.
  :return: Matplotlib Figure object
  
  :examples:
  >>> from h2o.estimators import H2OGradientBoostingEstimator
  >>> data = h2o.import_file("https://s3.amazonaws.com/h2o-public-test-data/smalldata/admissibleml_test/taiwan_credit_card_uci.csv")
  >>> x = ['LIMIT_BAL', 'AGE', 'PAY_0', 'PAY_2', 'PAY_3', 'PAY_4', 'PAY_5', 'PAY_6', 'BILL_AMT1', 'BILL_AMT2', 'BILL_AMT3',
  >>>      'BILL_AMT4', 'BILL_AMT5', 'BILL_AMT6', 'PAY_AMT1', 'PAY_AMT2', 'PAY_AMT3', 'PAY_AMT4', 'PAY_AMT5', 'PAY_AMT6']
  >>> y = "default payment next month"
  >>> protected_columns = ['SEX', 'EDUCATION']
  >>>
  >>> for c in [y] + protected_columns:
  >>>     data[c] = data[c].asfactor()
  >>>
  >>> train, test = data.split_frame([0.8])
  >>>
  >>> reference = ["1", "2"]  # university educated man
  >>> favorable_class = "0"  # no default next month
  >>>
  >>> gbm = H2OGradientBoostingEstimator()
  >>> gbm.train(x, y, training_frame=train)
  >>>
  >>> gbm.fair_pd_plot(test, "AGE", protected_columns)
docstr_tok: ["Partial","dependence","plot","per","protected","group",".",":","param","model",":","H2O","Model","Object",":","param","frame",":","H2OFrame",":","param","column",":","String","containing","column","name",".",":","param","protected_columns",":","List","of","categorical","columns","that","contain","sensitive","information","such","as","race",",","gender",",","age","etc",".",":","param","figsize",":","Tuple","with","figure","size",";","passed","directly","to","matplotlib",".",":","param","autoscale",":","If","``","True","``",",","try","to","guess","when","to","use","log","transformation","on","X","axis",".",":","param","save_plot_path",":","A","path","to","save","the","plot","via","using","matplotlib","function","savefig",".",":","return",":","Matplotlib","Figure","object",":","examples",":",">",">",">","from","h2o.estimators","import","H2OGradientBoostingEstimator",">",">",">","data","=","h2o.import_file","(","``","https",":","\/\/s3.amazonaws.com\/h2o-public-test-data\/smalldata\/admissibleml_test\/taiwan_credit_card_uci.csv","''",")",">",">",">","x","=","[","'LIMIT_BAL","'",",","'AGE","'",",","'PAY_0","'",",","'PAY_2","'",",","'PAY_3","'",",","'PAY_4","'",",","'PAY_5","'",",","'PAY_6","'",",","'BILL_AMT1","'",",","'BILL_AMT2","'",",","'BILL_AMT3","'",",",">",">",">","'BILL_AMT4","'",",","'BILL_AMT5","'",",","'BILL_AMT6","'",",","'PAY_AMT1","'",",","'PAY_AMT2","'",",","'PAY_AMT3","'",",","'PAY_AMT4","'",",","'PAY_AMT5","'",",","'PAY_AMT6","'","]",">",">",">","y","=","``","default","payment","next","month","''",">",">",">","protected_columns","=","[","'SEX","'",",","'EDUCATION","'","]",">",">",">",">",">",">","for","c","in","[","y","]","+","protected_columns",":",">",">",">","data","[","c","]","=","data","[","c","]",".asfactor","(",")",">",">",">",">",">",">","train",",","test","=","data.split_frame","(","[","0.8","]",")",">",">",">",">",">",">","reference","=","[","``","1","''",",","``","2","''","]","#","university","educated","man",">",">",">","favorable_class","=","``","0","''","#","no","default","next","month",">",">",">",">",">",">","gbm","=","H2OGradientBoostingEstimator","(",")",">",">",">","gbm.train","(","x",",","y",",","training_frame=train",")",">",">",">",">",">",">","gbm.fair_pd_plot","(","test",",","``","AGE","''",",","protected_columns",")"]
code: def fair_pd_plot(
      self,
      frame,
      column,
      protected_columns,
      figsize=(16, 9),
      autoscale=True,
      save_plot_path=None,
  ):
      """
      Partial dependence plot per protected group.
  
      :param model: H2O Model Object
      :param frame: H2OFrame
      :param column: String containing column name.
      :param protected_columns: List of categorical columns that contain sensitive information
                                    such as race, gender, age etc.
      :param figsize: Tuple with figure size; passed directly to matplotlib.
      :param autoscale: If ``True``, try to guess when to use log transformation on X axis.
      :param save_plot_path: A path to save the plot via using matplotlib function savefig.
      :return: Matplotlib Figure object
  
      :examples:
      >>> from h2o.estimators import H2OGradientBoostingEstimator
      >>> data = h2o.import_file("https://s3.amazonaws.com/h2o-public-test-data/smalldata/admissibleml_test/taiwan_credit_card_uci.csv")
      >>> x = ['LIMIT_BAL', 'AGE', 'PAY_0', 'PAY_2', 'PAY_3', 'PAY_4', 'PAY_5', 'PAY_6', 'BILL_AMT1', 'BILL_AMT2', 'BILL_AMT3',
      >>>      'BILL_AMT4', 'BILL_AMT5', 'BILL_AMT6', 'PAY_AMT1', 'PAY_AMT2', 'PAY_AMT3', 'PAY_AMT4', 'PAY_AMT5', 'PAY_AMT6']
      >>> y = "default payment next month"
      >>> protected_columns = ['SEX', 'EDUCATION']
      >>>
      >>> for c in [y] + protected_columns:
      >>>     data[c] = data[c].asfactor()
      >>>
      >>> train, test = data.split_frame([0.8])
      >>>
      >>> reference = ["1", "2"]  # university educated man
      >>> favorable_class = "0"  # no default next month
      >>>
      >>> gbm = H2OGradientBoostingEstimator()
      >>> gbm.train(x, y, training_frame=train)
      >>>
      >>> gbm.fair_pd_plot(test, "AGE", protected_columns)
      """
      import h2o
      from h2o.utils.shared_utils import can_use_numpy
  
      if not can_use_numpy():
          raise ImportError("numpy is required for fair_pd_plot.")
      import numpy as np
      from h2o.explanation._explain import no_progress_block
      from h2o.plot import get_matplotlib_pyplot
      from h2o.utils.typechecks import assert_is_type, is_type
  
      assert_is_type(frame, h2o.H2OFrame)
      assert_is_type(column, str)
      assert_is_type(protected_columns, [str])
      assert_is_type(figsize, tuple, list)
      assert_is_type(autoscale, bool)
  
      plt = get_matplotlib_pyplot(False, raise_if_not_available=True)
      pgs = product(
          *[
              frame[col].unique()["C1"].as_data_frame(False, False)
              for col in protected_columns
          ]
      )
      plt.figure(figsize=figsize)
      results = []
      maxes = []
      with no_progress_block():
          for pg in pgs:
              pg = [p[0] for p in pg]
              filtered_hdf = frame
              for i in range(len(protected_columns)):
                  filtered_hdf = filtered_hdf[
                      filtered_hdf[protected_columns[i]] == pg[i], :
                  ]
              if filtered_hdf.nrow == 0:
                  continue
              pd = self.partial_plot(
                  filtered_hdf, cols=[column], plot=False, nbins=40
              )[0]
              results.append((pg, pd))
              if is_type(pd[column.lower()][0], str):
                  maxes.append(1)
              else:
                  maxes.append(np.nanmax(pd[column.lower()]))
      maxes = np.array(maxes) - np.min(maxes) + 1
      is_factor = frame[column].isfactor()[0]
      autoscale = (
          autoscale
          and not is_factor
          and frame[column].min() > -1
          and (
              np.nanmax(np.log(maxes)) - np.nanmin(np.log(maxes)) > 1
          ).all()
      )
      for pg, pd in results:
          x = pd[column.lower()]
          if autoscale:
              x = np.log1p(x)
          mean_response = pd["mean_response"]
          stdev_response = pd["std_error_mean_response"]
          if is_factor:
              plt.errorbar(
                  x,
                  mean_response,
                  yerr=stdev_response,
                  label=", ".join(pg),
                  fmt="o",
                  elinewidth=3,
                  capsize=0,
                  markersize=10,
              )
          else:
              plt.plot(x, mean_response, label=", ".join(pg))
              plt.fill_between(
                  x,
                  [
                      m[0] - m[1]
                      for m in zip(mean_response, stdev_response)
                  ],
                  [
                      m[0] + m[1]
                      for m in zip(mean_response, stdev_response)
                  ],
                  label="_noLabel",
                  alpha=0.2,
              )
      plt.title("PDP for {}".format(column))
      plt.xlabel("log({})".format(column) if autoscale else column)
      plt.ylabel("Response")
      plt.legend()
      plt.grid()
      if save_plot_path is not None:
          plt.savefig(fname=save_plot_path)
      return plt.gcf()
  
file_path: h2o-3/h2o-py/h2o/model/extensions/fairness.py
imports: from collections import defaultdict
  from itertools import product
  from h2o.utils.threading import local_context
label_desc: Use image node_id 2 for calling the Fairness obj's underlying member method code with example usage: obj.fair_pd_plot(frame, column, protected_columns, figsize, autoscale, save_plot_path) and returns: plt