如何计算散点图中每个聚类的距离

问题描述 投票:0回答:1

我在散点图中绘制了2个群集,我需要找到它们的标准偏差和从一个群集到另一个群集的中心到中心的距离。我找不到任何简化散点图查找2个聚类中心的过程的文档指南,原因是我需要将每个聚类的散度与聚类中心的距离进行比较。我的实际散点图如下所示:

import matplotlib.pyplot as plt
import numpy as np


vector1 = [
    2.8238, 
    3.0284, 
    5.9333,
    2.0156,
    2.2467, 
    2.0092,
    4.7983, 
    4.3554,
    3.6372, 
    1.3159, 
    2.6174, 
    2.2336, 
    0.9625, 
    5.6285, 
    5.4040, 
    2.7887, 
    0, 
    3.4632, 
    0, 
    2.7370
]  
vector5 = [
    1.2994, 
    7.4469,
    3.6503, 
    2.1667,
    4.1975, 
    3.3006, 
    10.4082, 
    3.4112, 
    2.2395, 
    1.5653, 
    4.3237, 
    1.8679, 
    1.2622, 
    14.1372, 
    6.1686, 
    3.8903, 
    2.2873, 
    6.2559, 
    0.2132, 
    7.2303,
]

plt.rcParams['figure.figsize'] = (16.0, 10.0)
plt.style.use('ggplot')
data = [vector1, std_colomns4]

plt.plot(vector1 , marker='.', linestyle='none', markersize=20, label='Vector 1')
plt.plot(vector5, marker='.', linestyle='none', markersize=20, label='Vector 5')


plt.xticks(range(1, 20, 1))
plt.yticks(range(1, 20, 1))
plt.ylabel('Sizes')
plt.xlabel('Index')
plt.legend()
plt.show()

为了可视化:

enter image description here

python python-3.x matplotlib data-visualization
1个回答
0
投票

您可以通过将均值转换为数组来计算均值

vector1 = np.array([...])
vector5 = np.array([...])

mean1 = np.mean(vector1)
mean5 = np.mean(vector5)

# Rest of the code

plt.plot((vector1+vector5)/2, marker='x', linestyle='none', markersize=12, label='Mean')

plt.axhline(mean1)
plt.axhline(mean5, c='b')

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.