bayes_motelgemを使用していくつかのデータを分析しようとしています。私のバージョンのルビーと宝石のハッシュの作成の間には互換性がないと思います:
ruby-1.9.3-p0/gems/bayes_motel-0.1.0/lib/bayes_motel/corpus.rb:89:in `[]=': can't add a new key into hash during iteration (RuntimeError)
これはgemの関連コードです:
def clean(hash, k, v)
case v
when Hash
v.each_pair do |key, value|
clean(v, key, value)
end
if v.empty?
hash.delete(k)
elsif v.size == 1 and v['other']
hash.delete(k)
end
else
if v < (@total_count * 0.03).floor
hash['other'] ||= 0
hash['other'] += v
hash.delete(k)
end
end
end
私はこのチュートリアルに従っています:
http://www.mikeperham.com/2010/04/28/bayes_motel-bayesian-classification-for-ruby/
そして宝石のデモ: