class_docstr: Create Aspect
  
  Explanation methods that do not take into account dependencies between variables
  can produce misleading results. This class creates a representation of a model based
  on an Explainer object. In addition, it calculates the relationships between
  the variables that can be used to create explanations. Methods of this class produce
  explanation objects, that contain the main result attribute, and can be visualised
  using the plot method.
  
  The `explainer` is the only required parameter.
  
  Parameters
  ----------
  explainer : Explainer object
      Model wrapper created using the Explainer class.
  depend_method: {'assoc', 'pps'} or function, optional
      The method of calculating the dependencies between variables (i.e. the dependency
      matrix). Default is `'assoc'`, which means the use of statistical association
      (correlation coefficient, Cramér's V based on Pearson's chi-squared statistic 
      and eta-quared based on Kruskal-Wallis H-statistic);
      `'pps'` stands for Power Predictive Score.
      NOTE: When a function is passed, it is called with the `explainer.data` and it
      must return a symmetric dependency matrix (`pd.DataFrame` with variable names as
      columns and rows).
  clust_method : {'complete', 'single', 'average', 'weighted', 'centroid', 'median', 'ward'}, optional
      The linkage algorithm to use for variables hierarchical clustering
      (default is `'complete'`).
  corr_method : {'spearman', 'pearson', 'kendall'}, optional
      The method of calculating correlation between numerical variables
      (default is `'spearman'`).
      NOTE: Ignored if `depend_method` is not `'assoc'`.
  agg_method : {'max', 'min', 'avg'}, optional
      The method of aggregating the PPS values for pairs of variables
      (default is `'max'`).
      NOTE: Ignored if `depend_method` is not `'pps'`.
  
  Attributes
  --------
  explainer : Explainer object
      Model wrapper created using the Explainer class.
  depend_method : {'assoc', 'pps'} or function
      The method of calculating the dependencies between variables.
  clust_method : {'complete', 'single', 'average', 'weighted', 'centroid', 'median', 'ward'}
      The linkage algorithm to use for variables hierarchical clustering.
  corr_method : {'spearman', 'pearson', 'kendall'}
      The method of calculating correlation between numerical variables.
  agg_method : {'max', 'min', 'avg'}
      The method of aggregating the PPS values for pairs of variables.
  depend_matrix : pd.DataFrame
      The dependency matrix (with variable names as columns and rows).
  linkage_matrix :
      The hierarchical clustering of variables encoded as a `scipy` linkage matrix.
  
  Notes
  -----
  - assoc, eta-squared: http://tss.awf.poznan.pl/files/3_Trends_Vol21_2014__no1_20.pdf
  - assoc, Cramér's V: http://stats.lse.ac.uk/bergsma/pdf/cramerV3.pdf
  - PPS: https://github.com/8080labs/ppscore
  - triplot: https://arxiv.org/abs/2104.03403
class_docstr_tok: ["Create","Aspect","Explanation","methods","that","do","not","take","into","account","dependencies","between","variables","can","produce","misleading","results",".","This","class","creates","a","representation","of","a","model","based","on","an","Explainer","object",".","In","addition",",","it","calculates","the","relationships","between","the","variables","that","can","be","used","to","create","explanations",".","Methods","of","this","class","produce","explanation","objects",",","that","contain","the","main","result","attribute",",","and","can","be","visualised","using","the","plot","method",".","The","`","explainer","`","is","the","only","required","parameter",".","Parameters","--","--","--","--","--","explainer",":","Explainer","object","Model","wrapper","created","using","the","Explainer","class",".","depend_method",":","{","'assoc","'",",","'pps","'","}","or","function",",","optional","The","method","of","calculating","the","dependencies","between","variables","(","i.e",".","the","dependency","matrix",")",".","Default","is","`","'assoc","'","`",",","which","means","the","use","of","statistical","association","(","correlation","coefficient",",","Cram\u00e9r","'s","V","based","on","Pearson","'s","chi-squared","statistic","and","eta-quared","based","on","Kruskal-Wallis","H-statistic",")",";","`","'pps","'","`","stands","for","Power","Predictive","Score",".","NOTE",":","When","a","function","is","passed",",","it","is","called","with","the","`","explainer.data","`","and","it","must","return","a","symmetric","dependency","matrix","(","`","pd.DataFrame","`","with","variable","names","as","columns","and","rows",")",".","clust_method",":","{","'complete","'",",","'single","'",",","'average","'",",","'weighted","'",",","'centroid","'",",","'median","'",",","'ward","'","}",",","optional","The","linkage","algorithm","to","use","for","variables","hierarchical","clustering","(","default","is","`","'complete","'","`",")",".","corr_method",":","{","'spearman","'",",","'pearson","'",",","'kendall","'","}",",","optional","The","method","of","calculating","correlation","between","numerical","variables","(","default","is","`","'spearman","'","`",")",".","NOTE",":","Ignored","if","`","depend_method","`","is","not","`","'assoc","'","`",".","agg_method",":","{","'max","'",",","'min","'",",","'avg","'","}",",","optional","The","method","of","aggregating","the","PPS","values","for","pairs","of","variables","(","default","is","`","'max","'","`",")",".","NOTE",":","Ignored","if","`","depend_method","`","is","not","`","'pps","'","`",".","Attributes","--","--","--","--","explainer",":","Explainer","object","Model","wrapper","created","using","the","Explainer","class",".","depend_method",":","{","'assoc","'",",","'pps","'","}","or","function","The","method","of","calculating","the","dependencies","between","variables",".","clust_method",":","{","'complete","'",",","'single","'",",","'average","'",",","'weighted","'",",","'centroid","'",",","'median","'",",","'ward","'","}","The","linkage","algorithm","to","use","for","variables","hierarchical","clustering",".","corr_method",":","{","'spearman","'",",","'pearson","'",",","'kendall","'","}","The","method","of","calculating","correlation","between","numerical","variables",".","agg_method",":","{","'max","'",",","'min","'",",","'avg","'","}","The","method","of","aggregating","the","PPS","values","for","pairs","of","variables",".","depend_matrix",":","pd.DataFrame","The","dependency","matrix","(","with","variable","names","as","columns","and","rows",")",".","linkage_matrix",":","The","hierarchical","clustering","of","variables","encoded","as","a","`","scipy","`","linkage","matrix",".","Notes","--","--","-","-","assoc",",","eta-squared",":","http",":","\/\/tss.awf.poznan.pl\/files\/3_Trends_Vol21_2014__no1_20.pdf","-","assoc",",","Cram\u00e9r","'s","V",":","http",":","\/\/stats.lse.ac.uk\/bergsma\/pdf\/cramerV3.pdf","-","PPS",":","https",":","\/\/github.com\/8080labs\/ppscore","-","triplot",":","https",":","\/\/arxiv.org\/abs\/2104.03403"]
code: def get_aspects(self, h=0.5, n=None):
      from scipy.cluster.hierarchy import fcluster
  
      """Form aspects of variables from the hierarchical clustering
  
          Parameters
          ----------
          h : float, optional
              Threshold to apply when forming aspects, i.e., the minimum value of the dependency
              between the variables grouped in one aspect (default is `0.5`).
              NOTE: Ignored if `n` is not `None`.
          n : int, optional
              Maximum number of aspects to form 
              (default is `None`, which means the use of `h` parameter).
  
          Returns
          -------
          dict of lists
              Variables grouped in aspects, e.g. `{'aspect_1': ['x1', 'x2'], 'aspect_2': ['y1', 'y2']}`.
          """
      if n is None:
          aspect_label = fcluster(
              self.linkage_matrix, 1 - h, criterion="distance"
          )
      else:
          aspect_label = fcluster(
              self.linkage_matrix, n, criterion="maxclust"
          )
      aspects = pd.DataFrame(
          {
              "feature": self.depend_matrix.columns,
              "aspect": aspect_label,
          }
      )
      aspects = (
          aspects.groupby("aspect")["feature"].apply(list).reset_index()
      )
      aspects_dict = {}
  
      # rename an aspect when there is a single variable in it
      i = 1
      for index, row in aspects.iterrows():
          if len(row["feature"]) > 1:
              aspects_dict[f"aspect_{i}"] = row["feature"]
              i += 1
          else:
              aspects_dict[row["feature"][0]] = row["feature"]
  
      return aspects_dict
  
file_path: DALEX/python/dalex/dalex/aspect/object.py
imports: import numpy
  import pandas
  from dalex.aspect._model_aspect_importance.object import ModelAspectImportance
  from dalex.aspect._predict_aspect_importance.object import PredictAspectImportance
  from dalex.aspect._model_triplot.object import ModelTriplot
  from dalex.aspect._predict_triplot.object import PredictTriplot
  from .None import utils, checks, plot
  from ..None import _theme
label_desc: Use image node_id 2 for calling the Aspect obj's underlying member method code with example usage: obj.get_aspects(h, n) and returns: aspects_dict