相似度计算

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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值