class_docstr: One of the biggest challenges for classification models is an imbalance of
  classes in the training data. The ClassBalance visualizer shows the
  relationship of the support for each class in both the training and test
  data by displaying how frequently each class occurs as a bar graph.
  
  The ClassBalance visualizer can be displayed in two modes:
  
  1. Balance mode: show the frequency of each class in the dataset.
  2. Compare mode: show the relationship of support in train and test data.
  
  These modes are determined by what is passed to the ``fit()`` method.
  
  Parameters
  ----------
  ax : matplotlib Axes, default: None
      The axis to plot the figure on. If None is passed in the current axes
      will be used (or generated if required).
  
  labels: list, optional
      A list of class names for the x-axis if the target is already encoded.
      Ensure that the labels are ordered lexicographically with respect to
      the values in the target. A common use case is to pass
      ``LabelEncoder.classes_`` as this parameter. If not specified, the labels
      in the data will be used.
  
  colors: list of strings
      Specify colors for the barchart (will override colormap if both are provided).
  
  colormap : string or matplotlib cmap
      Specify a colormap to color the classes.
  
  kwargs: dict, optional
      Keyword arguments passed to the super class. Here, used
      to colorize the bars in the histogram.
  
  Attributes
  ----------
  classes_ : array-like
      The actual unique classes discovered in the target.
  
  support_ : array of shape (n_classes,) or (2, n_classes)
      A table representing the support of each class in the target. It is a
      vector when in balance mode, or a table with two rows in compare mode.
  
  Examples
  --------
  To simply observe the balance of classes in the target:
  
  >>> viz = ClassBalance().fit(y)
  >>> viz.show()
  
  To compare the relationship between training and test data:
  
  >>> _, _, y_train, y_test = train_test_split(X, y, test_size=0.2)
  >>> viz = ClassBalance()
  >>> viz.fit(y_train, y_test)
  >>> viz.show()
class_docstr_tok: ["One","of","the","biggest","challenges","for","classification","models","is","an","imbalance","of","classes","in","the","training","data",".","The","ClassBalance","visualizer","shows","the","relationship","of","the","support","for","each","class","in","both","the","training","and","test","data","by","displaying","how","frequently","each","class","occurs","as","a","bar","graph",".","The","ClassBalance","visualizer","can","be","displayed","in","two","modes",":","1",".","Balance","mode",":","show","the","frequency","of","each","class","in","the","dataset",".","2",".","Compare","mode",":","show","the","relationship","of","support","in","train","and","test","data",".","These","modes","are","determined","by","what","is","passed","to","the","``","fit","(",")","``","method",".","Parameters","--","--","--","--","--","ax",":","matplotlib","Axes",",","default",":","None","The","axis","to","plot","the","figure","on",".","If","None","is","passed","in","the","current","axes","will","be","used","(","or","generated","if","required",")",".","labels",":","list",",","optional","A","list","of","class","names","for","the","x-axis","if","the","target","is","already","encoded",".","Ensure","that","the","labels","are","ordered","lexicographically","with","respect","to","the","values","in","the","target",".","A","common","use","case","is","to","pass","``","LabelEncoder.classes_","``","as","this","parameter",".","If","not","specified",",","the","labels","in","the","data","will","be","used",".","colors",":","list","of","strings","Specify","colors","for","the","barchart","(","will","override","colormap","if","both","are","provided",")",".","colormap",":","string","or","matplotlib","cmap","Specify","a","colormap","to","color","the","classes",".","kwargs",":","dict",",","optional","Keyword","arguments","passed","to","the","super","class",".","Here",",","used","to","colorize","the","bars","in","the","histogram",".","Attributes","--","--","--","--","--","classes_",":","array-like","The","actual","unique","classes","discovered","in","the","target",".","support_",":","array","of","shape","(","n_classes",",",")","or","(","2",",","n_classes",")","A","table","representing","the","support","of","each","class","in","the","target",".","It","is","a","vector","when","in","balance","mode",",","or","a","table","with","two","rows","in","compare","mode",".","Examples","--","--","--","--","To","simply","observe","the","balance","of","classes","in","the","target",":",">",">",">","viz","=","ClassBalance","(",")",".fit","(","y",")",">",">",">","viz.show","(",")","To","compare","the","relationship","between","training","and","test","data",":",">",">",">","_",",","_",",","y_train",",","y_test","=","train_test_split","(","X",",","y",",","test_size=0.2",")",">",">",">","viz","=","ClassBalance","(",")",">",">",">","viz.fit","(","y_train",",","y_test",")",">",">",">","viz.show","(",")"]
docstr: Renders the class balance chart on the specified axes from support.
docstr_tok: ["Renders","the","class","balance","chart","on","the","specified","axes","from","support","."]
code: def draw(self):
      """
      Renders the class balance chart on the specified axes from support.
      """
      # Number of colors is either number of classes or 2
      colors = resolve_colors(
          len(self.support_), colormap=self.colormap, colors=self.colors
      )
  
      if self._mode == BALANCE:
          self.ax.bar(
              np.arange(len(self.support_)),
              self.support_,
              color=colors,
              align="center",
              width=0.5,
          )
  
      # Compare mode
      else:
          bar_width = 0.35
          labels = ["train", "test"]
  
          for idx, support in enumerate(self.support_):
              index = np.arange(len(self.classes_))
              if idx > 0:
                  index = index + bar_width
  
              self.ax.bar(
                  index,
                  support,
                  bar_width,
                  color=colors[idx],
                  label=labels[idx],
              )
  
      return self.ax
  
file_path: yellowbrick/yellowbrick/target/class_balance.py
imports: import numpy
  from yellowbrick.style.colors import resolve_colors
  from yellowbrick.target.base import TargetVisualizer
  from yellowbrick.exceptions import YellowbrickValueError
  from sklearn.utils.multiclass import unique_labels, type_of_target
label_desc: Use image node_id 3 for calling the ClassBalance obj's underlying member method code with example usage: obj.draw() and returns: self