Python sklearn库实现判别分析(最近更新:2019/10/24)

0 写在前面

判别分析相关概念请点击这里
参考资料:

  1. 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)

solversvd:奇异值分解,是默认的求解器,不计算协方差矩阵,因此建议用于具有大量特征的数据。lsqr:最小二乘解。eigen:特征值分解。
shrinkage:收缩率,可以在训练样本数量比特征数量少的情况下改进协方差矩阵的估计。可以设置为auto或[0,1]的数。指定为auto时需要将sover设置成lsqreigen

下图来自于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)

发布了60 篇原创文章 · 获赞 32 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_42297855/article/details/102721008
今日推荐