2016-03-08 59 views
0

对于一个任务,我将使用ConditionalProbDist,使用LidstoneProbDist作为估计器,为每个bin添加+0.01的样本数。Python:NLTK ValueError:Lidstone概率分布必须至少有一个bin?

我想下面的代码行会做到这一点,但它产生的值误差

fd = nltk.ConditionalProbDist(fd,nltk.probability.LidstoneProbDist,0.01) 

我不知道如何格式化内ConditionalProbDist参数和找出还没有多少运气如何通过python的帮助功能或谷歌,所以如果任何人都可以设置我的权利,这将是非常感谢!

回答

1

你可能因为这个问题已经很老了不需要这个了,不过,你可以通过LidstoneProbDist参数ConditionalProbDist与拉姆达的帮助:

estimator = lambda fdist, bins: nltk.LidstoneProbDist(fdist, 0.01, bins) 
cpd = nltk.ConditionalProbDist(fd, estimator, bins) 
0

我发现the probability tutorial的NLTK网站上相当作为参考很有帮助。

正如在上面的答案中所提到的,使用lambda表达式是一个好主意,因为ConditionalProbDist将生成频率分布(nltk.FreqDist),并通过传递给估计器。

更微妙的一点是,如果您不知道输入样本中最初有多少个垃圾箱,则无法通过垃圾箱参数!但是,FreqDist的箱数可用数为FreqDist.B()docs)。

而是使用FreqDist作为唯一的参数给您的拉姆达:

from nltk.probability import * 
# ... 

# Using the given parameters of one extra bin and a gamma of 0.01 
lidstone_estimator = lambda fd: LidstoneProbDist(fd, 0.01, fd.B() + 1) 
conditional_pd = ConditionalProbDist(conditional_fd, lidstone_estimator) 

我知道这个问题已经很老了,但我也努力寻找文件,所以我的情况下,其他人在这里它文档在这条线上也遇到了类似的情况。

祝你好运!

相关问题