本书使用的代码和数据均在GitHub上发布,地址
为:https://github.com/duoergun0729/1book
报错一
print distances
print indices
print nbrs.kneighbors_graph(X).toarray()
修改
print (distances)
print (indices)
print nbrs.kneighbors_graph(X).toarray()
报错二
Python3.8提示No module named ‘urlparse’
python3版本中已经将urlparse并入了urllib模块中
import urlparse
修改
from urllib.parse import urlparse
报错三
No module named ‘hmmlearn’
from hmmlearn import hmm
修改
1.Unofficial Windows Binaries for Python Extension Packages:https://www.lfd.uci.edu/~gohlke/pythonlibs/
下载与python版本相对应的whl文件
2.进入Anaconda prompt进行安装
pip install whl完整路径
pip install D:\software\Anaconda\hmmlearn-0.2.5-cp38-cp38-win_amd64.whl
报错四
cannot import name ‘joblib‘ from ‘sklearn.externals‘
因为joblib已经从sklearn中移除了
from sklearn.externals import joblib
修改
import joblib
报错五
ModuleNotFoundError: No module named ‘HTMLParser’
import HTMLParser
修改
from html.parser import HTMLParser
报错六
报错七
TypeError: ‘dict_keys’ object is not subscriptable
fdist = FreqDist(dist).keys()
dist_max=set(fdist[0:50])
dist_min = set(fdist[-50:])
fdist = FreqDist(cmd_block).keys()
f2=fdist[0:10]
f3=fdist[-10:]
修改
fdist = list(FreqDist(dist).keys())
dist_max=set(fdist[0:50])
dist_min = set(fdist[-50:])
fdist = list(FreqDist(cmd_block).keys())
f2=fdist[0:10]
f3=fdist[-10:]
第一行报错,第二行修改
#import urlparse
from urllib.parse import urlparse
#from sklearn.externals import joblib
import joblib
#import HTMLParser
from html.parser import HTMLParser
#fdist = FreqDist(dist).keys()
fdist = list(FreqDist(dist).keys())
#fdist = FreqDist(dist).keys()
fdist = list(FreqDist(dist).keys())
#fdist = FreqDist(cmd_block).keys()
fdist = list(FreqDist(cmd_block).keys())
#print "Dist:(%s)" % dist
print(dist)
#print score
#print classification_report(y_test, y_predict)
#print metrics.confusion_matrix(y_test, y_predict)
print(score)
print(classification_report(y_test, y_predict))
print(metrics.confusion_matrix(y_test, y_predict))
#from sklearn import cross_validation
from sklearn import model_selection
#print(cross_validation.cross_val_score(neigh, user_cmd_feature, y, n_jobs=-1,cv=10))
print(model_selection.cross_val_score(neigh, user_cmd_feature, y, n_jobs=-1,cv=10))
#from sklearn import cross_validation
from sklearn import model_selection
#print(cross_validation.cross_val_score(clf, x, y, n_jobs=-1, cv=10))
print(model_selection.cross_val_score(clf, x, y, n_jobs=-1, cv=10))
嗯?我没看懂!!!
D:\software\Anaconda\Anaconda3\lib\site-packages\sklearn\model_selection_split.py:666: UserWarning: The least populated class in y has only 2 members, which is less than n_splits=10.
warnings.warn((“The least populated class in y has only %d”
报错八
No module named ‘pydotplus’
import pydotplus
修改
进入Anaconda Prompt输入命令conda install pydotplus
认真是一种态度更是一种责任