0

私はPythonで次元削減を実装する方法を探しました。これが私が得た結果です:http://scikit-learn.org/stable/modules/unsupervised_reduction.html。そのウェブサイトに表示されている最後の方法は、フィーチャアグラムです。私は、そのpythonメソッドのドキュメントのリンクをクリックしましたが、私はまだそれを使用する方法がわかりません。次元削減のためにPythonの特徴集約を使用するには?

誰かが以前にPythonの機能集約メソッドを使っていたのであれば、それがどのように機能するか(入力、出力など)を説明することは可能でしょうか?ありがとう!あなたがnumpyの配列またはsklearn.cluster.FeatureAgglomeration

出力する入力としてパンダのデータフレームを使用することができ

答えて

2

はFeatureAgglomerationに設定されたパラメータデータセット内の行に等しい行およびn_clustersに等しい列のnumpyのアレイであります。

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() 

enter image description here

関連する問題