check_pipeline#

pybear.utilities.check_pipeline(pipeline)#

Validate a pipeline setup.

In particular, the construction of the steps attribute. Validate that steps is a list of tuples. In the first position of each tuple must be a string. The second position of each tuple must contain a class instance that has a fit method.

Parameters:
pipelinesklearn.pipeline.Pipeline

A Pipeline instance.

Returns:
None

Examples

>>> from pybear.utilities import check_pipeline
>>> from sklearn.pipeline import Pipeline
>>> from sklearn.preprocessing import StandardScaler
>>> from sklearn.linear_model import LogisticRegression
>>> import sys
>>>
>>> # not instantiated
>>> _steps = [('Scaler', StandardScaler), ('Logistic', LogisticRegression)]
>>> pipe = Pipeline(steps=_steps)
>>> try:
...     check_pipeline(pipe)
... except:
...     print(sys.exc_info()[0])
<class 'ValueError'>
>>>
>>> # correctly instantiated
>>> _steps = [('Scaler', StandardScaler()), ('Logistic', LogisticRegression())]
>>> pipe = Pipeline(steps=_steps)
>>> print(check_pipeline(pipe))
None