【发布时间】:2016-08-31 16:11:32
【问题描述】:
我正在尝试绘制具有x 和y 值的数据集的二元ccdf。
单变量我可以很好地绘制,下面是输入,代码是单变量数据集。
输入:这些只是数据点的前 20 行。输入有 1000 行,其中 col[1] 和 col[3] 需要绘制,因为它们具有用户和关键字频率关系。
tweetcricscore 34 #afgvssco 51
tweetcricscore 23 #afgvszim 46
tweetcricscore 24 #banvsire 12
tweetcricscore 456 #banvsned 46
tweetcricscore 653 #canvsnk 1
tweetcricscore 789 #cricket 178
tweetcricscore 625 #engvswi 46
tweetcricscore 86 #hkvssco 23
tweetcricscore 3 #indvsban 1
tweetcricscore 87 #sausvsvic 8
tweetcricscore 98 #wt20 56
代码:统一数据集
import numpy as np
import matplotlib.pyplot as plt
from pylab import*
import math
from matplotlib.ticker import LogLocator
data = np.genfromtxt('keyword.csv', delimiter=',', comments=None)
d0=data[:,1]
X0 = np.sort(d0)
cdf0 = np.arange(len(X0))/float(len(X0))
ccdf0 = 1 - cdf0
plt.plot(X0,ccdf0, color='b', marker='.', label='Keywords')
plt.legend(loc='upper right')
plt.xlabel('Freq (x)')
plt.ylabel('ccdf(x)')
plt.gca().set_xscale("log")
#plt.gca().set_yscale("log")
plt.show()
我正在为双变量数据点寻找一些选项。我提到了Seaborn Bivariate Distribution,但我无法将它与我的数据集放在适当的上下文中。
欢迎在 python、matplotlib、seaborn 中提出任何替代建议。 提前致谢。
【问题讨论】:
-
您的示例在其中一列中只有 1 个不同的值,所以我不确定我是否看到了双变量密度估计的意义。
-
我确实提到它只是前 20 行。数据已经排序。两列都有不同的值
-
那么您应该更新您的示例以更具代表性。随机数据就足够了。
-
您能否详细说明 col[0]、col[1]、col[2] 和 col[3] 中的值代表什么?我怀疑你有一些分类的东西(col[3] 是类别 ID 还是有意义的值?)。你可以建立一个累积分布函数,但它是不相关的,因为你的数据不是连续的,所以它是不可解释的(除了某个类别对 cdf 贡献了一定的百分比..)
-
col[0] 是一个用户,col[2] 是同一用户发布的关键词 col[1] 和 col[3] 分别是用户和关键词的频率。数据本质上是离散的,我试图在分类前后绘制这些数据的性质。
标签: python numpy matplotlib visualization seaborn