class_docstr: This wrapper handles sklearn models for image classification.
class_docstr_tok: ["This","wrapper","handles","sklearn","models","for","image","classification","."]
docstr: Preprocess a dataset with images and labels for use in training.
docstr_tok: ["Preprocess","a","dataset","with","images","and","labels","for","use","in","training","."]
code: def _preprocess_for_training(self, name, data):
      """Preprocess a dataset with images and labels for use in training."""
  
      if data is None:  # val/test can be empty´
          logger.info(f"{name}: Not given")
          return None, None
      else:
          # Convert format.
          logger.info(f"{name}:")
          logger.info(
              f"    data format: {preprocessing.recognize_data_format(data)}"
          )
          # TODO: Properly resize numpy arrays.
          data = preprocessing.to_numpy(data, resize=28, crop=28)
          images, labels = data
          logger.info(f"    samples: {len(images)}")
          logger.info(f"    image shape: {images.shape[1:]}")
  
          # Get number of classes.
          # TODO: Raise error if num_classes diverges between datasets.
          # TODO: Raise error if num_classes config param is given.
          num_classes = len(np.unique(labels))
          logger.info(f"    classes: {num_classes}")
  
          # Flatten.
          self._original_image_size = images.shape[1:]
          images = images.reshape(len(images), -1)
          logger.info(
              f"    flattened images (to {images.shape[1]} features)"
          )
  
          # Scale mean and std.
          if name == "train":
              self.scaler = sklearn.preprocessing.StandardScaler().fit(
                  images
              )
          images = self.scaler.transform(images)
          logger.info(
              "    scaled to mean 0, std 1 (based on train set)"
          )
  
          # Shuffle train set.
          if name == "train":
              images, labels = shuffle(images, labels)
              logger.info("    shuffled")
  
          return images, labels
  
imports: import sklearn.preprocessing
  from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
  from sklearn.gaussian_process import GaussianProcessClassifier
  from sklearn.linear_model import LogisticRegression, SGDClassifier, Perceptron, PassiveAggressiveClassifier
  from sklearn.naive_bayes import GaussianNB
  from sklearn.neighbors import KNeighborsClassifier
  from sklearn.neural_network import MLPClassifier
  from sklearn.svm import SVC, LinearSVC
  from sklearn.tree import DecisionTreeClassifier, ExtraTreeClassifier
  from sklearn.utils import shuffle
  import joblib
  import numpy
  from loguru import logger
  from ..model_wrapper import ModelWrapper
  from .None import preprocessing, visualization
label_desc: Use image node_id 2 for calling the SklearnImageClassificationWrapper obj's underlying member method code with example usage: obj._preprocess_for_training(name, data) and returns: None,  None, images,  labels