gtime.compose
.FeatureCreation¶
-
class
gtime.compose.
FeatureCreation
(transformers, remainder='drop', sparse_threshold=0.3, n_jobs=None, transformer_weights=None, verbose=False)¶ Applies transformers to columns of a pandas DataFrame.
This estimator is a wrapper of sklearn.compose.ColumnTransformer, the only difference is the output type of fit_transform and transform methods which is a DataFrame instead of an array.
- Attributes
named_transformers_
Access the fitted transformer by name.
Methods
fit
(self, X[, y])Fit all transformers using X.
fit_transform
(self, X, y)Fit all transformers, transform the data and concatenate results.
get_feature_names
(self)Get feature names from all transformers.
get_params
(self[, deep])Get parameters for this estimator.
set_params
(self, \*\*kwargs)Set the parameters of this estimator.
transform
(self, X)Transform X separately by each transformer, concatenate results.
-
__init__
(self, transformers, remainder='drop', sparse_threshold=0.3, n_jobs=None, transformer_weights=None, verbose=False)¶ Initialize self. See help(type(self)) for accurate signature.
-
fit
(self, X, y=None)¶ Fit all transformers using X.
- Parameters
- Xarray-like or DataFrame of shape [n_samples, n_features]
Input data, of which specified subsets are used to fit the transformers.
- yarray-like, shape (n_samples, …), optional
Targets for supervised learning.
- Returns
- selfColumnTransformer
This estimator
-
fit_transform
(self, X:pandas.core.frame.DataFrame, y:pandas.core.frame.DataFrame=None)¶ Fit all transformers, transform the data and concatenate results.
- Parameters
- Xpd.DataFrame, shape (n_samples, n_features), required
Input data, of which specified subsets are used to fit the transformers.
- ypd.DataFrame, shape (n_samples, …), optional, default:
None
Targets for supervised learning.
- Returns
- X_t_dfpd.DataFrame, shape (n_samples, sum_n_components)
hstack of results of transformers. sum_n_components is the sum of n_components (output dimension) over transformers.
Examples
>>> import pandas.util.testing as testing >>> from gtime.compose import FeatureCreation >>> from gtime.feature_extraction import Shift, MovingAverage >>> data = testing.makeTimeDataFrame(freq="s") >>> fc = FeatureCreation([ ... ('s1', Shift(1), ['A']), ... ('ma3', MovingAverage(window_size=3), ['B']), ... ]) >>> fc.fit_transform(data).head() s1__A__Shift ma3__B__MovingAverage 2000-01-01 00:00:00 NaN NaN 2000-01-01 00:00:01 0.211403 NaN 2000-01-01 00:00:02 -0.313854 0.085045 2000-01-01 00:00:03 0.502018 -0.239269 2000-01-01 00:00:04 -0.225324 -0.144625
-
get_feature_names
(self)¶ Get feature names from all transformers.
- Returns
- feature_nameslist of strings
Names of the features produced by transform.
-
get_params
(self, deep=True)¶ Get parameters for this estimator.
- Parameters
- deepboolean, optional
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns
- paramsmapping of string to any
Parameter names mapped to their values.
-
property
named_transformers_
¶ Access the fitted transformer by name.
Read-only attribute to access any transformer by given name. Keys are transformer names and values are the fitted transformer objects.
-
set_params
(self, **kwargs)¶ Set the parameters of this estimator.
Valid parameter keys can be listed with
get_params()
.- Returns
- self
-
transform
(self, X:pandas.core.frame.DataFrame)¶ Transform X separately by each transformer, concatenate results.
- Parameters
- Xpd.DataFrame, shape (n_samples, n_features), required
The data to be transformed by subset.
- Returns
- X_t_dfDataFrame, shape (n_samples, sum_n_components)
hstack of results of transformers. sum_n_components is the sum of n_components (output dimension) over transformers. If any result is a sparse matrix, everything will be converted to sparse matrices.