scipy.cluster.hierarchy.dedrogram "above_threshold_color=above_threshold_color" 中的错误

Error in scipy.cluster.hierarchy.dedrogram "above_threshold_color=above_threshold_color"

我正在尝试使用 scipy 0.18.1(在 mac 上)在 Python 3.5 中可视化树状图,代码如下:

import numpy as np
import pandas as pd
import scipy as sci
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
from scipy.cluster.hierarchy import cophenet
from scipy.spatial.distance import pdist

data = pd.read_csv("data.csv", header = 0)
data_clean = data.dropna()

cluster = data_clean[['HI','GO', 'PA', 'TE', 'GC', 'FU', 'LA']]
cluster = np.array(cluster)
cluster

data_dist = pdist(cluster) 
data_link = linkage(data_dist)

plt.figure(figsize=(25, 10))
plt.title('Hierarchical Clustering Dendrogram')
plt.xlabel('sample index')
plt.ylabel('distance')
dendrogram(data_link)

但是returns这个错误

---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
<ipython-input-14-57671852a042> in <module>()
  1 plt.figure(figsize=(7, 5))
----> 2 dendrogram(data_link)#, labels= ('HI','GO', 'PA', 'TE', 'GC', 'FU', 'LA'))
  3 plt.title('Hierarchical Clustering Dendrogram')#'Dendrograma de Clusterización Jerárquiza')
  4 plt.xlabel('sample index')#'Islas')
  5 plt.ylabel('distance')#'Disimilitud de Jaccard')

 /Users/Irbin/anaconda/lib/python3.5/site-packages/scipy/cluster/hierarchy.py in dendrogram(Z, p, truncate_mode, color_threshold, get_leaves, orientation, labels, count_sort, distance_sort, show_leaf_counts, no_plot, no_labels, leaf_font_size, leaf_rotation, leaf_label_func, show_contracted, link_color_func, ax, above_threshold_color)
2289         contraction_marks=contraction_marks,
2290         link_color_func=link_color_func,
 -> 2291         above_threshold_color=above_threshold_color)
2292 
2293     if not no_plot:

/Users/Irbin/anaconda/lib/python3.5/site-packages/scipy/cluster/hierarchy.py in _dendrogram_calculate_info(Z, p, truncate_mode, color_threshold, get_leaves, orientation, labels, count_sort, distance_sort, show_leaf_counts, i, iv, ivl, n, icoord_list, dcoord_list, lvs, mhr, current_color, color_list, currently_below_threshold, leaf_label_func, level, contraction_marks, link_color_func, above_threshold_color)
2577             level=level + 1, contraction_marks=contraction_marks,
2578             link_color_func=link_color_func,
 -> 2579             above_threshold_color=above_threshold_color)
2580 
2581     max_dist = max(uamd, ubmd, h)

/Users/Irbin/anaconda/lib/python3.5/site-packages/scipy/cluster/hierarchy.py in _dendrogram_calculate_info(Z, p, truncate_mode, color_threshold, get_leaves, orientation, labels, count_sort, distance_sort, show_leaf_counts, i, iv, ivl, n, icoord_list, dcoord_list, lvs, mhr, current_color, color_list, currently_below_threshold, leaf_label_func, level, contraction_marks, link_color_func, above_threshold_color)
2577             level=level + 1, contraction_marks=contraction_marks,
2578             link_color_func=link_color_func,
 -> 2579             above_threshold_color=above_threshold_color)
2580 
2581     max_dist = max(uamd, ubmd, h)

/Users/Irbin/anaconda/lib/python3.5/site-packages/scipy/cluster/hierarchy.py in _dendrogram_calculate_info(Z, p, truncate_mode, color_threshold, get_leaves, orientation, labels, count_sort, distance_sort, show_leaf_counts, i, iv, ivl, n, icoord_list, dcoord_list, lvs, mhr, current_color, color_list, currently_below_threshold, leaf_label_func, level, contraction_marks, link_color_func, above_threshold_color)
2577             level=level + 1, contraction_marks=contraction_marks,
2578             link_color_func=link_color_func,
 -> 2579             above_threshold_color=above_threshold_color)
2580 
2581     max_dist = max(uamd, ubmd, h)

/Users/Irbin/anaconda/lib/python3.5/site-packages/scipy/cluster/hierarchy.py in _dendrogram_calculate_info
         levellevel   contraction_markscontraction_marks
         link_color_funclink_color_func

实际上,在错误报告中,max_dist = max(uamd, ubmd, h)的块重复了太多次。分析似乎工作正常,但我无法绘制树状图。可能是什么错误?

我已经解决了。我只需要转置我的数据。错误是指我的集群中有太多组;因此,Python 没有足够的颜色来可视化它们。