文章目录
解决方案:1.问题描述:
F:\Anaconda3\python.exe D:/Workspaces/python/Naive_Bayes/News_NB.pyBuilding prefix dict from the default dictionary ...Dumping model to file cache C:\Users\ADMINI~1\AppData\Local\Temp\jieba.cacheLoading model cost 1.551 seconds.Prefix dict has been built successfully.Traceback (most recent call last):File "D:/Workspaces/python/Naive_Bayes/News_NB.py", line 169, in <module>test_accuracy = TextClassifier(train_feature_list, test_feature_list, train_class_list, test_class_list)File "D:/Workspaces/python/Naive_Bayes/News_NB.py", line 140, in TextClassifiertest_accuracy = classifier.score(test_feature_list, test_class_list)File "F:\Anaconda3\lib\site-packages\sklearn\base.py", line 309, in scorefrom .metrics import accuracy_scoreFile "F:\Anaconda3\lib\site-packages\sklearn\metrics\__init__.py", line 33, in <module>from . import clusterFile "F:\Anaconda3\lib\site-packages\sklearn\metrics\cluster\__init__.py", line 8, in <module>from .supervised import adjusted_mutual_info_scoreFile "F:\Anaconda3\lib\site-packages\sklearn\metrics\cluster\supervised.py", line 14, in <module>from scipy.misc import combImportError: cannot import name 'comb'Process finished with exit code 1
原因分析:根据提示:
from scipy.misc import comb ImportError: cannot import name ‘comb’
问题出在 scipy库上,本地查看一下这个库:
进入scipy文件夹
找到misc文件,进去看看有没有啥问题:
发现在 misc文件夹下根本没有comb。没有这个文件自然导入会出错。
下面,我们思考解决方法:
朴素的思想是:既然没有,我们就给他补上。或者重新安装scipy。
1.既然在misc文件夹下没有comb,我们就给它补上。我们就找找在其他地方有没有?
搜索文件:在F:\Anaconda3\Lib\site-packages\scipy\special目录下找到了comb.py
我们把comb.py复制到scipy\misc目录下,看看能不能用!?
把comb.py放进去
再次运行项目,看是否报错?
启动后还是报错,说明这个方案不可行,我们换下一个方案:
F:\Anaconda3\python.exe D:/Workspaces/python/Naive_Bayes/News_NB.pyBuilding prefix dict from the default dictionary ...Loading model from cache C:\Users\ADMINI~1\AppData\Local\Temp\jieba.cacheLoading model cost 1.716 seconds.Prefix dict has been built successfully.Traceback (most recent call last):File "D:/Workspaces/python/Naive_Bayes/News_NB.py", line 169, in <module>test_accuracy = TextClassifier(train_feature_list, test_feature_list, train_class_list, test_class_list)File "D:/Workspaces/python/Naive_Bayes/News_NB.py", line 140, in TextClassifiertest_accuracy = classifier.score(test_feature_list, test_class_list)File "F:\Anaconda3\lib\site-packages\sklearn\base.py", line 309, in scorefrom .metrics import accuracy_scoreFile "F:\Anaconda3\lib\site-packages\sklearn\metrics\__init__.py", line 33, in <module>from . import clusterFile "F:\Anaconda3\lib\site-packages\sklearn\metrics\cluster\__init__.py", line 8, in <module>from .supervised import adjusted_mutual_info_scoreFile "F:\Anaconda3\lib\site-packages\sklearn\metrics\cluster\supervised.py", line 13, in <module>from scipy.misc import combImportError: cannot import name 'comb'Process finished with exit code 1
解决方案:
换另一种方案。
之前我们看到comb.py文件是在\scipy\special文件夹下,所以我们尝试直接从这个文件夹下引用
修改程序代码中from scipy.misc import comb
为from scipy.special import comb
再次启动程序,问题解决!
F:\Anaconda3\python.exe D:/Workspaces/python/Naive_Bayes/News_NB.pyBuilding prefix dict from the default dictionary ...Loading model from cache C:\Users\ADMINI~1\AppData\Local\Temp\jieba.cacheLoading model cost 1.107 seconds.Prefix dict has been built successfully.0.42105263157894735Process finished with exit code 0
我详细的写了我从“遇到问题——分析问题——解决问题”的思路,如果帮到您了,为我来个“三连”吧——点赞+收藏+关注!祝好!