我试图可视化一个用scikit得到的给定数据集的单纯复杂图。代码如下:
import kmapper as km
from sklearn import cluster
# Define the data points
import numpy as np
data = np.asarray(
[ [145.0, 17.0], [166.0, 10], [145, 38], [161, 49],
[165, 24], [188, 41], [193, 18], [179, 52],
[208, 21], [194, 51], [198, 31], [207, 41],
[218, 55], [222, 26], [238, 27], [226, 41] ])
mapper = km.KeplerMapper(verbose=1)
projected_data = mapper.fit_transform(data, projection=[0],
distance_matrix="euclidean")
cover = km.Cover(n_cubes=10, perc_overlap=0.4)
graph = mapper.map(projected_data, data, cover=cover,
clusterer=cluster.AgglomerativeClustering(n_clusters=2,
linkage="single")
),
mapper.visualize(graph, path_html="graph1.html")
代码正确运行,直到最后一行,当我得到以下错误:
Created 11 edges and 16 nodes in 0:00:00.005993.
Traceback (most recent call last):
File "C:\Desktop\ex.py", line 24, in <module>
mapper.visualize(graph, path_html="graph1.html")
File "C:\Anaconda3\lib\site-packages\kmapper\utils.py", line 11, in wrapper
return f(*args, **kwargs)
File "C:\Anaconda3\lib\site-packages\kmapper\kmapper.py", line 829, in visualize
if not len(graph["nodes"]) > 0:
TypeError: tuple indices must be integers or slices, not str
1条答案
按热度按时间trnvg8h31#
由于某种原因,变量
graph
作为“tuple”而不是“dict”返回。我把最后一行换成了这就解决了问题