mojolearn.QuadraticDiscriminantAnalysis#

class mojolearn.QuadraticDiscriminantAnalysis(*, solver='svd', shrinkage=None, priors=None, reg_param=0.0, store_covariance=False, tol=0.0001, covariance_estimator=None)[source]#

Bases: _Classifier

Quadratic discriminant analysis classifier.

Follows scikit-learn’s QuadraticDiscriminantAnalysis. It fits one Gaussian per class, each with its own covariance, and classifies by the resulting quadratic decision function. Computation is float32.

Parameters:
  • solver ({‘svd’, ‘eigen’}, default ‘svd’) – 'svd' regularizes with reg_param. 'eigen' uses the empirical (optionally shrunk) class covariances and ignores reg_param, as in scikit-learn.

  • shrinkage ({None, ‘auto’} or float, default None) – Covariance shrinkage for 'eigen': 'auto' uses the Ledoit-Wolf estimate, a float in [0, 1] sets it directly. With solver='svd' it raises NotImplementedError.

  • priors (array-like of shape (n_classes,), default None) – Class priors (nonnegative). None uses the class frequencies.

  • reg_param (float, default 0.0) – Regularization of the class covariances under 'svd'.

  • store_covariance (bool, default False) – Store each class covariance in covariance_.

  • tol (float, default 1e-4) – A class whose scalings are not all above tol is rejected with ValueError (its covariance is not full rank).

  • covariance_estimator (object, default None) – An estimator with fit and a covariance_ attribute, used instead of the empirical covariance with solver='eigen' (ValueError with 'svd' or with shrinkage set). It is fitted on the host on each class’s float32 rows.

Variables:
  • classes_ (array of shape (n_classes,)) – Class labels.

  • means_ (array of shape (n_classes, n_features)) – Class means.

  • priors_ (array of shape (n_classes,)) – Class priors used.

  • rotations_ (list of arrays) – Per class, the (n_features, n_features) eigenvectors of its covariance.

  • scalings_ (list of arrays) – Per class, the (n_features,) variances along those eigenvectors.

  • covariance_ (list of arrays) – Per class covariance, when store_covariance=True.

  • n_features_in_ (int) – Number of columns seen in fit.

  • numeric_mode_ (str) – Numeric mode the estimator was fitted in; prediction runs in the same mode.

Notes

Fit raises ValueError with fewer than two classes or when a class has a single row.

Examples

>>> import numpy as np, mojolearn
>>> rng = np.random.default_rng(0)
>>> X = rng.random((1000, 4), dtype=np.float32)
>>> y = rng.integers(0, 2, 1000)
>>> model = mojolearn.QuadraticDiscriminantAnalysis().fit(X, y)
__init__(*, solver='svd', shrinkage=None, priors=None, reg_param=0.0, store_covariance=False, tol=0.0001, covariance_estimator=None)[source]#

Methods

decision_function(X)

fit(X, y)

fit_transform(X[, y])

Fit to X, then transform X.

get_params([deep])

Return the constructor parameters as a dict.

predict(X)

Predict the class of each row.

predict_joint_log_proba(X)

Return the unnormalized log score of each row and class.

predict_log_proba(X)

Return the log of the class probabilities for each row.

predict_proba(X)

Return class probabilities for each row.

score(X, y)

Return the mean accuracy on the given rows and labels.

set_params(**params)

Set constructor parameters.