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: Fit the visualizer to the the target variables, which must be 1D
  vectors containing discrete (classification) data. Fit has two modes:
  
  1. Balance mode: if only y_train is specified
  2. Compare mode: if both train and test are specified
  
  In balance mode, the bar chart is displayed with each class as its own
  color. In compare mode, a side-by-side bar chart is displayed colored
  by train or test respectively.
  
  Parameters
  ----------
  y_train : array-like
      Array or list of shape (n,) that contains discrete data.
  
  y_test : array-like, optional
      Array or list of shape (m,) that contains discrete data. If
      specified, the bar chart will be drawn in compare mode.
docstr_tok: ["Fit","the","visualizer","to","the","the","target","variables",",","which","must","be","1D","vectors","containing","discrete","(","classification",")","data",".","Fit","has","two","modes",":","1",".","Balance","mode",":","if","only","y_train","is","specified","2",".","Compare","mode",":","if","both","train","and","test","are","specified","In","balance","mode",",","the","bar","chart","is","displayed","with","each","class","as","its","own","color",".","In","compare","mode",",","a","side-by-side","bar","chart","is","displayed","colored","by","train","or","test","respectively",".","Parameters","--","--","--","--","--","y_train",":","array-like","Array","or","list","of","shape","(","n",",",")","that","contains","discrete","data",".","y_test",":","array-like",",","optional","Array","or","list","of","shape","(","m",",",")","that","contains","discrete","data",".","If","specified",",","the","bar","chart","will","be","drawn","in","compare","mode","."]
code: def fit(self, y_train, y_test=None):
      """
      Fit the visualizer to the the target variables, which must be 1D
      vectors containing discrete (classification) data. Fit has two modes:
  
      1. Balance mode: if only y_train is specified
      2. Compare mode: if both train and test are specified
  
      In balance mode, the bar chart is displayed with each class as its own
      color. In compare mode, a side-by-side bar chart is displayed colored
      by train or test respectively.
  
      Parameters
      ----------
      y_train : array-like
          Array or list of shape (n,) that contains discrete data.
  
      y_test : array-like, optional
          Array or list of shape (m,) that contains discrete data. If
          specified, the bar chart will be drawn in compare mode.
      """
  
      # check to make sure that y_train is not a 2D array, e.g. X
      if y_train.ndim == 2:
          raise YellowbrickValueError(
              (
                  "fit has changed to only require a 1D array, y "
                  "since version 0.9; please see the docs for more info"
              )
          )
  
      # Check the target types for the y variables
      self._validate_target(y_train)
      self._validate_target(y_test)
  
      # Get the unique values from the dataset
      targets = (y_train,) if y_test is None else (y_train, y_test)
      self.classes_ = unique_labels(*targets)
  
      # Validate the classes with the class names
      if self.labels is not None:
          if len(self.labels) != len(self.classes_):
              raise YellowbrickValueError(
                  (
                      "discovered {} classes in the data, does not match "
                      "the {} labels specified."
                  ).format(len(self.classes_), len(self.labels))
              )
  
      # Determine if we're in compare or balance mode
      self._mode = BALANCE if y_test is None else COMPARE
  
      # Compute the support values
      if self._mode == BALANCE:
          self.support_ = np.array(
              [(y_train == idx).sum() for idx in self.classes_]
          )
  
      else:
          self.support_ = np.array(
              [
                  [(y == idx).sum() for idx in self.classes_]
                  for y in targets
              ]
          )
  
      # Draw the bar chart
      self.draw()
  
      # Fit returns self
      return self
  
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 2 for calling the ClassBalance obj's underlying member method code with example usage: obj.fit(y_train, y_test) and returns: self