code: def explain_rows(
      train_data: pd.DataFrame,
      model: TabularPredictor,
      rows: pd.DataFrame,
      positive_class: Optional = None,
      display_rows: bool = False,
      plot: Optional[str] = "force",
      baseline_sample: int = 100,
      return_state: bool = False,
      fit_args: Optional[Dict[str, Any]] = None,
      **kwargs,
  ) -> Optional[AnalysisState]:
      """
      Kernel SHAP is a method that uses a special weighted linear regression
      to compute the importance of each feature. The computed importance values
      are Shapley values from game theory and also coefficients from a local linear
      regression values analysis for the given rows.
  
      The results are rendered either as force plot or waterfall plot.
  
      Parameters
      ----------
      train_data: DataFrame
          training dataset
      model: TabularPredictor
          trained AutoGluon predictor
      rows: pd.DataFrame,
          rows to explain
      positive_class: Optional
          Optionally specify positive class to explain; if not provided, the value will be autodetected.
          For binary it's derived from `model.positive_class`.
          For multiclass it's the last column in prediction probabilities.
      display_rows: bool, default = False
          if `True` then display the row before the explanation chart
      plot: Optional[str], default = 'force'
          type of plot to visualize the Shapley values. Supported keys:
          - `force` - Visualize the given SHAP values with an additive force layout
          - `waterfall` - Visualize the given SHAP values with a waterfall layout
          - `None` - do not use any visualization
      baseline_sample: int, default = 100
          The background dataset size to use for integrating out features. To determine the impact
          of a feature, that feature is set to "missing" and the change in the model output
          is observed.
      return_state: bool, default = False
          return state if `True`
      fit_args: Optional[Dict[str, Any]], default = None,
          kwargs for `ShapAnalysis`.
      kwargs
  
      Examples
      --------
      >>> import autogluon.eda.auto as auto
      >>>
      >>> state = auto.quick_fit(
      >>>     train_data=...,
      >>>     label=...,
      >>>     return_state=True,
      >>> )
      >>>
      >>> # quick_fit stored model in `state.model`, and can be passed here.
      >>> # This will visualize 1st row of rows with the highest errors;
      >>> # these rows are stored under `state.model_evaluation.highest_error`
      >>> auto.explain_rows(
      >>>     train_data=...,
      >>>     model=state.model,
      >>>     display_rows=True,
      >>>     rows=state.model_evaluation.highest_error[:1],
      >>>     plot='waterfall',  # visualize as waterfall plot
      >>> )
  
      See Also
      --------
      :py:class:`~shap.KernelExplainer`
      :py:class:`~autogluon.eda.analysis.explain.ShapAnalysis`
      :py:class:`~autogluon.eda.visualization.explain.ExplainForcePlot`
      :py:class:`~autogluon.eda.visualization.explain.ExplainWaterfallPlot`
      """
  
      if fit_args is None:
          fit_args = {}
  
      if plot is None:
          viz_facets = None
      else:
          supported_plots = {
              "force": ExplainForcePlot,
              "waterfall": ExplainWaterfallPlot,
          }
          viz_cls = supported_plots.get(plot, None)
          assert viz_cls is not None, (
              f"plot must be one of the following values: {','.join(supported_plots.keys())}. "
              f"If no visualization required, then `None` can be passed."
          )
          viz_facets = [viz_cls(display_rows=display_rows, **kwargs)]
  
      return analyze(
          train_data=train_data[model.original_features],
          model=model,
          return_state=return_state,
          anlz_facets=[ShapAnalysis(rows, positive_class=positive_class, baseline_sample=baseline_sample, **fit_args)],  # type: ignore
          viz_facets=viz_facets,  # type: ignore
      )
  
imports: import logging
  from typing import Any, Dict, List, Optional, Tuple, Union
  import pandas
  from autogluon.common.utils.log_utils import verbosity2loglevel
  from autogluon.features import CategoryFeatureGenerator
  from autogluon.tabular import TabularPredictor
  from ..None import AnalysisState
  from ..analysis import AnomalyDetectorAnalysis, ApplyFeatureGenerator, AutoGluonModelEvaluator, AutoGluonModelQuickFit, Correlation, DistributionFit, FeatureInteraction, MissingValuesAnalysis, ProblemTypeControl, ShapAnalysis, TrainValidationSplit, XShiftDetector
  from ..analysis.base import AbstractAnalysis, BaseAnalysis, SaveArgsToState
  from ..analysis.dataset import DatasetSummary, LabelInsightsAnalysis, RawTypesAnalysis, Sampler, SpecialTypesAnalysis, VariableTypeAnalysis
  from ..analysis.interaction import FeatureDistanceAnalysis
  from ..state import is_key_present_in_state
  from ..utils.common import expand_nested_args_into_nested_maps, get_empty_dict_if_none
  from ..utils.defaults import QuickFitDefaults
  from ..visualization import AnomalyScoresVisualization, ConfusionMatrix, CorrelationVisualization, DatasetStatistics, DatasetTypeMismatch, ExplainForcePlot, ExplainWaterfallPlot, FeatureImportance, FeatureInteractionVisualization, LabelInsightsVisualization, MarkdownSectionComponent, MissingValues, ModelLeaderboard, PropertyRendererComponent, RegressionEvaluation, XShiftSummary
  from ..visualization.base import AbstractVisualization
  from ..visualization.interaction import FeatureDistanceAnalysisVisualization, PDPInteractions
  from ..visualization.layouts import SimpleVerticalLinearLayout
label_desc: Use image node_id 14 for calling a global function with example usage: explain_rows(train_data, model, rows, positive_class, display_rows, plot, baseline_sample, return_state, fit_args) and returns: analyze