DBSCANとspark_sklearnを使用して入力データをクラスタ化したいとします。私はクラスタリングの後、各入力インスタンスのラベルを取得したいと思います。出来ますか?DBSCANとspark_sklearnを使用したデータのクラスタ化
temp_data = Spark DataFrame containing 'key' and 'features' columns,
where 'features' is a Vector.
ke = KeyedEstimator(sklearnEstimator=DBSCAN(), estimatorType="clusterer")
print ke.getOrDefault("estimatorType") --> "clusterer"
ke.fit_pedict(temp_data) --> ERROR: 'KeyedEstimator' object has no attribute 'fit_predict'
k_model = ke.fit(temp_data)
print k_model.getOrDefault("estimatorType") --> "clusterer"
k_model.fit_pedict(temp_data) --> ERROR: 'KeyedModel' object has no attribute 'fit_predict'
k_model.predict(temp_data) --> ERROR: 'KeyedModel' object has no attribute 'predict'
k_model.transform(temp_data) --> ERROR: estimatorType assumed to be a clusterer, but sklearnEstimator is missing fit_predict()
(NOTE: sklearn.cluster.DBSCAN actually have fit_predict() method)
私は通常sklearnを使用してください(スパークなしで)(dbscan_model.fit(temp_data-features)
)を合わせて、モデル(labels = dbscan_model.labels_
)からラベルを取得することです:
はhttp://pythonhosted.org/spark-sklearnのドキュメントを読んで、私は、次の試してみました。 spark-sklearnを使って 'labels_'属性を得ることもできます。
上記の呼び出し( '変換'または '予測')が機能しない場合は、spark-sklearnを使用してデータをフィッティングした後に 'labels_'を取得できますか?どうやってやるの? 'labels_'を取得したと仮定すると、入力インスタンスをlabels_にどのようにマップできますか?彼らは同じ注文をしていますか?
は避けてください...層の上にstackinglayerは、パフォーマンスを殺す(とpysparkはすでに遅いという評判を持っている)、そして、あなたはもうすべての機能を得ることはありません。 –