【问题标题】:How to use Python's feature agglomeration for dimensionality reduction? [closed]如何使用 Python 的特征聚合进行降维? [关闭]
【发布时间】:2017-08-11 00:22:00
【问题描述】:

我搜索了在 Python 中实现降维的方法,这是我得到的结果:http://scikit-learn.org/stable/modules/unsupervised_reduction.html。该网站显示的最后一种方法是特征集聚。我点击了该 python 方法的文档链接,但我仍然不确定如何使用它。

如果之前有人使用过 Python 的特征聚合方法,能否解释一下它是如何工作的(输入、输出等)?谢谢!

【问题讨论】:

    标签: python machine-learning scikit-learn feature-extraction dimensionality-reduction


    【解决方案1】:

    您可以使用 numpy 数组或 pandas 数据框作为 sklearn.cluster.FeatureAgglomeration 的输入

    输出是一个 numpy 数组,行数等于数据集中的行数,列数等于 FeatureAgglomeration 中设置的 n_clusters 参数。

    from sklearn.cluster import FeatureAgglomeration
    import pandas as pd
    import matplotlib.pyplot as plt
    
    #iris.data from https://archive.ics.uci.edu/ml/machine-learning-databases/iris/
    iris=pd.read_csv('iris.data',sep=',',header=None)
    #store labels
    label=iris[4]
    iris=iris.drop([4],1)
    
    #set n_clusters to 2, the output will be two columns of agglomerated features ( iris has 4 features)
    agglo=FeatureAgglomeration(n_clusters=2).fit_transform(iris)
    
    #plotting
    color=[]
    for i in label:
        if i=='Iris-setosa':
            color.append('g')
        if  i=='Iris-versicolor':
            color.append('b')
        if i=='Iris-virginica':
            color.append('r')
    plt.scatter(agglo[:,0],agglo[:,1],c=color)
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2022-01-15
      • 2021-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      • 2019-07-02
      • 2016-05-07
      • 2017-08-28
      相关资源
      最近更新 更多