code: def cate_mean_by_bin(
      test_data: pd.DataFrame,
      group_column: str,
      control_group_name: str,
      bin_column: str,
      n_bins: int,
      allow_dropped_bins: bool,
      prediction_column: str,
      target_column: str,
  ) -> pd.DataFrame:
      """
      Computes a dataframe with predicted and actual CATEs by bins of a given column.
  
      This is primarily an auxiliary function, but can be used to visualize the CATEs.
  
      Parameters
      ----------
      test_data : DataFrame
          A Pandas' DataFrame with `group_column` as a column.
  
      group_column : str
          The name of the column that tells whether rows belong to the test or control group.
  
      control_group_name : str
          The name of the control group.
  
      bin_column : str
          The name of the column from which the quantiles will be created.
  
      n_bins : str
          The number of bins to be created.
  
      allow_dropped_bins : bool
          Whether to allow the function to drop duplicated quantiles.
  
      prediction_column : str
          The name of the column containing the predictions from the model being evaluated.
  
      target_column : str
          The name of the column containing the actual outcomes of the treatment.
  
      Returns
      ----------
      gb: DataFrame
          The grouped dataframe with actual and predicted CATEs by bin.
      """
      test_group_name = _validate_test_and_control_groups(
          test_data, group_column, control_group_name
      )
  
      test_after_control = test_group_name > control_group_name
  
      quantile_column = bin_column + "_q" + str(n_bins)
      duplicates = "drop" if allow_dropped_bins else "raise"
      test_data_binned = test_data.assign(
          **{
              quantile_column: pd.qcut(
                  test_data[bin_column], n_bins, duplicates=duplicates
              )
          }
      )
  
      gb_columns = [group_column, quantile_column]
  
      gb = (
          test_data_binned[
              gb_columns + [prediction_column, target_column]
          ]
          .groupby(gb_columns)
          .mean()
          .sort_index(level=group_column, ascending=test_after_control)
      )
      return (
          gb.groupby(quantile_column)
          .diff()
          .dropna()
          .reset_index(drop=True)
      )
  
imports: import pandas
  from toolz import curry
  from fklearn.types import EvalReturnType, UncurriedEvalFnType
  from fklearn.validation.evaluators import r2_evaluator
label_desc: Use image node_id 2 for calling a global function with example usage: cate_mean_by_bin(test_data, group_column, control_group_name, bin_column, n_bins, allow_dropped_bins, prediction_column, target_column) and returns: gb