三元矩阵的分层聚类

发布于 2025-02-10 15:49:40 字数 908 浏览 1 评论 0原文

我有一个具有值-1,0,1的矩阵

array([[ 1,   1],
       [ 0,  -1],
       [ 1,  -1],
       [ 1,   1]
       [ -1,  1]])

,我想要的是从左到右的分层聚类。

  • “最大” 3个集群包含数据点,在第一个维度中具有-1,0或1。
  • 接下来的9个集群是对前3个群集的改进,以便它们包含一个
    • 1在第一维处,在二维或

      处1
    • 1在第一维处,在二维或

      处0
    • 1在第一个维度,第二维或

      处-1
    • 0在第一个维度,在第二维或

      处1
    • 0在第一个维度,0在第二维或

    • 0在第一维时-1在第二维或

    • -1在第一维处,在二维或

      处1
    • -1在第一维处,在二维或

      处0
    • -1在第一维处,第二维处-1

等等。

所需的输出应该是

output = [[[0,3],[],[2]],[[1],[],[]],[[4],[],[]]]

因为

数据点0([[ 1 ,1]),数据点2([ 1 ,-1])和数据点3([< 1 ,1])在第一个大集群中,数据点1([ 0 ,-1])在第二个大群集中,数据点4([ -1 ,1])在第三个大群集中,然后在第二个维度上进行的改进。

I have a matrix with values -1,0,1 of the form

array([[ 1,   1],
       [ 0,  -1],
       [ 1,  -1],
       [ 1,   1]
       [ -1,  1]])

and what I want is kind of a hierarchical clustering from left to right.

  • The 'biggest' 3 clusters contain the data points, that have a -1,0 or 1 in the first dimension.
  • The next 9 clusters are a refinement of the first 3 clusters such that they contain a
    • 1 at first dimension, 1 at second dimension or

    • 1 at first dimension, 0 at second dimension or

    • 1 at first dimension, -1 at second dimension or

    • 0 at first dimension, 1 at second dimension or

    • 0 at first dimension, 0 at second dimension or

    • 0 at first dimension, -1 at second dimension or

    • -1 at first dimension, 1 at second dimension or

    • -1 at first dimension, 0 at second dimension or

    • -1 at first dimension, -1 at second dimension

and so on.

The desired output should be

output = [[[0,3],[],[2]],[[1],[],[]],[[4],[],[]]]

because

data point 0 ([1,1]), data point 2 ([1,-1]) and data point 3 ([1,1]) are in the first big cluster, data point 1 ([0,-1]) is in the second big cluster, data point 4 ([-1,1]) is in the third big cluster and then the refinements concerning the second dimension.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˉ厌 2025-02-17 15:49:40

这不是聚类的一个很好的例子,我认为这更多是一个分类案例,因为在这种情况下定义了类别的类别,并且以下命题等确定性代码足以分类所有条目:

import numpy as np
a = np.array([[ 1,   1],
              [ 0,  -1],
              [ 1,  -1],
              [ 1,   1],
              [ -1,  1]])

def categorize(a):
    classes = [[[],[],[]],[[],[],[]],[[],[],[]]]
    def get_classes(x,y):
        idx = 0 if x==1 else 1 if x == 0  else 2
        idy = 0 if y==1 else 1 if y == 0  else 2
        return idx,idy

    for i in range(a.shape[0]):
        idx,idy=get_classes(a[i,0],a[i,1])
        classes[idx][idy].append(i)
    return classes

output = categorize(a)
print(output)

This is not a good example on clustering, I believe it's more of a classification case since the classes in this case are defined, and a deterministic code such as the proposition below is enough to classifiy all the entries:

import numpy as np
a = np.array([[ 1,   1],
              [ 0,  -1],
              [ 1,  -1],
              [ 1,   1],
              [ -1,  1]])

def categorize(a):
    classes = [[[],[],[]],[[],[],[]],[[],[],[]]]
    def get_classes(x,y):
        idx = 0 if x==1 else 1 if x == 0  else 2
        idy = 0 if y==1 else 1 if y == 0  else 2
        return idx,idy

    for i in range(a.shape[0]):
        idx,idy=get_classes(a[i,0],a[i,1])
        classes[idx][idy].append(i)
    return classes

output = categorize(a)
print(output)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文