skoot.base.BasePDTransformer

class skoot.base.BasePDTransformer(cols=None, as_df=True)[source][source]

The base class for all Pandas frame transformers.

Provides the base class for all skoot transformers that require Pandas dataframes as input.

Parameters:

cols : array-like, shape=(n_features,), optional (default=None)

The names of the columns on which to apply the transformation. If no column names are provided, the transformer will be fit on the entire frame. Note that the transformation will also only apply to the specified columns, and any other non-specified columns will still be present after the transformation.

as_df : bool, optional (default=True) Whether to return a Pandas DataFrame in the transform method. If False, will return a Numpy ndarray instead. Since most skoot transformers depend on explicitly-named DataFrame features, the as_df parameter is True by default.

Examples

The following is an example of how to subclass a BasePDTransformer:

>>> from skoot.base import BasePDTransformer
>>> class A(BasePDTransformer):
...     def __init__(self, cols=None, as_df=None):
...             super(A, self).__init__(cols, as_df)
...
>>> A()
A(as_df=None, cols=None)

Methods

fit(X[, y]) Fit the transformer.
fit_transform(X[, y]) Fit to data, then transform it.
get_params([deep]) Get parameters for this estimator.
set_params(**params) Set the parameters of this estimator.
__init__(cols=None, as_df=True)[source][source]

Initialize self. See help(type(self)) for accurate signature.

fit(X, y=None)[source][source]

Fit the transformer.

Default behavior is not to fit any parameters and return self. This is useful for transformers which do not require parameterization, but need to fit into a pipeline.

Parameters:

X : pd.DataFrame, shape=(n_samples, n_features)

The Pandas frame to fit.

y : array-like or None, shape=(n_samples,), optional (default=None)

Pass-through for sklearn.pipeline.Pipeline.

fit_transform(X, y=None, **fit_params)[source]

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters:

X : numpy array of shape [n_samples, n_features]

Training set.

y : numpy array of shape [n_samples]

Target values.

Returns:

X_new : numpy array of shape [n_samples, n_features_new]

Transformed array.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:

deep : boolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params : mapping of string to any

Parameter names mapped to their values.

set_params(**params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns:self