使用PCA组件进行分类

我对我的数据集进行了PCA分析,如下所示:

from sklearn.decomposition import PCApca = 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 Axes3Dfig = 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()

PCA 3D Plot

但是,当我使用像SVM或Logistic Regression这样的分类模型时,它无法学习这种关系:

from sklearn.linear_model import LogisticRegressionlg = 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

这可能是什么原因?


回答:

首先,使用三个特征PC1、PC2、PC3。图中未显示的附加特征(PC4至PC6)可能会影响分类结果。

其次,分类器有时可能不如你想象的那样训练得好。我建议使用决策树来代替你使用的分类器,因为树是一种(水平)线性分类器,可能会产生你预期的结果。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注