model = AgglomerativeClustering(linkage='average', affinity='cosine')
model.fit(X)
ii = itertools.count(X.shape[0])
[{'node_id': next(ii), 'left': x[0], 'right': x[1]} for x in model.children_]
Как пройти по дереву из sklearn AgglomerativeClustering?