The_Nightime 2024-03-27 16:01 采纳率: 0%
浏览 19

使用tslearn中的TimeSeriesKMeans时,将metric设置为softdtw后,聚类中心有误

我在使用tslearn中的TimeSeriesKMeans时,将metric设置为softdtw时出现了问题,即聚类中心在可视化时非常离谱,不符实际。

但是将metric设置为欧式距离就没有问题,请教这是为什么?

def softdtw_KMeans(df_array, number_of_components):
    Kmeans = TimeSeriesKMeans(n_clusters=number_of_components,
                              metric='softdtw', init='random').fit(df_array)
    cluster_center = Kmeans.cluster_centers_
    return Kmeans, cluster_center

def cluster_center_plotter(df_array, number_of_components, time_series_class, cluster_center):
    global time
    cluster_10th_percentile = []
    cluster_90th_percentile = []

    for yi in range(number_of_components):
        for time in range(df_array.shape[1]):
            class_temporary = df_array[time_series_class == yi]
            number_1 = np.percentile(class_temporary[:, time], 10)
            number_2 = np.percentile(class_temporary[:, time], 90)
            cluster_10th_percentile.append(number_1)
            cluster_90th_percentile.append(number_2)
    cluster_10th_percentile = np.reshape(cluster_10th_percentile, (number_of_components, df_array.shape[1]))
    cluster_90th_percentile = np.reshape(cluster_90th_percentile, (number_of_components, df_array.shape[1]))

    plt.figure()
    for yi in range(number_of_components):
        plt.subplot(3, 3, yi + 1)
        for xx in range(3):
            plt.plot(cluster_10th_percentile[yi, :], "k-", alpha=.2)
            plt.plot(cluster_90th_percentile[yi, :], "k-", alpha=.2)
            plt.plot(cluster_center[yi].ravel(), "r-")
    return plt.show()

# softdtw_KMeans
km, cluster_center = KMeans_clustering.softdtw_KMeans(dataset, number_of_components)

# Plotting the clusters centre
# taking the 10th and 90th percentile to display along with the clusters centre
KMeans_clustering.cluster_center_plotter(dataset, number_of_components, time_series_class, cluster_center)

上图为使用欧式距离度量,下图为softdtw距离

img

img

  • 写回答

3条回答 默认 最新

  • IT工程师_二师兄 2024-03-28 10:54
    关注

    你把报错信息发给我

    评论

报告相同问题?

问题事件

  • 创建了问题 3月27日

悬赏问题

  • ¥15 Windows Script Host 无法找到脚本文件"C:\ProgramData\Player800\Cotrl.vbs”
  • ¥15 matlab自定义损失函数
  • ¥15 35114 SVAC视频验签的问题
  • ¥15 impedancepy
  • ¥15 求往届大挑得奖作品(ppt…)
  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图