在R中运行LDA,如下所示:
iris = read.table("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data", sep=",")
library("MASS")
mylda = lda(iris$V5~iris$V1+iris$V2+iris$V3+iris$V4)
mylda
提供以下输出报告:
Call:
lda(iris$V5 ~ iris$V1 + iris$V2 + iris$V3 + iris$V4)
Prior probabilities of groups:
Iris-setosa Iris-versicolor Iris-virginica
0.3333333 0.3333333 0.3333333
Group means:
iris$V1 iris$V2 iris$V3 iris$V4
Iris-setosa 5.006 3.418 1.464 0.244
Iris-versicolor 5.936 2.770 4.260 1.326
Iris-virginica 6.588 2.974 5.552 2.026
Coefficients of linear discriminants:
LD1 LD2
iris$V1 0.8192685 0.03285975
iris$V2 1.5478732 2.15471106
iris$V3 -2.1849406 -0.93024679
iris$V4 -2.8538500 2.80600460
Proportion of trace:
LD1 LD2
0.9915 0.0085
> mylda
Call:
lda(iris$V5 ~ iris$V1 + iris$V2 + iris$V3 + iris$V4)
Prior probabilities of groups:
Iris-setosa Iris-versicolor Iris-virginica
0.3333333 0.3333333 0.3333333
Group means:
iris$V1 iris$V2 iris$V3 iris$V4
Iris-setosa 5.006 3.418 1.464 0.244
Iris-versicolor 5.936 2.770 4.260 1.326
Iris-virginica 6.588 2.974 5.552 2.026
Coefficients of linear discriminants:
LD1 LD2
iris$V1 0.8192685 0.03285975
iris$V2 1.5478732 2.15471106
iris$V3 -2.1849406 -0.93024679
iris$V4 -2.8538500 2.80600460
Proportion of trace:
LD1 LD2
0.9915 0.0085
通过scikit在python中执行LDA:
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
mylda = LinearDiscriminantAnalysis().fit(iris.loc[:, 0:3], iris.loc[:, 4])
print(mylda.priors_)
print(mylda.means_)
print(mylda.scalings_)
到目前为止产生以下输出:
array([ 0.33333333, 0.33333333, 0.33333333])
array([[ 5.006, 3.418, 1.464, 0.244],
[ 5.936, 2.77 , 4.26 , 1.326],
[ 6.588, 2.974, 5.552, 2.026]])
array([[-0.81926852, 0.03285975],
[-1.5478732 , 2.15471106],
[ 2.18494056, -0.93024679],
[ 2.85385002, 2.8060046 ]])
如何获取/打印R's LDA在python中打印的“跟踪比例:”?
答案 0 :(得分:0)
线性描述的Coffecient可以使用:
找到trans=mylda.transform(iris.loc[:, 0:3])