class_docstr: Defines the top-level Model Analysis API.
  Use RAIInsights to analyze errors, explain the most important
  features, compute counterfactuals and run causal analysis in a
  single API.
class_docstr_tok: ["Defines","the","top-level","Model","Analysis","API",".","Use","RAIInsights","to","analyze","errors",",","explain","the","most","important","features",",","compute","counterfactuals","and","run","causal","analysis","in","a","single","API","."]
docstr: Validate the inputs for the RAIInsights constructor.
  
  :param model: The model to compute RAI insights for.
      A model that implements sklearn-style predict or predict_proba
      or a function that accepts a 2d ndarray.
  :type model: object
  :param train: The training dataset including the label column.
  :type train: pandas.DataFrame
  :param test: The test dataset including the label column.
  :type test: pandas.DataFrame
  :param target_column: The name of the label column.
  :type target_column: str
  :param task_type: The task to run, can be `classification` or
      `regression`.
  :type task_type: str
  :param classes: The class labels in the training dataset
  :type classes: numpy.ndarray
  :param serializer: Picklable custom serializer with save and load
      methods defined for model that is not serializable. The save
      method returns a dictionary state and load method returns the
      model.
  :type serializer: object
  :param feature_metadata: Feature metadata for the train/test
      dataset to identify various kinds of features in the dataset.
  :type feature_metadata: FeatureMetadata
docstr_tok: ["Validate","the","inputs","for","the","RAIInsights","constructor",".",":","param","model",":","The","model","to","compute","RAI","insights","for",".","A","model","that","implements","sklearn-style","predict","or","predict_proba","or","a","function","that","accepts","a","2d","ndarray",".",":","type","model",":","object",":","param","train",":","The","training","dataset","including","the","label","column",".",":","type","train",":","pandas.DataFrame",":","param","test",":","The","test","dataset","including","the","label","column",".",":","type","test",":","pandas.DataFrame",":","param","target_column",":","The","name","of","the","label","column",".",":","type","target_column",":","str",":","param","task_type",":","The","task","to","run",",","can","be","`","classification","`","or","`","regression","`",".",":","type","task_type",":","str",":","param","classes",":","The","class","labels","in","the","training","dataset",":","type","classes",":","numpy.ndarray",":","param","serializer",":","Picklable","custom","serializer","with","save","and","load","methods","defined","for","model","that","is","not","serializable",".","The","save","method","returns","a","dictionary","state","and","load","method","returns","the","model",".",":","type","serializer",":","object",":","param","feature_metadata",":","Feature","metadata","for","the","train\/test","dataset","to","identify","various","kinds","of","features","in","the","dataset",".",":","type","feature_metadata",":","FeatureMetadata"]
code: def _validate_rai_insights_input_parameters(
      self,
      model: Any,
      train: pd.DataFrame,
      test: pd.DataFrame,
      target_column: str,
      task_type: str,
      classes: np.ndarray,
      serializer,
      feature_metadata: FeatureMetadata,
      **kwargs,
  ):
      """Validate the inputs for the RAIInsights constructor.
  
      :param model: The model to compute RAI insights for.
          A model that implements sklearn-style predict or predict_proba
          or a function that accepts a 2d ndarray.
      :type model: object
      :param train: The training dataset including the label column.
      :type train: pandas.DataFrame
      :param test: The test dataset including the label column.
      :type test: pandas.DataFrame
      :param target_column: The name of the label column.
      :type target_column: str
      :param task_type: The task to run, can be `classification` or
          `regression`.
      :type task_type: str
      :param classes: The class labels in the training dataset
      :type classes: numpy.ndarray
      :param serializer: Picklable custom serializer with save and load
          methods defined for model that is not serializable. The save
          method returns a dictionary state and load method returns the
          model.
      :type serializer: object
      :param feature_metadata: Feature metadata for the train/test
          dataset to identify various kinds of features in the dataset.
      :type feature_metadata: FeatureMetadata
      """
      valid_tasks = [
          ModelTask.CLASSIFICATION.value,
          ModelTask.REGRESSION.value,
      ]
      # Check if forecasting feature flag was passed as kwarg.
      # We specifically do not advertise for this until we want people to
      # use it.
      if kwargs.get(_FORECASTING_RAI_INSIGHTS_ENABLED, False):
          print(
              "WARNING: Support for the forecasting task type is not yet "
              "stable. Please do not use it except for testing purposes."
          )
          valid_tasks.append(ModelTask.FORECASTING.value)
      if task_type not in valid_tasks:
          message = (
              f"Unsupported task type '{task_type}'. "
              f"Should be one of {valid_tasks}"
          )
          raise UserConfigValidationException(message)
  
      if model is None:
          warnings.warn(
              "INVALID-MODEL-WARNING: No valid model is supplied. "
              "The explanations, error analysis and counterfactuals "
              "may not work"
          )
          if serializer is not None:
              raise UserConfigValidationException(
                  "No valid model is specified but model "
                  "serializer provided."
              )
  
      if serializer is not None:
          if not hasattr(serializer, "save"):
              raise UserConfigValidationException(
                  "The serializer does not implement save()"
              )
  
          if not hasattr(serializer, "load"):
              raise UserConfigValidationException(
                  "The serializer does not implement load()"
              )
  
          try:
              pickle.dumps(serializer)
          except Exception:
              raise UserConfigValidationException(
                  "The serializer should be serializable via pickle"
              )
  
      if not isinstance(train, pd.DataFrame) or not isinstance(
          test, pd.DataFrame
      ):
          raise UserConfigValidationException(
              "Unsupported data type for either train or test. "
              "Expecting pandas DataFrame for train and test."
          )
  
      if len(train) <= 0 or len(test) <= 0:
          raise UserConfigValidationException(
              "Either of the train/test are empty. "
              "Please provide non-empty dataframes for train "
              "and test sets."
          )
  
      if (
          len(set(train.columns) - set(test.columns)) != 0
          or len(set(test.columns) - set(train.columns)) != 0
      ):
          raise UserConfigValidationException(
              "The features in train and test data do not match"
          )
  
      if target_column not in list(
          train.columns
      ) or target_column not in list(test.columns):
          raise UserConfigValidationException(
              f"Target name {target_column} not present in train/test data"
          )
  
      categorical_features = feature_metadata.categorical_features
      if (
          categorical_features is not None
          and len(categorical_features) > 0
      ):
          if target_column in categorical_features:
              raise UserConfigValidationException(
                  f"Found target name {target_column} in "
                  "categorical feature list"
              )
  
          difference_set = set(categorical_features) - set(
              train.drop(columns=[target_column]).columns
          )
          if len(difference_set) > 0:
              message = (
                  "Feature names in categorical_features "
                  "do not exist in train data: "
                  f"{list(difference_set)}"
              )
              raise UserConfigValidationException(message)
  
      # Validate that the target column isn't continuous if the
      # user is running classification scenario
      # To address error thrown from sklearn here:  # noqa: E501
      # https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/utils/multiclass.py#L197
      y_data = train[target_column]
      if (
          task_type == ModelTask.CLASSIFICATION
          and pd.api.types.is_float_dtype(y_data.dtype)
          and np.any(y_data != y_data.astype(int))
      ):
          raise UserConfigValidationException(
              "Target column type must not be continuous "
              "for classification scenario."
          )
      # Check if any features exist that are not numeric, datetime, or
      # categorical.
      train_features = train.drop(columns=[target_column]).columns
      numeric_features = (
          train.drop(columns=[target_column])
          .select_dtypes(include="number")
          .columns.tolist()
      )
      string_features_set = set(train_features) - set(numeric_features)
      if (
          task_type == ModelTask.FORECASTING
          and feature_metadata is not None
          and feature_metadata.datetime_features is not None
      ):
          string_features_set = string_features_set - set(
              feature_metadata.datetime_features
          )
      non_categorical_or_time_string_columns = (
          string_features_set - set(categorical_features)
      )
      if len(non_categorical_or_time_string_columns) > 0:
          raise UserConfigValidationException(
              "The following string features were not "
              "identified as categorical features: "
              f"{non_categorical_or_time_string_columns}"
          )
  
      self._validate_feature_metadata(
          feature_metadata, train, task_type, model, target_column
      )
  
      if model is not None:
          # Pick one row from train and test data
          has_dropped_features = False
          if feature_metadata is not None and (
              feature_metadata.dropped_features is not None
              and len(feature_metadata.dropped_features) != 0
          ):
              has_dropped_features = True
              features_to_drop = feature_metadata.dropped_features + [
                  target_column
              ]
          else:
              features_to_drop = [target_column]
  
          actual_train_data = train.drop(
              columns=features_to_drop, axis=1
          )
          actual_test_data = test.drop(columns=features_to_drop, axis=1)
          if (
              len(actual_train_data.columns) == 0
              or len(actual_test_data.columns) == 0
          ):
              if has_dropped_features:
                  raise UserConfigValidationException(
                      "All features have been dropped from the dataset."
                      " Please do not drop all the features."
                  )
              else:
                  raise UserConfigValidationException(
                      "There is no feature in the dataset. Please make "
                      "sure that your dataset contains at least "
                      "one feature."
                  )
  
          self._wrap_model_if_needed(model)
  
          # Ensure that the model has the required methods and that they
          # do not change the input data.
          if task_type != ModelTask.FORECASTING:
              self._ensure_model_outputs(input_data=actual_train_data)
          self._ensure_model_outputs(input_data=actual_test_data)
  
          if task_type == ModelTask.REGRESSION:
              if hasattr(model, SKLearn.PREDICT_PROBA):
                  raise UserConfigValidationException(
                      "The regression model "
                      "provided has a predict_proba function. "
                      "Please check the task_type."
                  )
  
      if task_type == ModelTask.CLASSIFICATION:
          self._validate_classes(
              model,
              train,
              test,
              target_column,
              feature_metadata,
              classes,
          )
  
imports: import json
  import pickle
  import warnings
  from enum import Enum
  from pathlib import Path
  from typing import Any, List, Optional, Union
  import numpy
  import pandas
  from erroranalysis._internal.cohort_filter import FilterDataWithCohortFilters
  from erroranalysis._internal.process_categoricals import process_categoricals
  from raiutils.data_processing import convert_to_list
  from raiutils.exceptions import SystemErrorException, UserConfigValidationException
  from raiutils.models import Forecasting, ModelTask, SKLearn
  from responsibleai._interfaces import Dataset, RAIInsightsData, TabularDatasetMetadata
  from responsibleai._internal._forecasting_wrappers import _wrap_model
  from responsibleai._internal.constants import FileFormats, ManagerNames, Metadata, SerializationAttributes
  from responsibleai.feature_metadata import FeatureMetadata
  from responsibleai.managers.causal_manager import CausalManager
  from responsibleai.managers.counterfactual_manager import CounterfactualManager
  from responsibleai.managers.data_balance_manager import DataBalanceManager
  from responsibleai.managers.error_analysis_manager import ErrorAnalysisManager
  from responsibleai.managers.explainer_manager import ExplainerManager
  from responsibleai.rai_insights.rai_base_insights import RAIBaseInsights
label_desc: Use image node_id 9 for calling the RAIInsights obj's underlying member method code with example usage: obj._validate_rai_insights_input_parameters(model, train, test, target_column, task_type, classes, serializer, feature_metadata) without return types