【发布时间】:2020-07-15 07:53:03
【问题描述】:
我对我的数据集使用了 PCA 分析,如下所示:
from sklearn.decomposition import PCA
pca = PCA(n_components=3)
principalComponents = pca.fit_transform(scale_x)
principalDf = pd.DataFrame(data=principalComponents, columns = ['PC1', 'PC2', 'PC3'])
然后使用 MatPlotLib 可视化结果 - 我可以看到我的两个类之间的划分如下:
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(principalDf['PC1'].values, principalDf['PC2'].values, principalDf['PC3'].values, c=['red' if m==0 else 'green' for m in y], marker='o')
ax.set_xlabel('PC1')
ax.set_ylabel('PC2')
ax.set_zlabel('PC3')
plt.show()
但是当我使用像 SVM 或 Logistic Regression 这样的分类模型时,它无法学习这种关系:
from sklearn.linear_model import LogisticRegression
lg = LogisticRegression(solver = 'lbfgs')
lg.fit(principalDf.values, y)
lg_p = lg.predict(principalDf.values)
print(classification_report(y, lg_p, target_names=['Failure', 'Success']))
precision recall f1-score support Failure 1.00 0.03 0.06 67 Success 0.77 1.00 0.87 219 accuracy 0.77 286 macro avg 0.89 0.51 0.46 286 weighted avg 0.82 0.77 0.68 286
这可能是什么原因?
【问题讨论】:
标签: python matplotlib machine-learning scikit-learn pca