package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `Pipeline
]
type t = [ `BaseEstimator | `Object | `Pipeline ] Obj.t
val of_pyobject : Py.Object.t -> t
val to_pyobject : [> tag ] Obj.t -> Py.Object.t
val as_estimator : t -> [ `BaseEstimator ] Obj.t
val create : ?memory:[ `S of string | `Joblib_Memory of Py.Object.t ] -> ?verbose:bool -> steps:(string * [> `BaseEstimator ] Np.Obj.t) list -> unit -> t

Pipeline of transforms with a final estimator.

Sequentially apply a list of transforms and a final estimator. Intermediate steps of the pipeline must be 'transforms', that is, they must implement fit and transform methods. The final estimator only needs to implement fit. The transformers in the pipeline can be cached using ``memory`` argument.

The purpose of the pipeline is to assemble several steps that can be cross-validated together while setting different parameters. For this, it enables setting parameters of the various steps using their names and the parameter name separated by a '__', as in the example below. A step's estimator may be replaced entirely by setting the parameter with its name to another estimator, or a transformer removed by setting it to 'passthrough' or ``None``.

Read more in the :ref:`User Guide <pipeline>`.

.. versionadded:: 0.5

Parameters ---------- steps : list List of (name, transform) tuples (implementing fit/transform) that are chained, in the order in which they are chained, with the last object an estimator.

memory : str or object with the joblib.Memory interface, default=None Used to cache the fitted transformers of the pipeline. By default, no caching is performed. If a string is given, it is the path to the caching directory. Enabling caching triggers a clone of the transformers before fitting. Therefore, the transformer instance given to the pipeline cannot be inspected directly. Use the attribute ``named_steps`` or ``steps`` to inspect estimators within the pipeline. Caching the transformers is advantageous when fitting is time consuming.

verbose : bool, default=False If True, the time elapsed while fitting each step will be printed as it is completed.

Attributes ---------- named_steps : :class:`~sklearn.utils.Bunch` Dictionary-like object, with the following attributes. Read-only attribute to access any step parameter by user given name. Keys are step names and values are steps parameters.

See Also -------- sklearn.pipeline.make_pipeline : Convenience function for simplified pipeline construction.

Examples -------- >>> from sklearn.svm import SVC >>> from sklearn.preprocessing import StandardScaler >>> from sklearn.datasets import make_classification >>> from sklearn.model_selection import train_test_split >>> from sklearn.pipeline import Pipeline >>> X, y = make_classification(random_state=0) >>> X_train, X_test, y_train, y_test = train_test_split(X, y, ... random_state=0) >>> pipe = Pipeline(('scaler', StandardScaler()), ('svc', SVC())) >>> # The pipeline can be used as any other estimator >>> # and avoids leaking the test set into the train set >>> pipe.fit(X_train, y_train) Pipeline(steps=('scaler', StandardScaler()), ('svc', SVC())) >>> pipe.score(X_test, y_test) 0.88

val get_item : ind:[ `I of int | `S of string | `Slice of Np.Wrap_utils.Slice.t ] -> [> tag ] Obj.t -> Py.Object.t

Returns a sub-pipeline or a single esimtator in the pipeline

Indexing with an integer will return an estimator; using a slice returns another Pipeline instance which copies a slice of this Pipeline. This copy is shallow: modifying (or fitting) estimators in the sub-pipeline will affect the larger pipeline and vice-versa. However, replacing a value in `step` will not affect a copy.

val decision_function : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

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 : array-like of shape (n_samples, n_classes)

val fit : ?y:[> `ArrayLike ] Np.Obj.t -> ?fit_params:(string * Py.Object.t) list -> x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> t

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 parameter ``p`` for step ``s`` has key ``s__p``.

Returns ------- self : Pipeline This estimator

val fit_predict : ?y:[> `ArrayLike ] Np.Obj.t -> ?fit_params:(string * Py.Object.t) list -> x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

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 parameter ``p`` for step ``s`` has key ``s__p``.

Returns ------- y_pred : array-like

val fit_transform : ?y:[> `ArrayLike ] Np.Obj.t -> ?fit_params:(string * Py.Object.t) list -> x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

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 parameter ``p`` for step ``s`` has key ``s__p``.

Returns ------- Xt : array-like of shape (n_samples, n_transformed_features) Transformed samples

val get_params : ?deep:bool -> [> tag ] Obj.t -> Dict.t

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 : mapping of string to any Parameter names mapped to their values.

val inverse_transform : ?x:[> `ArrayLike ] Np.Obj.t -> ?y:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

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 and ``n_features`` is the number of features. Must fulfill input requirements of last step of pipeline's ``inverse_transform`` method.

Returns ------- Xt : array-like of shape (n_samples, n_features)

val predict : ?predict_params:(string * Py.Object.t) list -> x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

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.

.. versionadded:: 0.20

Returns ------- y_pred : array-like

val predict_log_proba : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

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 : array-like of shape (n_samples, n_classes)

val predict_proba : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

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 : array-like of shape (n_samples, n_classes)

val score : ?y:[> `ArrayLike ] Np.Obj.t -> ?sample_weight:[> `ArrayLike ] Np.Obj.t -> x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> float

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 the ``score`` method of the final estimator.

Returns ------- score : float

val score_samples : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

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 : ndarray of shape (n_samples,)

val set_params : ?kwargs:(string * Py.Object.t) list -> [> tag ] Obj.t -> t

Set the parameters of this estimator.

Valid parameter keys can be listed with ``get_params()``.

Returns ------- self

val named_steps : t -> Dict.t

Attribute named_steps: get value or raise Not_found if None.

val named_steps_opt : t -> Dict.t option

Attribute named_steps: get value as an option.

val to_string : t -> string

Print the object to a human-readable representation.

val show : t -> string

Print the object to a human-readable representation.

val pp : Stdlib.Format.formatter -> t -> unit

Pretty-print the object to a formatter.