package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `QuadraticDiscriminantAnalysis
]
type t = [ `BaseEstimator | `ClassifierMixin | `Object | `QuadraticDiscriminantAnalysis ] Obj.t
val of_pyobject : Py.Object.t -> t
val to_pyobject : [> tag ] Obj.t -> Py.Object.t
val as_classifier : t -> [ `ClassifierMixin ] Obj.t
val as_estimator : t -> [ `BaseEstimator ] Obj.t
val create : ?priors:[> `ArrayLike ] Np.Obj.t -> ?reg_param:float -> ?store_covariance:bool -> ?tol:float -> unit -> t

Quadratic Discriminant Analysis

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

The model fits a Gaussian density to each class.

.. versionadded:: 0.17 *QuadraticDiscriminantAnalysis*

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

Parameters ---------- priors : ndarray of shape (n_classes,), default=None Class priors. By default, the class proportions are inferred from the training data.

reg_param : float, default=0.0 Regularizes the per-class covariance estimates by transforming S2 as ``S2 = (1 - reg_param) * S2 + reg_param * np.eye(n_features)``, where S2 corresponds to the `scaling_` attribute of a given class.

store_covariance : bool, default=False If True, the class covariance matrices are explicitely computed and stored in the `self.covariance_` attribute.

.. versionadded:: 0.17

tol : float, default=1.0e-4 Absolute threshold for a singular value to be considered significant, used to estimate the rank of `Xk` where `Xk` is the centered matrix of samples in class k. This parameter does not affect the predictions. It only controls a warning that is raised when features are considered to be colinear.

.. versionadded:: 0.17

Attributes ---------- covariance_ : list of len n_classes of ndarray of shape (n_features, n_features) For each class, gives the covariance matrix estimated using the samples of that class. The estimations are unbiased. Only present if `store_covariance` is True.

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

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

rotations_ : list of len n_classes of ndarray of shape (n_features, n_k) For each class k an array of shape (n_features, n_k), where ``n_k = min(n_features, number of elements in class k)`` It is the rotation of the Gaussian distribution, i.e. its principal axis. It corresponds to `V`, the matrix of eigenvectors coming from the SVD of `Xk = U S Vt` where `Xk` is the centered matrix of samples from class k.

scalings_ : list of len n_classes of ndarray of shape (n_k,) For each class, contains the scaling of the Gaussian distributions along its principal axes, i.e. the variance in the rotated coordinate system. It corresponds to `S^2 / (n_samples - 1)`, where `S` is the diagonal matrix of singular values from the SVD of `Xk`, where `Xk` is the centered matrix of samples from class k.

classes_ : ndarray of shape (n_classes,) Unique class labels.

Examples -------- >>> from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis >>> import numpy as np >>> 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 = QuadraticDiscriminantAnalysis() >>> clf.fit(X, y) QuadraticDiscriminantAnalysis() >>> print(clf.predict([-0.8, -1])) 1

See also -------- sklearn.discriminant_analysis.LinearDiscriminantAnalysis: Linear Discriminant Analysis

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

Apply decision function to an array of samples.

The decision function is equal (up to a constant factor) to the log-posterior of the model, i.e. `log p(y = k | x)`. In a binary classification setting this instead corresponds to the difference `log p(y = 1 | x) - log p(y = 0 | x)`. See :ref:`lda_qda_math`.

Parameters ---------- X : array-like of shape (n_samples, n_features) Array of samples (test vectors).

Returns ------- C : ndarray of shape (n_samples,) or (n_samples, n_classes) Decision function values related to each class, per sample. In the two-class case, the shape is (n_samples,), giving the log likelihood ratio of the positive class.

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

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

.. versionchanged:: 0.19 ``store_covariances`` has been moved to main constructor as ``store_covariance``

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

Parameters ---------- X : array-like of shape (n_samples, n_features) Training vector, where n_samples is the number of samples and n_features is the number of features.

y : array-like of shape (n_samples,) Target values (integers)

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 predict : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Perform classification on an array of test vectors X.

The predicted class C for each sample in X is returned.

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

Returns ------- C : ndarray of shape (n_samples,)

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

Return log of posterior probabilities of classification.

Parameters ---------- X : array-like of shape (n_samples, n_features) Array of samples/test vectors.

Returns ------- C : ndarray of shape (n_samples, n_classes) Posterior log-probabilities of classification per class.

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

Return posterior probabilities of classification.

Parameters ---------- X : array-like of shape (n_samples, n_features) Array of samples/test vectors.

Returns ------- C : ndarray of shape (n_samples, n_classes) Posterior probabilities of classification per class.

val score : ?sample_weight:[> `ArrayLike ] Np.Obj.t -> x:[> `ArrayLike ] Np.Obj.t -> y:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.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 -> [> tag ] Obj.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 covariance_ : t -> Py.Object.t

Attribute covariance_: get value or raise Not_found if None.

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

Attribute covariance_: get value as an option.

val means_ : t -> [> `ArrayLike ] Np.Obj.t

Attribute means_: get value or raise Not_found if None.

val means_opt : t -> [> `ArrayLike ] Np.Obj.t option

Attribute means_: get value as an option.

val priors_ : t -> [> `ArrayLike ] Np.Obj.t

Attribute priors_: get value or raise Not_found if None.

val priors_opt : t -> [> `ArrayLike ] Np.Obj.t option

Attribute priors_: get value as an option.

val rotations_ : t -> Py.Object.t

Attribute rotations_: get value or raise Not_found if None.

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

Attribute rotations_: get value as an option.

val scalings_ : t -> Py.Object.t

Attribute scalings_: get value or raise Not_found if None.

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

Attribute scalings_: get value as an option.

val classes_ : t -> [> `ArrayLike ] Np.Obj.t

Attribute classes_: get value or raise Not_found if None.

val classes_opt : t -> [> `ArrayLike ] Np.Obj.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.