import numpy as np
import scipy.stats
import pandas as pd
import matplotlib.pyplot as plt
import fastdtw
def 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)
相似度计算
最新推荐文章于 2023-12-19 20:37:38 发布