如何使用Python';s特征凝聚用于降维?
我找到了在Python中实现降维的方法,得到的结果是:。该网站上显示的最后一种方法是特征聚合。我点击了python方法文档的链接,但我仍然不确定如何使用它如何使用Python';s特征凝聚用于降维?,python,machine-learning,scikit-learn,feature-extraction,dimensionality-reduction,Python,Machine Learning,Scikit Learn,Feature Extraction,Dimensionality Reduction,我找到了在Python中实现降维的方法,得到的结果是:。该网站上显示的最后一种方法是特征聚合。我点击了python方法文档的链接,但我仍然不确定如何使用它 如果以前有人使用过Python的特性聚合方法,您是否可以解释它是如何工作的(输入、输出等)?谢谢 您可以使用numpy数组或pandas数据帧作为sklearn.cluster.features的输入 输出是一个numpy数组,行等于数据集中的行,列等于featurecongregation中设置的n_clusters参数 from skle
如果以前有人使用过Python的特性聚合方法,您是否可以解释它是如何工作的(输入、输出等)?谢谢 您可以使用numpy数组或pandas数据帧作为sklearn.cluster.features的输入 输出是一个numpy数组,行等于数据集中的行,列等于featurecongregation中设置的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()