Ruby 中的朴素贝叶斯
我们正在尝试用 Ruby 进行朴素贝叶斯分类。
目前我们正在使用 http://ai4r.rubyforge.org/
我们无法让它适用于浮点值字符串值的准确度降低约 20%。使用浮点/整数,我们得到 [] 没有从 nil 到整数的隐式转换。我们用 to_s 转换浮点数。
有没有办法让浮点值发挥作用?如果不是的话,Ruby 的 ai4r 的替代 gem 或朴素贝叶斯的替代算法是什么?
We are trying to do naive bayes classification in Ruby.
Currently we are using http://ai4r.rubyforge.org/
We couldn't get it working for float values and have about 20% points lower accuracy with string values. With float/integers we get a [] no implicit conversion from nil to integer. We convert floats with to_s.
Is there a way to get float values working? If not what are alternative gems to ai4r for ruby or alternative algorithms to naive bayes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“...隐式转换...”错误来自 Ruby 解释器内的上下文,其中需要
Integer
但需要nil
被发现。出现此错误有点困难,但查看它的一种方法是:
...所以这可能就是您的情况发生的情况。
事实上,gems/ai4r-1.9/lib/ai4r/classifiers/naive_bayes.rb 实际上使用了相当罕见的 Array.new(...) 构造。
传递给 Array.new() 的值取决于
Ai4r: :Data::DataSet
从#build_domains。
我知道这一点不能解决您的问题,但也许它会帮助您进一步进行分析。
The "...implicit conversion..." error is coming from within the Ruby interpreter in a context where an
Integer
is required but anil
is found.It's a bit hard to get this error but one way to see it is:
...so that's probably what is happening in your case.
And in fact,
gems/ai4r-1.9/lib/ai4r/classifiers/naive_bayes.rb
does actually use the rather rare construct ofArray.new(...)
.The value passed to Array.new() depends on what
Ai4r::Data::DataSet
returns from#build_domains.
I know this doesn't solve your problem but perhaps it will help you proceed further with your analysis.
我知道这个问题是一个较旧的问题,但我想指出一个更强大的用于朴素贝叶斯分类的 Ruby gem:
https: //github.com/oasic/nbayes
I know this question is an older one, but I wanted to point out a more robust Ruby gem for Naive Bayes classification:
https://github.com/oasic/nbayes