MapperPipeline¶
-
class
gtda.mapper.pipeline.
MapperPipeline
(**kwargs)[source]¶ Subclass of
sklearn.pipeline.Pipeline
to deal with pipelines generated bymake_mapper_pipeline
.The
set_params
method is modified from the corresponding method insklearn.pipeline.Pipeline
to allow for simple access to the parameters involved in the definition of the Mapper algorithm, without the need to interface with the nested structure of the Pipeline objects generated bymake_mapper_pipeline
. The convenience methodget_mapper_params
shows which parameters can be set. See the Examples below.Examples
>>> from sklearn.cluster import DBSCAN >>> from sklearn.decomposition import PCA >>> from gtda.mapper import make_mapper_pipeline, CubicalCover >>> filter_func = PCA(n_components=2) >>> cover = CubicalCover() >>> clusterer = DBSCAN() >>> pipe = make_mapper_pipeline(filter_func=filter_func, ... cover=cover, ... clusterer=clusterer) >>> print(pipe.get_mapper_params()["clusterer__eps"]) 0.5 >>> pipe.set_params(clusterer___eps=0.1) >>> print(pipe.get_mapper_params()["clusterer__eps"]) 0.1
See also
make_mapper_pipeline
-
__init__
(steps, *, memory=None, verbose=False)¶ Initialize self. See help(type(self)) for accurate signature.
-
decision_function
(X)¶ Apply transforms, and decision_function of the final estimator
- Parameters
X (iterable) – Data to predict on. Must fulfill input requirements of first step of the pipeline.
- Returns
y_score
- Return type
array-like of shape (n_samples, n_classes)
-
fit
(X, y=None, **fit_params)¶ Fit the model
Fit all the transforms one after the other and transform the data, then fit the transformed data using the final estimator.
- Parameters
X (iterable) – Training data. Must fulfill input requirements of first step of the pipeline.
y (iterable, default=None) – Training targets. Must fulfill label requirements for all steps of the pipeline.
**fit_params (dict of string -> object) – Parameters passed to the
fit
method of each step, where each parameter name is prefixed such that parameterp
for steps
has keys__p
.
- Returns
self – This estimator
- Return type
-
fit_predict
(X, y=None, **fit_params)¶ Applies fit_predict of last step in pipeline after transforms.
Applies fit_transforms of a pipeline to the data, followed by the fit_predict method of the final estimator in the pipeline. Valid only if the final estimator implements fit_predict.
- Parameters
X (iterable) – Training data. Must fulfill input requirements of first step of the pipeline.
y (iterable, default=None) – Training targets. Must fulfill label requirements for all steps of the pipeline.
**fit_params (dict of string -> object) – Parameters passed to the
fit
method of each step, where each parameter name is prefixed such that parameterp
for steps
has keys__p
.
- Returns
y_pred
- Return type
array-like
-
fit_transform
(X, y=None, **fit_params)¶ Fit the model and transform with the final estimator
Fits all the transforms one after the other and transforms the data, then uses fit_transform on transformed data with the final estimator.
- Parameters
X (iterable) – Training data. Must fulfill input requirements of first step of the pipeline.
y (iterable, default=None) – Training targets. Must fulfill label requirements for all steps of the pipeline.
**fit_params (dict of string -> object) – Parameters passed to the
fit
method of each step, where each parameter name is prefixed such that parameterp
for steps
has keys__p
.
- Returns
Xt – Transformed samples
- Return type
array-like of shape (n_samples, n_transformed_features)
-
get_mapper_params
(deep=True)[source]¶ Get all Mapper parameters for this estimator.
- Parameters
deep (boolean, optional, default:
True
) – IfTrue
, will return the parameters for this estimator and contained subobjects that are estimators.- Returns
params – Parameter names mapped to their values.
- Return type
mapping of string to any
-
get_params
(deep=True)¶ 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 – Parameter names mapped to their values.
- Return type
mapping of string to any
-
property
inverse_transform
¶ Apply inverse transformations in reverse order
All estimators in the pipeline must support
inverse_transform
.- Parameters
Xt (array-like of shape (n_samples, n_transformed_features)) – Data samples, where
n_samples
is the number of samples andn_features
is the number of features. Must fulfill input requirements of last step of pipeline’sinverse_transform
method.- Returns
Xt
- Return type
array-like of shape (n_samples, n_features)
-
predict
(X, **predict_params)¶ Apply transforms to the data, and predict with the final estimator
- Parameters
X (iterable) – Data to predict on. Must fulfill input requirements of first step of the pipeline.
**predict_params (dict of string -> object) –
Parameters to the
predict
called at the end of all transformations in the pipeline. Note that while this may be used to return uncertainties from some models with return_std or return_cov, uncertainties that are generated by the transformations in the pipeline are not propagated to the final estimator.New in version 0.20.
- Returns
y_pred
- Return type
array-like
-
predict_log_proba
(X)¶ Apply transforms, and predict_log_proba of the final estimator
- Parameters
X (iterable) – Data to predict on. Must fulfill input requirements of first step of the pipeline.
- Returns
y_score
- Return type
array-like of shape (n_samples, n_classes)
-
predict_proba
(X)¶ Apply transforms, and predict_proba of the final estimator
- Parameters
X (iterable) – Data to predict on. Must fulfill input requirements of first step of the pipeline.
- Returns
y_proba
- Return type
array-like of shape (n_samples, n_classes)
-
score
(X, y=None, sample_weight=None)¶ Apply transforms, and score with the final estimator
- Parameters
X (iterable) – Data to predict on. Must fulfill input requirements of first step of the pipeline.
y (iterable, default=None) – Targets used for scoring. Must fulfill label requirements for all steps of the pipeline.
sample_weight (array-like, default=None) – If not None, this argument is passed as
sample_weight
keyword argument to thescore
method of the final estimator.
- Returns
score
- Return type
float
-
score_samples
(X)¶ Apply transforms, and score_samples of the final estimator.
- Parameters
X (iterable) – Data to predict on. Must fulfill input requirements of first step of the pipeline.
- Returns
y_score
- Return type
ndarray of shape (n_samples,)
-
set_params
(**kwargs)[source]¶ Set the Mapper parameters.
Valid parameter keys can be listed with
get_mapper_params
.- Returns
- Return type
self
-
property
transform
¶ Apply transforms, and transform with the final estimator
This also works where final estimator is
None
: all prior transformations are applied.- Parameters
X (iterable) – Data to transform. Must fulfill input requirements of first step of the pipeline.
- Returns
Xt
- Return type
array-like of shape (n_samples, n_transformed_features)
-