Math 计算一组值看起来有多好(分布有多好)
这组值: 1 2 3 3 4 1 如果你在条形图上想一想,看起来很不错:Math 计算一组值看起来有多好(分布有多好),math,statistics,computer-science,visualization,data-visualization,Math,Statistics,Computer Science,Visualization,Data Visualization,这组值: 1 2 3 3 4 1 如果你在条形图上想一想,看起来很不错: * * * * * * ======= 1 2 3 4 虽然这个看起来很糟糕。。 1 2 2 2 2 9 8 * * * * * * * * * * * ================= 1 2 3 4 5 6 7 8 9 这是因为有很多的2和一个很大的差距2和8 我需要找到一个公式来计算一组数字看起来有多漂亮。。 我想我需要一些偏差函数。。有什么想法吗 谢谢
* *
* * * *
=======
1 2 3 4
虽然这个看起来很糟糕。。
1 2 2 2 2 9 8
*
*
*
*
*
*
*
* * * *
=================
1 2 3 4 5 6 7 8 9
这是因为有很多的2和一个很大的差距2和8
我需要找到一个公式来计算一组数字看起来有多漂亮。。
我想我需要一些偏差函数。。有什么想法吗
谢谢你对“好”的定义有点宽泛。根据我对你所说的“好”的理解,我建议两种方法
A可能就是你要找的。如果以正确的方式使用,它将为您提供一个数字,描述您的分布与离散均匀分布的接近程度。离散均匀分布将是平坦的(即,每个直方图桶中的元素数量大致相同),这似乎符合您对“尼斯”的定义。A可能就是您想要的。如果以正确的方式使用,它将为您提供一个数字,描述您的分布与离散均匀分布的接近程度。离散均匀分布将是平坦的(即每个直方图桶中的元素数量大致相同),这似乎符合您对“尼斯”的定义。这对我来说似乎是合理的,但我对统计的了解非常有限:
from collections import Counter
def tonums( s ):
return [int(x) for x in s if x!=' ']
def nice( nums ):
# how far do they spread
used_range = range(min(nums), max(nums)+1)
# how often would each number occur if they were equally distributed
expected = 1.0*len(nums)/len(used_range)
# how often do they actually occur
counter = Counter(nums)
# compute the variance
return sum((count-expected)**2 for item, count in counter.iteritems())
# should be fst < snd
print nice(tonums('1 2 3 3 4 1'))
print nice(tonums('1 2 2 2 2 2 2 2 2 9 8'))
# these should be 0
print nice(tonums('1'))
print nice(tonums('1 1 1 1'))
# should be equal
print nice(tonums('1 1 2 3'))
print nice(tonums('1 2 2 3'))
从集合导入计数器
def音调:
如果x!='',则返回[int(x)for x in s]
def nice(nums):
#它们传播多远
使用范围=范围(最小值(nums),最大值(nums)+1)
#如果平均分布,每个数字出现的频率是多少
预期值=1.0*len(nums)/len(使用范围)
#它们实际发生的频率是多少
计数器=计数器(nums)
#计算方差
返回和((预计计数)**2,对于项目,在计数器中计数。iteritems())
#应为fst
这对我来说似乎是合理的,但我对统计学的知识非常有限:
from collections import Counter
def tonums( s ):
return [int(x) for x in s if x!=' ']
def nice( nums ):
# how far do they spread
used_range = range(min(nums), max(nums)+1)
# how often would each number occur if they were equally distributed
expected = 1.0*len(nums)/len(used_range)
# how often do they actually occur
counter = Counter(nums)
# compute the variance
return sum((count-expected)**2 for item, count in counter.iteritems())
# should be fst < snd
print nice(tonums('1 2 3 3 4 1'))
print nice(tonums('1 2 2 2 2 2 2 2 2 9 8'))
# these should be 0
print nice(tonums('1'))
print nice(tonums('1 1 1 1'))
# should be equal
print nice(tonums('1 1 2 3'))
print nice(tonums('1 2 2 3'))
从集合导入计数器
def音调:
如果x!='',则返回[int(x)for x in s]
def nice(nums):
#它们传播多远
使用范围=范围(最小值(nums),最大值(nums)+1)
#如果平均分布,每个数字出现的频率是多少
预期值=1.0*len(nums)/len(使用范围)
#它们实际发生的频率是多少
计数器=计数器(nums)
#计算方差
返回和((预计计数)**2,对于项目,在计数器中计数。iteritems())
#应为fst
你的问题有了答案-一组数字看起来有多漂亮
。首先定义一个what meansnice
并编写一个nice(list)
函数。您需要首先正式定义“nice”。“好”是指低标准差吗?“nice”的意思是否符合正态分布?这是否意味着数据很适合其他分布?我想知道如何定义nice。。我提供了两个例子,因为我不能在数学中很好地定义它。好的取决于你的动机和应用。为什么你想知道它有多好?这个问题几乎是纯统计而不是CS-/你的问题有答案-一组数字看起来有多漂亮
。首先定义一个what meansnice
并编写一个nice(list)
函数。您需要首先正式定义“nice”。“好”是指低标准差吗?“nice”的意思是否符合正态分布?这是否意味着数据很适合其他分布?我想知道如何定义nice。。我提供了两个例子,因为我不能在数学中很好地定义它。好的取决于你的动机和应用。为什么你想知道它有多好?这个问题几乎是纯统计而不是CS-/一个非常平坦的分布有成吨的高阶傅里叶系数。@honk,同意,但傅里叶分析可能对“nice”的其他一些值有用。一个非常平坦的分布有成吨的高阶傅里叶系数。@honk,同意,但傅里叶分析可能对“nice”的其他一些值有用