class_docstr: Shared methods across categorical transformers.
  
  - BaseEstimator brings methods get_params() and set_params().
  - TransformerMixin brings method fit_transform()
  - GetFeatureNamesOutMixin brings method get_feature_names_out().
class_docstr_tok: ["Shared","methods","across","categorical","transformers",".","-","BaseEstimator","brings","methods","get_params","(",")","and","set_params","(",")",".","-","TransformerMixin","brings","method","fit_transform","(",")","-","GetFeatureNamesOutMixin","brings","method","get_feature_names_out","(",")","."]
docstr: Replace categories with the learned parameters.
  
  Parameters
  ----------
  X: pandas dataframe of shape = [n_samples, n_features].
      The dataset to transform.
  
  Returns
  -------
  X_new: pandas dataframe of shape = [n_samples, n_features].
      The dataframe containing the categories replaced by numbers.
docstr_tok: ["Replace","categories","with","the","learned","parameters",".","Parameters","--","--","--","--","--","X",":","pandas","dataframe","of","shape","=","[","n_samples",",","n_features","]",".","The","dataset","to","transform",".","Returns","--","--","--","-","X_new",":","pandas","dataframe","of","shape","=","[","n_samples",",","n_features","]",".","The","dataframe","containing","the","categories","replaced","by","numbers","."]
code: def transform(self, X: pd.DataFrame) -> pd.DataFrame:
      """Replace categories with the learned parameters.
  
      Parameters
      ----------
      X: pandas dataframe of shape = [n_samples, n_features].
          The dataset to transform.
  
      Returns
      -------
      X_new: pandas dataframe of shape = [n_samples, n_features].
          The dataframe containing the categories replaced by numbers.
      """
  
      X = self._check_transform_input_and_state(X)
  
      # check if dataset contains na
      _check_contains_na(X, self.variables_)
  
      # replace categories by the learned parameters
      for feature in self.encoder_dict_.keys():
          X[feature] = X[feature].map(self.encoder_dict_[feature])
  
          # if original variables are cast as categorical, they will remain
          # categorical after the encoding, and this is probably not desired
          if pd.api.types.is_categorical_dtype(X[feature]):
              if all(isinstance(x, int) for x in X[feature]):
                  X[feature] = X[feature].astype("int")
              else:
                  X[feature] = X[feature].astype("float")
  
      if self.unseen == "encode":
          X[self.variables_] = X[self.variables_].fillna(
              self._unseen, downcast="infer"
          )
      else:
          # check if nan values were introduced by the transformation
          self._check_nan_values_after_transformation(X)
  
      return X
  
imports: import warnings
  from typing import List, Union
  import pandas
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.utils.validation import check_is_fitted
  from feature_engine._base_transformers.mixins import GetFeatureNamesOutMixin
  from feature_engine._docstrings.init_parameters import _ignore_format_docstring, _variables_categorical_docstring
  from feature_engine._docstrings.substitute import Substitution
  from feature_engine._variable_handling.init_parameter_checks import _check_init_parameter_variables
  from feature_engine._variable_handling.variable_type_selection import _find_all_variables, _find_or_check_categorical_variables
  from feature_engine.dataframe_checks import _check_contains_na, _check_X_matches_training_df, check_X
  from feature_engine.tags import _return_tags
label_desc: Use image node_id 5 for calling the CategoricalMethodsMixin obj's underlying member method code with example usage: obj.transform(X) and returns: X