转自http://blog.sina.com.cn/s/blog_17b9e19320102x2w0.html
1.DecisionTree中,最后的预测:predictedY = clf.predict(oneRowX),运行时会出现报错:
于是把predict一行改一下:predictedY = clf.predict([oneRowX]),然后程序就可以运行无误了。
2.svm linear unseperable情况人脸识别中遇到的问题
上网搜方法:
(2)但是当输入:lfw_people = fetch_lfw_people(min_faces_per_person=70,
resize=0.4)这个时,会出现需要下载文件的提示,这个时候按照提示下载labeled
faces in the wild里面的图片文件就可以了
(3)当运行下面的语句时:
Warning 1:
源代码:
from sklearn.cross_validation import train_test_split from sklearn.decomposition import RandomizedPCA from sklearn.grid_search import GridSearchCV
警告信息:
D:\python35\lib\site-packages\sklearn\cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20. "This module will be removed in 0.20.", DeprecationWarning) D:\python35\lib\site-packages\sklearn\grid_search.py:43: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. This module will be removed in 0.20. DeprecationWarning) D:\python35\lib\site-packages\sklearn\utils\deprecation.py:52: DeprecationWarning: Class RandomizedPCA is deprecated; RandomizedPCA was deprecated in 0.18 and will be removed in 0.20. Use PCA(svd_solver='randomized') instead. The new implementation DOES NOT store whiten ``components_``. Apply transform to get them. warnings.warn(msg, category=DeprecationWarning)
改正后代码:
from sklearn.model_selection import train_test_split from sklearn.decomposition import PCA from sklearn.model_selection import GridSearchCV
也就是说首先b a程序的最前面from sklearn.decomposition import RandomizedPCA修改为 import PCA
然后将出错的那个程序句子改为:pca = PCA(svd_solver='randomized', n_components = n_components, whiten =True).fit(X_train)
然后运行程序通过:)