本文共 949 字,大约阅读时间需要 3 分钟。
import numpy as npimport scipy.statsimport pandas as pdimport matplotlib.pyplot as pltimport fastdtwdef plot_pic(x, y, z): plt.figure() plt.plot(x, color = 'r', label = 'x') plt.plot(y, color = 'b',label = 'y') plt.plot(z, color = 'y',label = 'z') plt.legend() plt.show()# 随机生成两个离散型分布# x = [np.random.randint(1, 11) for i in range(10)]# y = [np.random.randint(1, 11) for i in range(10)]x = [10, 4, 9, 9, 3, 3, 3, 9, 2, 9]y = [1, 3, 9, 1, 10, 4, 9, 9, 3, 3]z = [10, 4, 5, 4, 3, 3, 2, 5, 2, 9]print(x)print(y)KL = scipy.stats.entropy(x, y) print("KL散度x-y:", KL)KL = scipy.stats.entropy(y, x) print("KL散度y-x:", KL)print('spearman---x-y: ', pd.Series(x).corr(pd.Series(y),method='spearman'))dis, _ = fastdtw(x, y)print('')print('*'*30)KL = scipy.stats.entropy(x, z) print("KL散度x-z:", KL)KL = scipy.stats.entropy(z, x) print("KL散度z-x:", KL)print('spearman---x-z: ', pd.Series(x).corr(pd.Series(z),method='spearman'))plot_pic(x, y, z)
转载地址:http://czmfb.baihongyu.com/