Toggle Menu
Prev Up Next

scikit-learn 1.3.2
Other versions

Please cite us if you use the software.

# `sklearn.base`.TransformerMixin

class sklearn.base.TransformerMixin

  Mixin class for all transformers in scikit-learn.

  If get_feature_names_out is defined, then `BaseEstimator` will automatically wrap `transform` and `fit_transform` to follow the `set_output` API. See the Developer API for set_output for details.

  `OneToOneFeatureMixin` and `ClassNamePrefixFeaturesOutMixin` are helpful mixins for defining get_feature_names_out.

  Methods

  `fit_transform`(X[, y]) | Fit to data, then transform it.
  `set_output`(*[, transform]) | Set output container.

  fit_transform(X, y=None, **fit_params)

    Fit to data, then transform it.

    Fits transformer to `X` and `y` with optional parameters `fit_params` and returns a transformed version of `X`.

    Parameters:
      X array-like of shape (n_samples, n_features)

        Input samples.

      y array-like of shape (n_samples,) or (n_samples, n_outputs), default=None

        Target values (None for unsupervised transformations).

      **fit_params dict

        Additional fit parameters.

    Returns:
      X_new ndarray array of shape (n_samples, n_features_new)

        Transformed array.

  set_output(*, transform=None)

    Set output container.

    See Introducing the set_output API for an example on how to use the API.

    Parameters:
      transform{“default”, “pandas”}, default=None

        Configure output of `transform` and `fit_transform`.

        - `"default"`: Default output format of a transformer

        - `"pandas"`: DataFrame output

        - `None`: Transform configuration is unchanged

    Returns:
      self estimator instance

        Estimator instance.

## Examples using `sklearn.base.TransformerMixin`

Metadata Routing

Metadata Routing

Approximate nearest neighbors in TSNE

Approximate nearest neighbors in TSNE