首页 > 解决方案 > PCA 图降维

问题描述

我尝试使用 PCA 技术进行集群。

就我而言,我有 n 部电影的用户进行的评论。我以这种方式创建了一个表用户 x 电影:

User    Movie
        0 1 2 3 4 
      0 2 0 5 0 0
      1 0 1 1 0 0
      2 0 5 5 5 0

如果用户不评论电影,则为 0,如果他评论 1 到 5 星,则为 1-5。形状是 (6040, 3706)

我对数据进行规范化,然后将此代码用于 PCA(来自 sklearn)

pca = PCA(0.7)
pca_result = pca.fit_transform(X_std)

a = pca_result[:,0]
b = pca_result[:,1] 

我将 0.7 用于集群,因为我的累积解释方差 在此处输入图像描述

所以对我来说是非常具有代表性的值 0.7 而我的新形状是 (6040, 650)

在我看到尺寸将以这种方式绘制之后(但我认为不是很重要)

fig = plt.figure(figsize = (20,16))
ax = fig.add_subplot(111)


ax.scatter(a,b, alpha = 1)
plt.title('Method: PCA')
plt.show()

但是通过这种方式,我将 A 放在 X 轴上,将 B 放在 Y 轴上,所以我认为只使用二维(因为我看到了所有二维示例)。

在此处输入图像描述

所以我的问题是我没有绘制所有维度?(在我的情况下,650 个剩余尺寸?) 我做错了什么?

也许我的问题可能很愚蠢,但我试图理解这个话题。

标签: pythonmatplotlibpcadimensionality-reduction

解决方案


Don't use 0 to encode missing values (in particular, not with PCA).

This is the maximum difference to a 5, so in essence you are right now assuming that users hate all movies they did not rate.

I don't know if there is any variant of PCA that works with missing data. Usually it seems to assume you have all the the values. So you likely need to choose other algorithms.


推荐阅读