code: def class_prediction_error(
      estimator,
      X_train,
      y_train,
      X_test=None,
      y_test=None,
      ax=None,
      classes=None,
      encoder=None,
      is_fitted="auto",
      force_model=False,
      show=True,
      **kwargs,
  ):
      """Class Prediction Error
  
      Divides the dataset X and y into train and test splits, fits the model on the train
      split, then scores the model on the test split. The visualizer displays the support
      for each class in the fitted classification model displayed as a stacked bar plot.
      Each bar is segmented to show the distribution of predicted classes for each class.
  
      Parameters
      ----------
      estimator : estimator
          A scikit-learn estimator that should be a classifier. If the model is
          not a classifier, an exception is raised. If the internal model is not
          fitted, it is fit when the visualizer is fitted, unless otherwise specified
          by ``is_fitted``.
  
      X_train : ndarray or DataFrame of shape n x m
          A feature array of n instances with m features the model is trained on.
          Used to fit the visualizer and also to score the visualizer if test splits are
          not directly specified.
  
      y_train : ndarray or Series of length n
          An array or series of target or class values. Used to fit the visualizer and
          also to score the visualizer if test splits are not specified.
  
      X_test : ndarray or DataFrame of shape n x m, default: None
          An optional feature array of n instances with m features that the model
          is scored on if specified, using X_train as the training data.
  
      y_test : ndarray or Series of length n, default: None
          An optional array or series of target or class values that serve as actual
          labels for X_test for scoring purposes.
  
      ax : matplotlib Axes, default: None
          The axes to plot the figure on. If not specified the current axes will be
          used (or generated if required).
  
      classes : list of str, defult: None
          The class labels to use for the legend ordered by the index of the sorted
          classes discovered in the ``fit()`` method. Specifying classes in this
          manner is used to change the class names to a more specific format or
          to label encoded integer classes. Some visualizers may also use this
          field to filter the visualization for specific classes. For more advanced
          usage specify an encoder rather than class labels.
  
      encoder : dict or LabelEncoder, default: None
          A mapping of classes to human readable labels. Often there is a mismatch
          between desired class labels and those contained in the target variable
          passed to ``fit()`` or ``score()``. The encoder disambiguates this mismatch
          ensuring that classes are labeled correctly in the visualization.
  
      is_fitted : bool or str, default="auto"
          Specify if the wrapped estimator is already fitted. If False, the estimator
          will be fit when the visualizer is fit, otherwise, the estimator will not be
          modified. If "auto" (default), a helper method will check if the estimator
          is fitted before fitting it again.
  
      force_model : bool, default: False
          Do not check to ensure that the underlying estimator is a classifier. This
          will prevent an exception when the visualizer is initialized but may result
          in unexpected or unintended behavior.
  
      show: bool, default: True
          If True, calls ``show()``, which in turn calls ``plt.show()`` however
          you cannot call ``plt.savefig`` from this signature, nor
          ``clear_figure``. If False, simply calls ``finalize()``
  
      kwargs: dict
          Keyword arguments passed to the visualizer base classes.
  
      Returns
      -------
      viz : ClassPredictionError
          Returns the fitted, finalized visualizer
      """
      # Instantiate the visualizer
      viz = ClassPredictionError(
          estimator=estimator,
          ax=ax,
          classes=classes,
          encoder=encoder,
          is_fitted=is_fitted,
          force_model=force_model,
          **kwargs,
      )
  
      # Fit the visualizer (calls draw)
      viz.fit(X_train, y_train, **kwargs)
  
      # Score the visualizer
      if X_test is not None and y_test is not None:
          viz.score(X_test, y_test)
      elif X_test is not None or y_test is not None:
          raise YellowbrickValueError(
              "must specify both X_test and y_test or neither"
          )
      else:
          viz.score(X_train, y_train)
  
      # Draw the final visualization
      if show:
          viz.show()
      else:
          viz.finalize()
  
      # Return the visualizer
      return viz
  
file_path: yellowbrick/yellowbrick/classifier/class_prediction_error.py
imports: import numpy
  from sklearn.utils.multiclass import unique_labels
  from yellowbrick.draw import bar_stack
  from yellowbrick.classifier.base import ClassificationScoreVisualizer
  from yellowbrick.exceptions import ModelError, YellowbrickValueError, NotFitted
label_desc: Use image node_id 1 for calling a global function with example usage: class_prediction_error(estimator, X_train, y_train, X_test, y_test, ax, classes, encoder, is_fitted, force_model, show) and returns: viz