【问题标题】:Working example of Principal Component Analysis? [closed]主成分分析的工作示例? [关闭]
【发布时间】:2011-05-19 20:24:55
【问题描述】:

是否有任何示例可以提供对数据集进行主成分分析的动手示例?我正在阅读仅讨论理论的文章,​​并且真的在寻找能够向我展示如何使用 PCA,然后解释结果并将原始数据集转换为新数据集的东西。请问有什么建议吗?

【问题讨论】:

    标签: language-agnostic machine-learning linear-algebra pca


    【解决方案1】:

    如果您了解 Python,这里有一个简短的动手示例:

    # Generate correlated data from uncorrelated data.
    # Each column of X is a 3-dimensional feature vector.
    Z = scipy.randn(3, 1000)
    C = scipy.randn(3, 3)
    X = scipy.dot(C, Z)
    
    # Visualize the correlation among the features.
    pylab.scatter(X[0,:], X[1,:])
    pylab.scatter(X[0,:], X[2,:])
    pylab.scatter(X[1,:], X[2,:])
    
    # Perform PCA. It can be shown that the principal components of the 
    # matrix X are equivalent to the left singular vectors of X, which are
    # equivalent to the eigenvectors of X X^T (up to indeterminacy in sign).
    U, S, Vh = scipy.linalg.svd(X)
    W, Q = scipy.linalg.eig(scipy.dot(X, X.T))
    print U
    print Q
    
    # Project the original features onto the eigenspace.
    Y = scipy.dot(U.T, X)
    
    # Visualize the absence of correlation among the projected features.
    pylab.scatter(Y[0,:], Y[1,:])
    pylab.scatter(Y[1,:], Y[2,:])
    pylab.scatter(Y[0,:], Y[2,:])
    

    【讨论】:

      【解决方案2】:

      您可以查看http://alias-i.com/lingpipe/demos/tutorial/svd/read-me.html SVD 和 LSA 与 PCA 的方法非常相似,都是空间缩减方法。基础评估方法的唯一区别。

      【讨论】:

        【解决方案3】:

        由于您要求提供可用的动手示例,here 您有一个交互式演示可以玩。

        【讨论】:

          猜你喜欢
          • 2021-12-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-10-25
          • 2013-10-24
          • 2013-08-24
          相关资源
          最近更新 更多