package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type t
val of_pyobject : Py.Object.t -> t
val to_pyobject : t -> Py.Object.t
val create : ?threshold:[ `S of string | `F of float ] -> ?prefit:bool -> ?norm_order:Py.Object.t -> ?max_features:int -> estimator:Py.Object.t -> unit -> t

Meta-transformer for selecting features based on importance weights.

.. versionadded:: 0.17

Parameters ---------- estimator : object The base estimator from which the transformer is built. This can be both a fitted (if ``prefit`` is set to True) or a non-fitted estimator. The estimator must have either a ``feature_importances_`` or ``coef_`` attribute after fitting.

threshold : string, float, optional default None The threshold value to use for feature selection. Features whose importance is greater or equal are kept while the others are discarded. If "median" (resp. "mean"), then the ``threshold`` value is the median (resp. the mean) of the feature importances. A scaling factor (e.g., "1.25*mean") may also be used. If None and if the estimator has a parameter penalty set to l1, either explicitly or implicitly (e.g, Lasso), the threshold used is 1e-5. Otherwise, "mean" is used by default.

prefit : bool, default False Whether a prefit model is expected to be passed into the constructor directly or not. If True, ``transform`` must be called directly and SelectFromModel cannot be used with ``cross_val_score``, ``GridSearchCV`` and similar utilities that clone the estimator. Otherwise train the model using ``fit`` and then ``transform`` to do feature selection.

norm_order : non-zero int, inf, -inf, default 1 Order of the norm used to filter the vectors of coefficients below ``threshold`` in the case where the ``coef_`` attribute of the estimator is of dimension 2.

max_features : int or None, optional The maximum number of features selected scoring above ``threshold``. To disable ``threshold`` and only select based on ``max_features``, set ``threshold=-np.inf``.

.. versionadded:: 0.20

Attributes ---------- estimator_ : an estimator The base estimator from which the transformer is built. This is stored only when a non-fitted estimator is passed to the ``SelectFromModel``, i.e when prefit is False.

threshold_ : float The threshold value used for feature selection.

Notes ----- Allows NaN/Inf in the input if the underlying estimator does as well.

Examples -------- >>> from sklearn.feature_selection import SelectFromModel >>> from sklearn.linear_model import LogisticRegression >>> X = [ 0.87, -1.34, 0.31 ], ... [-2.79, -0.02, -0.85 ], ... [-1.34, -0.48, -2.55 ], ... [ 1.92, 1.48, 0.65 ] >>> y = 0, 1, 0, 1 >>> selector = SelectFromModel(estimator=LogisticRegression()).fit(X, y) >>> selector.estimator_.coef_ array([-0.3252302 , 0.83462377, 0.49750423]) >>> selector.threshold_ 0.55245... >>> selector.get_support() array(False, True, False) >>> selector.transform(X) array([-1.34], [-0.02], [-0.48], [ 1.48])

val fit : ?y:Arr.t -> ?fit_params:(string * Py.Object.t) list -> x:Arr.t -> t -> t

Fit the SelectFromModel meta-transformer.

Parameters ---------- X : array-like of shape (n_samples, n_features) The training input samples.

y : array-like, shape (n_samples,) The target values (integers that correspond to classes in classification, real numbers in regression).

**fit_params : Other estimator specific parameters

Returns ------- self : object

val fit_transform : ?y:Arr.t -> ?fit_params:(string * Py.Object.t) list -> x:Arr.t -> t -> Arr.t

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.

**fit_params : dict Additional fit parameters.

Returns ------- X_new : numpy array of shape n_samples, n_features_new Transformed array.

val get_params : ?deep:bool -> 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 get_support : ?indices:bool -> t -> Arr.t

Get a mask, or integer index, of the features selected

Parameters ---------- indices : boolean (default False) If True, the return value will be an array of integers, rather than a boolean mask.

Returns ------- support : array An index that selects the retained features from a feature vector. If `indices` is False, this is a boolean array of shape # input features, in which an element is True iff its corresponding feature is selected for retention. If `indices` is True, this is an integer array of shape # output features whose values are indices into the input feature vector.

val inverse_transform : x:Arr.t -> t -> Arr.t

Reverse the transformation operation

Parameters ---------- X : array of shape n_samples, n_selected_features The input samples.

Returns ------- X_r : array of shape n_samples, n_original_features `X` with columns of zeros inserted where features would have been removed by :meth:`transform`.

val partial_fit : ?y:Arr.t -> ?fit_params:(string * Py.Object.t) list -> x:Arr.t -> t -> t

Fit the SelectFromModel meta-transformer only once.

Parameters ---------- X : array-like of shape (n_samples, n_features) The training input samples.

y : array-like, shape (n_samples,) The target values (integers that correspond to classes in classification, real numbers in regression).

**fit_params : Other estimator specific parameters

Returns ------- self : object

val set_params : ?params:(string * Py.Object.t) list -> t -> t

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.

Parameters ---------- **params : dict Estimator parameters.

Returns ------- self : object Estimator instance.

val transform : x:Arr.t -> t -> Arr.t

Reduce X to the selected features.

Parameters ---------- X : array of shape n_samples, n_features The input samples.

Returns ------- X_r : array of shape n_samples, n_selected_features The input samples with only the selected features.

val estimator_ : t -> Py.Object.t

Attribute estimator_: get value or raise Not_found if None.

val estimator_opt : t -> Py.Object.t option

Attribute estimator_: get value as an option.

val threshold_ : t -> float

Attribute threshold_: get value or raise Not_found if None.

val threshold_opt : t -> float option

Attribute threshold_: 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 : Format.formatter -> t -> unit

Pretty-print the object to a formatter.

OCaml

Innovation. Community. Security.