如何从线性判别分析中解释变量权重?
How to explain variables weight from a Linear Discriminant Analysis?
我正在研究受监督的 class化。首先,我想找到具有重要权重的变量来区分每个 class。我的代码如下:
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
X = X_train_std[0:1000,:]
y = y_train[0:1000]
target_names = classes
lda = LDA(n_components=2)
X_r2 = lda.fit(X, y).transform(X)
print('explained variance ratio (first two components) with LDA: %s'
% str(lda.explained_variance_ratio_))
结果是:
explained variance ratio (first two components) with LDA: [0.64492115 0.24080238]
然后我试试这个:
lda.covariance_
我得到一个错误:
AttributeError Traceback (most recent call last)
<ipython-input-28-35184940aba0> in <module>
----> 1 lda.covariance_
AttributeError: 'LinearDiscriminantAnalysis' object has no attribute 'covariance_'
你有解决这个问题的想法吗?此外,如果您知道如何创建关联圈,那就太好了!
谢谢。
您必须在创建 LDA 时指定要存储协方差...
解决这个问题:
lda = LDA(n_components=2, store_covariance=True)
应该就可以了
干杯
编辑:相关圆参见Plot a Correlation Circle in Python
我正在研究受监督的 class化。首先,我想找到具有重要权重的变量来区分每个 class。我的代码如下:
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
X = X_train_std[0:1000,:]
y = y_train[0:1000]
target_names = classes
lda = LDA(n_components=2)
X_r2 = lda.fit(X, y).transform(X)
print('explained variance ratio (first two components) with LDA: %s'
% str(lda.explained_variance_ratio_))
结果是:
explained variance ratio (first two components) with LDA: [0.64492115 0.24080238]
然后我试试这个:
lda.covariance_
我得到一个错误:
AttributeError Traceback (most recent call last)
<ipython-input-28-35184940aba0> in <module>
----> 1 lda.covariance_
AttributeError: 'LinearDiscriminantAnalysis' object has no attribute 'covariance_'
你有解决这个问题的想法吗?此外,如果您知道如何创建关联圈,那就太好了!
谢谢。
您必须在创建 LDA 时指定要存储协方差...
解决这个问题:
lda = LDA(n_components=2, store_covariance=True)
应该就可以了
干杯
编辑:相关圆参见Plot a Correlation Circle in Python