- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当使用 scipy.spatial.distance.pdist
创建压缩距离矩阵并将其传递给 ward
时,出现此错误:
Valid methods when the raw observations are omitted are 'single', 'complete', 'weighted', and 'average' error.
虽然文档说 linkage()
函数需要一个压缩距离矩阵。我该如何解决这个问题?
foo = np.random.randint(3, size=(10,10))
scipy.spatial.distance.pdist(foo)
scipy.cluster.hierarchy.linkage(foo)
bar = scipy.spatial.distance.pdist(foo)
scipy.cluster.hierarchy.linkage(bar, method='ward')
给出:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/scipy /cluster/hierarchy.py", line 627, in linkage
raise ValueError("Valid methods when the raw observations are "
ValueError: Valid methods when the raw observations are omitted are 'single', 'complete', 'weighted', and 'average'.
我搜索了一下,找到了 this link ,表明其他一些人也有问题,但我无法找到一种解决方法来以 scipy 可以接受的形式提供数据。
最佳答案
来自文档字符串:
y : ndarray
A condensed or redundant distance matrix. A condensed distance matrix is a flat array containing the upper triangular of the distance matrix. This is the form that pdist returns. Alternatively, a collection of m observation vectors in n dimensions may be passed as an m by n array.
传入您的原始观察 x 维度数组 foo
似乎有效:
scipy.cluster.hierarchy.linkage(foo, method='ward')
给出:
array([[ 1. , 2. , 2.23606798, 2. ],
[ 5. , 8. , 2.23606798, 2. ],
[ 3. , 7. , 2.64575131, 2. ],
[ 9. , 11. , 2.64575131, 3. ],
[ 0. , 10. , 3.31662479, 3. ],
[ 12. , 13. , 3.71483512, 5. ],
[ 6. , 14. , 4.12310563, 4. ],
[ 4. , 16. , 4.17133072, 5. ],
[ 15. , 17. , 5.5136195 , 10. ]])
我同意 linkage()
的文档至少可以改进。
关于python - 你如何访问 scipy 中的 ward/centroid/median 聚类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29152518/
我想计算存储为位压缩整数数组的位图(黑白)的质心。我知道有一些快速算法可以计算整数中设置位的数量,但这并不能帮助我计算质心。有什么想法吗? 举个例子,如果我的位图是这样的: 111000 111000
我想为 d3 map 中的每个社区添加一个社区名称。 我在这段代码中使用了 centroid() 函数。 var mapLabel = svg.selectAll("text") .data(
我需要获取 质心 (质心)用于一组具有亚像素精度的二值图像中的组件。 Mathematica 8 附带了一个很好的补充: i = Import@"http://i.stack.imgur.com/2
通过邮政编码质心进行地理编码,但是是否有一个 zip+4 质心,它会更细化但不完全是街道地址粒度? 最佳答案 就在这里。我在 SmartyStreets 工作,我们在这里验证和地理编码街道地址。 ZI
System.Windows.Shapes.Shape 命名空间提供对可在 XAML 或代码中使用的 Polygon 对象的访问。 是否有 Microsoft 库提供一些非常基本的多边形计算,例如面积
如何找到从质心到每个簇中所有数据点的平均距离。我能够从每个簇的质心找到每个点(在我的数据集中)的欧氏距离。现在我想找到从质心到每个集群中所有数据点的平均距离。计算与每个质心的平均距离的好方法是什么?到
此代码是我用于 silhouette_score 的代码. 在这里我使用凝聚聚类,链接作为病房。 我想获得凝聚聚类的“质心”,从凝聚聚类中可以获得吗?我只能得到 K 均值的质心和模糊 c 均值。 df
所以,最近我开始尝试使用 D3 library .我已经成功制作了一个有效的和弦图,here's the pen . var parentSelector = '#con1' var width =
我有一个多边形(在 Shapely 对象中转换)。我的目标是按照图形示例计算“内部质心”(也称为“表面上的点”)(返回 x、y 值)和“质心”(返回 x、y 值): from shapely.geom
我正在训练一种需要对数据点进行集群的无监督学习模型。现在,出于验证目的,我拥有每个类的数据点的平均值,并且我需要将每个数据点分配到不同的类。。假设我有4个班级,每个班级A、B、C、D和质心1、2、3、
公平警告:我是这里的 D3 新手。我正在使用 D3 构建一个 donut chart ,到目前为止一切都很好,除了切片上的标签没有与切片对齐。使用下面的代码,每个切片的标签都呈现在图表的中间,彼此堆叠
当使用 scipy.spatial.distance.pdist 创建压缩距离矩阵并将其传递给 ward 时,出现此错误: Valid methods when the raw observation
问题是我无法用现有代码实现质心,在检测到的对象被矩形包围后使用哪个图像对象等,这样我就可以获得路径的轨迹。 我正在使用 Opencv2.3 。我发现有两种方法 - Link1和 Link2谈谈mome
我有一个基于谷歌地图的程序,可以根据用户输入计算面积。这里是 Demo JSFiddle HTML 应该是这样的 Length (red line): 0 mt - Area (gr
我已经用 Java 实现了整个模糊逻辑系统,但我在去模糊化过程中遇到了严重的问题。 在我的代码中,我将输入定义为时间和距离,输出只是输出。我拥有构造输入和输出集的每个线性函数,因此我可以访问它的任何值
我一直在使用 scipy.cluster.vq.kmeans 进行一些 k 均值聚类,但想知道是否有一种方法可以确定每个数据点是哪个质心(假定)与相关联。 显然您可以手动执行此操作,但据我所知,kme
Sci-Kit学习Kmeans和PCA降维 我有一个 200 万行 x 7 列的数据集,其中包含不同的家庭用电量测量值以及每个测量值的日期。 日期, Global_active_power, Glob
我正在创建一个 donut (或饼图),并且我想将标签放置在该区域之外。我创建了一个 fiddle http://jsfiddle.net/VeeTee/mA3V7/为它。 arcs.append("
我正在尝试使用 centroid() 函数将圆弧标签居中,如 D3 documentation 中所述. arcs.append("text") .attr("transform", function
我正在编写一个用于 K 均值聚类的程序,以找到每个点应属于的聚类。此代码有 8 个点和 3 个簇。在我的代码中,“条目”函数以某种方式无限执行。我找不到哪里出错了。这是我遵循的逻辑: 8个点的硬编码输
我是一名优秀的程序员,十分优秀!