fl4health.feature_alignment.string_columns_transformer module¶
- class TextColumnTransformer(transformer)[source]¶
Bases:
BaseEstimator
,TransformerMixin
- __init__(transformer)[source]¶
The purpose of this class is to enable the application of text feature transformers from sklearn to a single-column pandas dataframe, which is not supported in the first place.
- Parameters:
transformer (TextFeatureTransformer) – Transformer to be applied
- fit(x, y=None)[source]¶
Fit the transformer to the provided dataframe. The dataframe should have a single string column The transformer is fit on the text from the single columns in the
X
dataframe.- Parameters:
X (pd.DataFrame) – Column on which to fit the transformer
y (pd.DataFrame | None, optional) – Not used. Defaults to None.
- Returns:
The fit transformer
- Return type:
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') TextColumnTransformer ¶
Request metadata passed to the
fit
method.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 tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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:
- xstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
x
parameter infit
.
- Returns:
- selfobject
The updated object.
- set_transform_request(*, x: bool | None | str = '$UNCHANGED$') TextColumnTransformer ¶
Request metadata passed to the
transform
method.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 totransform
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it totransform
.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:
- xstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
x
parameter intransform
.
- Returns:
- selfobject
The updated object.
- class TextMulticolumnTransformer(transformer)[source]¶
Bases:
BaseEstimator
,TransformerMixin
- __init__(transformer)[source]¶
The purpose of this class is to enable the application of text feature transformers from sklearn to multiple string columns, which is not supported in the first place.
- Parameters:
transformer (TextFeatureTransformer) – Transformer to be applied
- fit(x, y=None)[source]¶
Fit the transformer to the provided dataframe. The dataframe should have multiple string columns The transformer is fit on the appended text from all columns in the
X
dataframe.- Parameters:
X (pd.DataFrame) – Columns on which to fit the transformer
y (pd.DataFrame | None, optional) – Not used. Defaults to None.
- Returns:
The fit transformer
- Return type:
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') TextMulticolumnTransformer ¶
Request metadata passed to the
fit
method.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 tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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:
- xstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
x
parameter infit
.
- Returns:
- selfobject
The updated object.
- set_transform_request(*, x: bool | None | str = '$UNCHANGED$') TextMulticolumnTransformer ¶
Request metadata passed to the
transform
method.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 totransform
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it totransform
.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:
- xstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
x
parameter intransform
.
- Returns:
- selfobject
The updated object.