python - 在python中比较多维分布的测试
问题描述
我有以下数据集:
import random
import pandas as pd
A = pd.DataFrame({'x':[random.uniform(0, 1) for i in range(0,100)], 'y':[random.uniform(0, 1) for i in range(0,100)]})
B = pd.DataFrame({'x':[random.uniform(0, 1) for i in range(0,100)], 'y':[random.uniform(0, 1) for i in range(0,100)]})
从这两个数据集中,我可以生成以下图
import matplotlib.pyplot as plt
import scipy.stats as st
def plot_2d_kde(df):
# Extract x and y
x = df['x']
y = df['y']
# Define the borders
deltaX = (max(x) - min(x))/10
deltaY = (max(y) - min(y))/10
xmin = min(x) - deltaX
xmax = max(x) + deltaX
ymin = min(y) - deltaY
ymax = max(y) + deltaY
# Create meshgrid
xx, yy = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]
# We will fit a gaussian kernel using the scipy’s gaussian_kde method
positions = np.vstack([xx.ravel(), yy.ravel()])
values = np.vstack([x, y])
kernel = st.gaussian_kde(values)
f = np.reshape(kernel(positions).T, xx.shape)
fig = plt.figure(figsize=(13, 7))
ax = plt.axes(projection='3d')
surf = ax.plot_surface(xx, yy, f, rstride=1, cstride=1, cmap='coolwarm', edgecolor='none')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('PDF')
ax.set_title('Surface plot of Gaussian 2D KDE')
fig.colorbar(surf, shrink=0.5, aspect=5) # add color bar indicating the PDF
ax.view_init(60, 35)
plot_2d_kde(A)
plot_2d_kde(B)
有没有办法测试多维 PDF 是否与 python 中的A
不同B
?
解决方案
推荐阅读
- discord.js - Bot ping 即将到来
- javascript - 我如何“等待”异步 super() 构造函数?
- firebase - 无法在 Firebase 托管后面调用 Google Cloud Function - 状态 503,但状态页面上没有指示
- wso2 - Wso2 apim 3.2 与 Wso2 公里 5.10
- html - 如果同一个类出现在它之后,可以为元素设置样式吗?
- flutter - Flutter 应用程序自动检测超链接并通过点击打开它
- ios - 上下图像视图,反之亦然 Swift/iOS
- winapi - DrawFocusRect 函数:Windows 10 中奇怪的 2 像素焦点矩形
- python - Sentinel3 OLCI (chl) Python 上 netcdf 文件的平均值
- java - 如何仅计算输入值的数组平均值