Base Classes
To work properly with all the sklearn methods and components, each transformer needs to have a specific set of characteristics. This class ensures just that. Nearly every other class in TubesML inherits from this class.
- class tubesml.base.BaseTransformer
This is the base class for all the transformers.
- Attributes:
- columns: an empty list that gets reset by the fit method, populated by the transform method,
returned by the
get_feature_names_outmethod
- fit(X, y=None)
Method to train the transformer.
It also reset the
columnsattribute- Parameters:
X – {array-like} of shape (n_samples, n_features) The training input samples.
y – array-like of shape (n_samples,) or (n_samples, n_outputs), optional The target values (class labels) as integers or strings.
- get_feature_names_out()
Returns the
columnsattribute, useful to well behave with other sklearn methods
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') BaseTransformer
Request metadata passed to the
scoremethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.Parameters
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns
- selfobject
The updated object.
- transform(X, y=None)
Method to transform the input data.
It populates the
columnsattribute with the columns of the output data- Parameters:
X – {array-like} of shape (n_samples, n_features) The input samples.
y – array-like of shape (n_samples,) or (n_samples, n_outputs), optional The target values (class labels) as integers or strings.
- tubesml.base.fit_wrapper(func)
Wrapper for the fit method. It stores the column order and resets the
columnsattribute
- tubesml.base.transform_wrapper(func)
Wrapper for the transform method. It makes sure the columns are in the same order as when the fit method was called and it populates the
columnsattribute