FeatureGrouper
class atom.feature_engineering.FeatureGrouper(group, name=None, operators=None, drop_columns=True, verbose=0, logger=None)[source]
Extract statistics from similar features.
Replace groups of features with related characteristics with new
features that summarize statistical properties of te group. The
statistical operators are calculated over every row of the group.
The group names and features can be accessed through the groups
method.
This class can be accessed from atom through the feature_grouping method. Read more in the user guide.
Tip
Use a regex pattern with the groups
parameter to select
groups easier, e.g. atom.feature_generation(features="var_.+")
to select all features that start with var_
.
See Also
Extract features from datetime columns.
Generate new features.
Reduce the number of features in the data.
Example
>>> from atom import ATOMClassifier
>>> from sklearn.datasets import load_breast_cancer
>>> X, y = load_breast_cancer(return_X_y=True, as_frame=True)
>>> atom = ATOMClassifier(X, y)
>>> atom.feature_grouping(group=["mean.+"], name="means", verbose=2)
Fitting FeatureGrouper...
Grouping features...
--> Group means successfully created.
>>> # Note the mean features are gone and the new std(means) feature
>>> print(atom.dataset)
radius error texture error ... std(means) target
0 0.2949 1.6560 ... 137.553584 1
1 0.2351 2.0110 ... 79.830195 1
2 0.4302 2.8780 ... 80.330330 1
3 0.2345 1.2190 ... 151.858455 1
4 0.3511 0.9527 ... 145.769474 1
.. ... ... ... ... ...
564 0.4866 1.9050 ... 116.749243 1
565 0.5925 0.6863 ... 378.431333 0
566 0.2577 1.0950 ... 141.220243 1
567 0.4615 0.9197 ... 257.903846 0
568 0.5462 1.5110 ... 194.704033 1
[569 rows x 27 columns]
>>> from atom.feature_engineering import FeatureGrouper
>>> from sklearn.datasets import load_breast_cancer
>>> X, y = load_breast_cancer(return_X_y=True, as_frame=True)
>>> # Group all features that start with mean
>>> fg = FeatureGrouper(group="mean.+", name="means", verbose=2)
>>> X = fg.transform(X)
Fitting FeatureGrouper...
Grouping features...
--> Group means successfully created.
>>> # Note the mean features are gone and the new std(means) feature
>>> print(X)
radius error texture error ... mode(means) std(means)
0 1.0950 0.9053 ... 0.07871 297.404540
1 0.5435 0.7339 ... 0.05667 393.997131
2 0.7456 0.7869 ... 0.05999 357.203084
3 0.4956 1.1560 ... 0.09744 114.444620
4 0.7572 0.7813 ... 0.05883 385.450556
.. ... ... ... ... ...
564 1.1760 1.2560 ... 0.05623 439.441252
565 0.7655 2.4630 ... 0.05533 374.274845
566 0.4564 1.0750 ... 0.05302 254.320568
567 0.7260 1.5950 ... 0.07016 375.376476
568 0.3857 1.4280 ... 0.00000 53.739926
[569 rows x 26 columns]
Methods
fit | Does nothing. |
fit_transform | Fit to data, then transform it. |
get_params | Get parameters for this estimator. |
inverse_transform | Does nothing. |
log | Print message and save to log file. |
save | Save the instance to a pickle file. |
set_params | Set the parameters of this estimator. |
transform | Group features. |
method fit(X=None, y=None, **fit_params)[source]
Does nothing.
Implemented for continuity of the API.
method fit_transform(X=None, y=None, **fit_params)[source]
Fit to data, then transform it.
method get_params(deep=True)[source]
Get parameters for this estimator.
Parameters | deep : bool, default=True
If True, will return the parameters for this estimator and
contained subobjects that are estimators.
|
Returns | params : dict
Parameter names mapped to their values.
|
method inverse_transform(X=None, y=None)[source]
Does nothing.
method log(msg, level=0, severity="info")[source]
Print message and save to log file.
method save(filename="auto", save_data=True)[source]
Save the instance to a pickle file.
Parameters | filename: str, default="auto"
Name of the file. Use "auto" for automatic naming.
save_data: bool, default=True
Whether to save the dataset with the instance. This parameter
is ignored if the method is not called from atom. If False,
add the data to the load method.
|
method set_params(**params)[source]
Set the parameters of this estimator.
Parameters | **params : dict
Estimator parameters.
|
Returns | self : estimator instance
Estimator instance.
|
method transform(X, y=None)[source]
Group features.