文章目录
0 写在前面
判别分析相关概念请点击这里
参考资料:
- sklearn User’s Guide
1 LDA(线性判别分析)
1.1 导入LDA
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
1.2 api参数详解
LDA(solver=’svd’, shrinkage=None, priors=None, n_components=None, store_covariance=False, tol=0.0001)
solver
:svd
:奇异值分解,是默认的求解器,不计算协方差矩阵,因此建议用于具有大量特征的数据。lsqr
:最小二乘解。eigen
:特征值分解。
shrinkage
:收缩率,可以在训练样本数量比特征数量少的情况下改进协方差矩阵的估计。可以设置为auto
或[0,1]的数。指定为auto
时需要将sover
设置成lsqr
或eigen
。
下图来自于Sklearn官方文档关于收缩率在不同样本量下的表现。
priors
n_components
:类别数
store_covariance
tol
:SVD求解中用于秩和估计的阈值。
1.3 返回值的属性
coef_ :
Weight vector(s).
intercept_ :
Intercept term.
covariance_ :
Covariance matrix (shared by all classes).
explained_variance_ratio_ :
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.
1.4 返回值的方法
decision_function(self, X) Predict confidence scores for samples.
fit(self, X, y) Fit LinearDiscriminantAnalysis model according to the given training data and parameters.
fit_transform(self, X[, y]) Fit to data, then transform it.
get_params(self[, deep]) Get parameters for this estimator.
predict(self, X) Predict class labels for samples in X.
predict_log_proba(self, X) Estimate log probability.
predict_proba(self, X) Estimate probability.
score(self, X, y[, sample_weight]) Returns the mean accuracy on the given test data and labels.
set_params(self, **params) Set the parameters of this estimator.
transform(self, X) Project data to maximize class separation.
2 QDA(二次判别分析)
2.1 导入QDA
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis as QDA
2.2 api参数详解
QDA(priors=None, reg_param=0.0, store_covariance=False, tol=0.0001)