0

我真的对这个结果感到困惑.. 2 个类的相同数据集以及 PCA 和 LDA 的结果.. 这是合理的还是可能有问题?
感谢您的任何回答!

在此处输入图像描述

X = data.drop(['label'], axis=1)
y = data['label']
scaler = MinMaxScaler()
X_scaled = scaler.fit_transform(X)
"""
PCA 
"""
pca = PCA(n_components=2)
X_pca = pca.fit_transform(X_scaled)
"""
LDA 
"""
lda = LinearDiscriminantAnalysis(n_components=1,solver='svd').fit(X_scaled,y)
X_lda = lda.transform(X_scaled)

"""
Plot
"""
N = 2
target_names = list(range(N))
colors = ['yellow', 'purple']

"""
Plot PCA
"""
plt.figure()


lw = 2
for  color, i , target_name in zip(colors,range(N), target_names):
    plt.scatter(X_pca[y == i, 0], X_pca[y == i, 1], alpha=.8,color = color, lw = lw,label=target_name)
plt.legend(loc='best', shadow=False, scatterpoints=1)
plt.xlabel('pca 1')
plt.ylabel('pca 2')
plt.title('PCA')
plt.grid()
"""
Plot LDA  
"""
plt.figure()
for color, i, target_name in zip(colors,range(N), target_names):
    plt.scatter(X_lda[y == i, 0], X_lda[y == i, 0], alpha=.8, color=color,lw = lw,label=target_name)
plt.legend(loc='best', shadow=False, scatterpoints=1)
plt.xlabel('LD 1')
plt.ylabel('LD 2')
plt.title('LDA')
plt.grid()
4

0 回答 0