carefree0910 / MachineLearning

Machine learning algorithms implemented by pure numpy

Home Page:https://mlblog.carefree0910.me

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

when use 'mushroom.txt', appear a TypeError

incipient1 opened this issue · comments

当我使用mushroom这个数据集的时候,出现了以下错误,但是使用balloon1.0、balloon1.5数据的时候一切正常,应该怎么做呢?
Traceback (most recent call last): File "E:\Python_learning\MachineLearning\b_NaiveBayes\MultinomialNB.py", line 70, in <module> nb.fit( _x, _y ) File "E:\Python_learning\MachineLearning\b_NaiveBayes\Basic.py", line 39, in fit self.feed_data(x, y, sample_weight) File "E:\Python_learning\MachineLearning\b_NaiveBayes\MultinomialNB.py", line 17, in feed_data cat_counter = np.bincount(y) TypeError: Cannot cast array data from dtype('float64') to dtype('int64') according to the rule 'safe' [Finished in 0.2s]

你好!由于没有上下文,所以我只能给出一个可能可行的解决方案:将你代码中的
nb.fit( _x, _y )
改成
nb.fit( _x, np.asarray(_y,np.int) )
我会暂时close掉这个issue;如果上述方法无法解决你的问题的话,欢迎随时再在这里讨论!