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 : ?degree:int -> ?interaction_only:bool -> ?include_bias:bool -> ?order:[ `C | `F ] -> unit -> t

Generate polynomial and interaction features.

Generate a new feature matrix consisting of all polynomial combinations of the features with degree less than or equal to the specified degree. For example, if an input sample is two dimensional and of the form a, b, the degree-2 polynomial features are 1, a, b, a^2, ab, b^2.

Parameters ---------- degree : integer The degree of the polynomial features. Default = 2.

interaction_only : boolean, default = False If true, only interaction features are produced: features that are products of at most ``degree`` *distinct* input features (so not ``x1 ** 2``, ``x0 * x2 ** 3``, etc.).

include_bias : boolean If True (default), then include a bias column, the feature in which all polynomial powers are zero (i.e. a column of ones - acts as an intercept term in a linear model).

order : str in 'C', 'F', default 'C' Order of output array in the dense case. 'F' order is faster to compute, but may slow down subsequent estimators.

.. versionadded:: 0.21

Examples -------- >>> import numpy as np >>> from sklearn.preprocessing import PolynomialFeatures >>> X = np.arange(6).reshape(3, 2) >>> X array([0, 1], [2, 3], [4, 5]) >>> poly = PolynomialFeatures(2) >>> poly.fit_transform(X) array([ 1., 0., 1., 0., 0., 1.], [ 1., 2., 3., 4., 6., 9.], [ 1., 4., 5., 16., 20., 25.]) >>> poly = PolynomialFeatures(interaction_only=True) >>> poly.fit_transform(X) array([ 1., 0., 1., 0.], [ 1., 2., 3., 6.], [ 1., 4., 5., 20.])

Attributes ---------- powers_ : array, shape (n_output_features, n_input_features) powers_i, j is the exponent of the jth input in the ith output.

n_input_features_ : int The total number of input features.

n_output_features_ : int The total number of polynomial output features. The number of output features is computed by iterating over all suitably sized combinations of input features.

Notes ----- Be aware that the number of features in the output array scales polynomially in the number of features of the input array, and exponentially in the degree. High degrees can cause overfitting.

See :ref:`examples/linear_model/plot_polynomial_interpolation.py <sphx_glr_auto_examples_linear_model_plot_polynomial_interpolation.py>`

val fit : ?y:Py.Object.t -> x:Arr.t -> t -> t

Compute number of output features.

Parameters ---------- X : array-like, shape (n_samples, n_features) The data.

Returns ------- self : instance

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_feature_names : ?input_features:string list -> t -> string list

Return feature names for output features

Parameters ---------- input_features : list of string, length n_features, optional String names for input features if available. By default, "x0", "x1", ... "xn_features" is used.

Returns ------- output_feature_names : list of string, length n_output_features

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 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

Transform data to polynomial features

Parameters ---------- X : array-like or CSR/CSC sparse matrix, shape n_samples, n_features The data to transform, row by row.

Prefer CSR over CSC for sparse input (for speed), but CSC is required if the degree is 4 or higher. If the degree is less than 4 and the input format is CSC, it will be converted to CSR, have its polynomial features generated, then converted back to CSC.

If the degree is 2 or 3, the method described in "Leveraging Sparsity to Speed Up Polynomial Feature Expansions of CSR Matrices Using K-Simplex Numbers" by Andrew Nystrom and John Hughes is used, which is much faster than the method used on CSC input. For this reason, a CSC input will be converted to CSR, and the output will be converted back to CSC prior to being returned, hence the preference of CSR.

Returns ------- XP : np.ndarray or CSR/CSC sparse matrix, shape n_samples, NP The matrix of features, where NP is the number of polynomial features generated from the combination of inputs.

val powers_ : t -> Arr.t

Attribute powers_: get value or raise Not_found if None.

val powers_opt : t -> Arr.t option

Attribute powers_: get value as an option.

val n_input_features_ : t -> int

Attribute n_input_features_: get value or raise Not_found if None.

val n_input_features_opt : t -> int option

Attribute n_input_features_: get value as an option.

val n_output_features_ : t -> int

Attribute n_output_features_: get value or raise Not_found if None.

val n_output_features_opt : t -> int option

Attribute n_output_features_: 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.