Получите кластеры из агломерации для данного усечения.Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Получите кластеры из агломерации для данного усечения.

Сообщение Anonymous »

На примере scikit-learn с использованием scipy (только изменение truncate_mode с «level» на «lastp»)

Код: Выделить всё

import numpy as np

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram
from sklearn.datasets import load_iris
from sklearn.cluster import AgglomerativeClustering

def plot_dendrogram(model, **kwargs):
# Create linkage matrix and then plot the dendrogram

# create the counts of samples under each node
counts = np.zeros(model.children_.shape[0])
n_samples = len(model.labels_)
for i, merge in enumerate(model.children_):
current_count = 0
for child_idx in merge:
if child_idx < n_samples:
current_count += 1  # leaf node
else:
current_count += counts[child_idx - n_samples]
counts[i] = current_count

linkage_matrix = np.column_stack(
[model.children_, model.distances_, counts]
).astype(float)

# Plot the corresponding dendrogram
dendrogram(linkage_matrix, **kwargs)

iris = load_iris()
X = iris.data

# setting distance_threshold=0 ensures we compute the full tree.
model = AgglomerativeClustering(distance_threshold=0, n_clusters=None)

model = model.fit(X)
plt.title("Hierarchical Clustering Dendrogram")
# plot the top three levels of the dendrogram
plot_dendrogram(model, truncate_mode="lastp", p=10)
plt.xlabel("Number of points in node (or index of point if no parenthesis).")
plt.show()
Понятно,
Изображение

Теперь, как мне получить элементы, принадлежащие каждому из кластеров для этого конкретного усечения?
Я хотел бы знать индексы 21, 17, 12 и т. д. элементы, составляющие каждый из этих кластеры.

Подробнее здесь: https://stackoverflow.com/questions/704 ... truncation
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»