2017-08-11 79 views
0

我期待深入了解我的数据。我使用sklearn PCA将它们转换成VSM,并将它们绘制成matplotlib图形。这涉及绘制新文档以绘制散点图

  1. 使用管道

    test = pipeline.fit_transform(docs).todense() 
    
  2. 件到我的模型铸造的文件的数量矩阵

    pca = PCA().fit(test) 
    
  3. 然后我使用变换

    data = pca.transform(test) 
    
    将其转换
  4. 最后我用绘制Matplotlib

    plt.scatter(data[:,0], data[:,1], c = categories) 
    

我的问题,结果是这样的:我如何采取新的句子,并确定他们将在于相对于其他文件绘制。用X标记他们的相对位置?

感谢

回答

1
  1. 也蒙上了新的文件,数字数组

    new = pipeline.transform(new_docs).todense() 
    

    注意,这里使用了pipeline与先前安装参数,因此它pipeline.transform,不pipeline.fit_transform

  2. 使用预先安装pca变换新的数据。

    new_data = pca.transform(new) 
    

    这会将新数据转换为与原始数据相同的PC空间。

  3. 使用第二个scatter将新数据添加到图中。

    plt.scatter(data[:,0], data[:,1], c = categories) 
    plt.scatter(new_data[:,0], new_data[:,1], marker = 'x') 
    plt.show()