class_docstr: ```
  Abstract class used to tune and train Keras models. The fit method is
  an abstract method and must be implemented by subclasses.
  ```
class_docstr_tok: ["``","`","Abstract","class","used","to","tune","and","train","Keras","models",".","The","fit","method","is","an","abstract","method","and","must","be","implemented","by","subclasses",".","``","`"]
docstr: ```
  Returns confusion matrix and optionally prints
  a classification report.
  For multilabel classification problems,confusion matrices are not supported,
  but classification reports are.
  
  By default, this uses val_data, as supplied to ktrain.get_learner().
  Other validation or test data can be optionally be supplied as argument.
  Supply class_names to include labels instead of intenger class integer values in classification report.
  Args:
    val_data(Dataset|np.ndarray): validation data.  If None, self.val_data is used.
    print_report(bool): If True, classification report will be printed. If False, report will be saved to CSV
                        at save path. Not applicable to regression models.
    save_path(str): Classification report will be saved to this file path/name if print_report=False
    class_names(list): list of class names to be used in classification report instead of
                       class integer IDs.
  ```
docstr_tok: ["``","`","Returns","confusion","matrix","and","optionally","prints","a","classification","report",".","For","multilabel","classification","problems",",","confusion","matrices","are","not","supported",",","but","classification","reports","are",".","By","default",",","this","uses","val_data",",","as","supplied","to","ktrain.get_learner","(",")",".","Other","validation","or","test","data","can","be","optionally","be","supplied","as","argument",".","Supply","class_names","to","include","labels","instead","of","intenger","class","integer","values","in","classification","report",".","Args",":","val_data","(","Dataset|np.ndarray",")",":","validation","data",".","If","None",",","self.val_data","is","used",".","print_report","(","bool",")",":","If","True",",","classification","report","will","be","printed",".","If","False",",","report","will","be","saved","to","CSV","at","save","path",".","Not","applicable","to","regression","models",".","save_path","(","str",")",":","Classification","report","will","be","saved","to","this","file","path\/name","if","print_report=False","class_names","(","list",")",":","list","of","class","names","to","be","used","in","classification","report","instead","of","class","integer","IDs",".","``","`"]
code: def validate(
      self,
      val_data=None,
      print_report=True,
      save_path="ktrain_classification_report.csv",
      class_names=[],
  ):
      """
      ```
      Returns confusion matrix and optionally prints
      a classification report.
      For multilabel classification problems,confusion matrices are not supported,
      but classification reports are.
  
      By default, this uses val_data, as supplied to ktrain.get_learner().
      Other validation or test data can be optionally be supplied as argument.
      Supply class_names to include labels instead of intenger class integer values in classification report.
      Args:
        val_data(Dataset|np.ndarray): validation data.  If None, self.val_data is used.
        print_report(bool): If True, classification report will be printed. If False, report will be saved to CSV
                            at save path. Not applicable to regression models.
        save_path(str): Classification report will be saved to this file path/name if print_report=False
        class_names(list): list of class names to be used in classification report instead of
                           class integer IDs.
      ```
      """
      if val_data is not None:
          val = val_data
      else:
          val = self.val_data
  
      classification, multilabel = U.is_classifier(self.model)
      if not classification:
          # warnings.warn('learner.validate is only for classification problems. '
          #'For regression, etc., use learner.predict and learner.ground_truth '
          #'to manually validate.')
          # return
          pass
      is_multilabel = U.is_multilabel(val) or multilabel
      y_pred = self.predict(val_data=val)
      y_true = self.ground_truth(val_data=val)
      y_pred = np.squeeze(y_pred)
      y_true = np.squeeze(y_true)
  
      # regression evaluation
      if not classification:
          from sklearn.metrics import (
              mean_absolute_error,
              mean_squared_error,
          )
  
          regout = []
          metrics = U.metrics_from_model(self.model)
          for m in metrics:
              if m in ["mae", "mean_absolute_error"]:
                  regout.append(
                      (m, mean_absolute_error(y_true, y_pred))
                  )
              elif m in ["mse", "mean_squared_error"]:
                  regout.append((m, mean_squared_error(y_true, y_pred)))
          if not regout:
              warnings.warn(
                  "%s is not supported by validate/evaluate - falling back to MAE"
              )
              regout.append(
                  ("mae", mean_absolute_error(y_true, y_pred))
              )
          return regout
  
      if len(y_pred.shape) == 1:
          y_pred = np.where(y_pred > 0.5, 1, 0)
          y_true = np.where(y_true > 0.5, 1, 0)
      elif is_multilabel:
          from sklearn.preprocessing import binarize
  
          y_pred = binarize(y_pred, threshold=0.5)
      else:
          y_pred = np.argmax(y_pred, axis=1)
          y_true = np.argmax(y_true, axis=1)
  
      if print_report or save_path is not None:
          if class_names:
              try:
                  class_names = [str(s) for s in class_names]
              except:
                  pass
              report = classification_report(
                  y_true,
                  y_pred,
                  target_names=class_names,
                  output_dict=not print_report,
              )
          else:
              report = classification_report(
                  y_true,
                  y_pred,
                  output_dict=not print_report,
                  zero_division=0,
              )
          if print_report:
              print(report)
          else:
              df = pd.DataFrame(report).transpose()
              df.to_csv(save_path)
              print("classification report saved to: %s" % (save_path))
          cm_func = confusion_matrix
      if is_multilabel:
          warnings.warn(
              "Confusion matrices do not currently support multilabel classification, so returning None"
          )
          return
  
      cm = confusion_matrix(y_true, y_pred)
      return cm
  
imports: from .None import utils
  from .graph.predictor import LinkPredictor, NodePredictor
  from .graph.preprocessor import LinkPreprocessor, NodePreprocessor
  from .imports import *
  from .lroptimize.lrfinder import *
  from .tabular.predictor import TabularPredictor
  from .tabular.preprocessor import TabularPreprocessor
  from .text.ner.predictor import NERPredictor
  from .text.ner.preprocessor import NERPreprocessor
  from .text.predictor import TextPredictor
  from .text.preprocessor import BERTPreprocessor, TextPreprocessor, TransformersPreprocessor
  from .vision.predictor import ImagePredictor
  from .vision.preprocessor import ImagePreprocessor
label_desc: Use image node_id 6 for calling the Learner obj's underlying member method code with example usage: obj.validate(val_data, print_report, save_path, class_names) and returns: cm, regout