mojolearn.QuadraticDiscriminantAnalysis#
- class mojolearn.QuadraticDiscriminantAnalysis(*, solver='svd', shrinkage=None, priors=None, reg_param=0.0, store_covariance=False, tol=0.0001, covariance_estimator=None)#
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 withreg_param.'eigen'uses the empirical (optionally shrunk) class covariances and ignoresreg_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. Withsolver='svd'it raisesNotImplementedError.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
tolis rejected withValueError(its covariance is not full rank).covariance_estimator (object, default None) – An estimator with
fitand acovariance_attribute, used instead of the empirical covariance withsolver='eigen'(ValueErrorwith'svd'or withshrinkageset). 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
ValueErrorwith 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)
Methods
decision_function(X)fit(X, y)fit_transform(X[, y])Fit to
X, then transformX.get_params([deep])Return the constructor parameters as a dict.
predict(X)Predict the class of each row.
Return the unnormalized log score of each row and class.
Return the log of the class probabilities for each row.
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.
- fit_transform(X, y=None, **fit_params)#
Fit to
X, then transformX.- Returns:
array – The transformed data.
- get_params(deep=True)#
Return the constructor parameters as a dict.
- Parameters:
deep (bool, default True) – Accepted for scikit-learn compatibility.
- Returns:
dict – Parameter names mapped to their values.
- predict(X)#
Predict the class of each row.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Rows to classify.
- Returns:
array of shape (n_samples,) – Predicted class labels.
- predict_joint_log_proba(X)#
Return the unnormalized log score of each row and class.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Rows to score.
- Returns:
array of shape (n_samples, n_classes) – Log scores that
predict_log_probanormalizes, in the order ofclasses_.
- predict_log_proba(X)#
Return the log of the class probabilities for each row.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Rows to score.
- Returns:
array of shape (n_samples, n_classes) – Log probability of each class, in the order of
classes_.
- predict_proba(X)#
Return class probabilities for each row.
Probabilities are float32 in
identicalmode. Infastmode (Apple), they are float64, so that a very confident prediction does not round to exactly 1.0.- Parameters:
X (array-like of shape (n_samples, n_features)) – Rows to score.
- Returns:
array of shape (n_samples, n_classes) – Probability of each class, in the order of
classes_.
- score(X, y)#
Return the mean accuracy on the given rows and labels.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Rows to classify.
y (array-like of shape (n_samples,)) – True labels.
- Returns:
float – Fraction of rows classified correctly.
- set_params(**params)#
Set constructor parameters.
An unknown parameter name raises
ValueError.- Returns:
self