我正在尝试在sklearn 17.1中使用explained_variance_ratio_。
在sklearn文档中,它被描述为LinearDiscriminationAnalysis类的属性。
但是如何应用呢?
我的代码是
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as lda
clf = lda(solver='eigen', shrinkage = 'auto')
clf.fit((tr_train, targ_train)
基本上,我在尝试
lda.explained_variance_ratio_(tr_train)
但我有
AttributeError: 'LinearDiscriminantAnalysis' object has no attribute 'explained_variance_ratio_'
我认为您想要的可以通过以下方式实现:
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as lda
clf = lda(solver='eigen', shrinkage = 'auto')
clf.fit(tr_train, targ_train)
print clf.explained_variance_ratio_