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 : ?solver:string -> ?shrinkage:[ `S of string | `F of float ] -> ?priors:Arr.t -> ?n_components:int -> ?store_covariance:bool -> ?tol:float -> unit -> t

Linear Discriminant Analysis

A classifier with a linear decision boundary, generated by fitting class conditional densities to the data and using Bayes' rule.

The model fits a Gaussian density to each class, assuming that all classes share the same covariance matrix.

The fitted model can also be used to reduce the dimensionality of the input by projecting it to the most discriminative directions.

.. versionadded:: 0.17 *LinearDiscriminantAnalysis*.

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

Parameters ---------- solver : string, optional Solver to use, possible values:

  • 'svd': Singular value decomposition (default). Does not compute the covariance matrix, therefore this solver is recommended for data with a large number of features.
  • 'lsqr': Least squares solution, can be combined with shrinkage.
  • 'eigen': Eigenvalue decomposition, can be combined with shrinkage.

shrinkage : string or float, optional Shrinkage parameter, possible values:

  • None: no shrinkage (default).
  • 'auto': automatic shrinkage using the Ledoit-Wolf lemma.
  • float between 0 and 1: fixed shrinkage parameter.

Note that shrinkage works only with 'lsqr' and 'eigen' solvers.

priors : array, optional, shape (n_classes,) Class priors.

n_components : int, optional (default=None) Number of components (<= min(n_classes - 1, n_features)) for dimensionality reduction. If None, will be set to min(n_classes - 1, n_features).

store_covariance : bool, optional Additionally compute class covariance matrix (default False), used only in 'svd' solver.

.. versionadded:: 0.17

tol : float, optional, (default 1.0e-4) Threshold used for rank estimation in SVD solver.

.. versionadded:: 0.17

Attributes ---------- coef_ : array, shape (n_features,) or (n_classes, n_features) Weight vector(s).

intercept_ : array, shape (n_classes,) Intercept term.

covariance_ : array-like, shape (n_features, n_features) Covariance matrix (shared by all classes).

explained_variance_ratio_ : array, shape (n_components,) Percentage of variance explained by each of the selected components. If ``n_components`` is not set then all components are stored and the sum of explained variances is equal to 1.0. Only available when eigen or svd solver is used.

means_ : array-like, shape (n_classes, n_features) Class means.

priors_ : array-like, shape (n_classes,) Class priors (sum to 1).

scalings_ : array-like, shape (rank, n_classes - 1) Scaling of the features in the space spanned by the class centroids.

xbar_ : array-like, shape (n_features,) Overall mean.

classes_ : array-like, shape (n_classes,) Unique class labels.

See also -------- sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis: Quadratic Discriminant Analysis

Notes ----- The default solver is 'svd'. It can perform both classification and transform, and it does not rely on the calculation of the covariance matrix. This can be an advantage in situations where the number of features is large. However, the 'svd' solver cannot be used with shrinkage.

The 'lsqr' solver is an efficient algorithm that only works for classification. It supports shrinkage.

The 'eigen' solver is based on the optimization of the between class scatter to within class scatter ratio. It can be used for both classification and transform, and it supports shrinkage. However, the 'eigen' solver needs to compute the covariance matrix, so it might not be suitable for situations with a high number of features.

Examples -------- >>> import numpy as np >>> from sklearn.discriminant_analysis import LinearDiscriminantAnalysis >>> X = np.array([-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]) >>> y = np.array(1, 1, 1, 2, 2, 2) >>> clf = LinearDiscriminantAnalysis() >>> clf.fit(X, y) LinearDiscriminantAnalysis() >>> print(clf.predict([-0.8, -1])) 1

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

Predict confidence scores for samples.

The confidence score for a sample is the signed distance of that sample to the hyperplane.

Parameters ---------- X : array_like or sparse matrix, shape (n_samples, n_features) Samples.

Returns ------- array, shape=(n_samples,) if n_classes == 2 else (n_samples, n_classes) Confidence scores per (sample, class) combination. In the binary case, confidence score for self.classes_1 where >0 means this class would be predicted.

val fit : x:Arr.t -> y:Arr.t -> t -> t

Fit LinearDiscriminantAnalysis model according to the given training data and parameters.

.. versionchanged:: 0.19 *store_covariance* has been moved to main constructor.

.. versionchanged:: 0.19 *tol* has been moved to main constructor.

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

y : array, shape (n_samples,) Target values.

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 predict : x:Arr.t -> t -> Arr.t

Predict class labels for samples in X.

Parameters ---------- X : array_like or sparse matrix, shape (n_samples, n_features) Samples.

Returns ------- C : array, shape n_samples Predicted class label per sample.

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

Estimate log probability.

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

Returns ------- C : array, shape (n_samples, n_classes) Estimated log probabilities.

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

Estimate probability.

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

Returns ------- C : array, shape (n_samples, n_classes) Estimated probabilities.

val score : ?sample_weight:Arr.t -> x:Arr.t -> y:Arr.t -> t -> float

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters ---------- X : array-like of shape (n_samples, n_features) Test samples.

y : array-like of shape (n_samples,) or (n_samples, n_outputs) True labels for X.

sample_weight : array-like of shape (n_samples,), default=None Sample weights.

Returns ------- score : float Mean accuracy of self.predict(X) wrt. y.

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

Project data to maximize class separation.

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

Returns ------- X_new : array, shape (n_samples, n_components) Transformed data.

val coef_ : t -> Arr.t

Attribute coef_: get value or raise Not_found if None.

val coef_opt : t -> Arr.t option

Attribute coef_: get value as an option.

val intercept_ : t -> Arr.t

Attribute intercept_: get value or raise Not_found if None.

val intercept_opt : t -> Arr.t option

Attribute intercept_: get value as an option.

val covariance_ : t -> Arr.t

Attribute covariance_: get value or raise Not_found if None.

val covariance_opt : t -> Arr.t option

Attribute covariance_: get value as an option.

val explained_variance_ratio_ : t -> Arr.t

Attribute explained_variance_ratio_: get value or raise Not_found if None.

val explained_variance_ratio_opt : t -> Arr.t option

Attribute explained_variance_ratio_: get value as an option.

val means_ : t -> Arr.t

Attribute means_: get value or raise Not_found if None.

val means_opt : t -> Arr.t option

Attribute means_: get value as an option.

val priors_ : t -> Arr.t

Attribute priors_: get value or raise Not_found if None.

val priors_opt : t -> Arr.t option

Attribute priors_: get value as an option.

val scalings_ : t -> Arr.t

Attribute scalings_: get value or raise Not_found if None.

val scalings_opt : t -> Arr.t option

Attribute scalings_: get value as an option.

val xbar_ : t -> Arr.t

Attribute xbar_: get value or raise Not_found if None.

val xbar_opt : t -> Arr.t option

Attribute xbar_: get value as an option.

val classes_ : t -> Arr.t

Attribute classes_: get value or raise Not_found if None.

val classes_opt : t -> Arr.t option

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