转自http://blog.sina.com.cn/s/blog_17b9e19320102x2w0.html


1.DecisionTree中,最后的预测:predictedY = clf.predict(oneRowX),运行时会出现报错:

python用sklearn分类版本和代码拼写问题

python用sklearn分类版本和代码拼写问题
上面提示说需要2维array,但是得到的是1维array
于是把predict一行改一下:predictedY = clf.predict([oneRowX]),然后程序就可以运行无误了。
为什么要是2维呢?因为python用sklearn分类版本和代码拼写问题


2.svm linear unseperable情况人脸识别中遇到的问题
(1)python用sklearn分类版本和代码拼写问题
运行时会出错:python用sklearn分类版本和代码拼写问题

上网搜方法:python用sklearn分类版本和代码拼写问题

更改后再运行,发现还有问题,继续上网搜,发现 还有地方没有更改:python用sklearn分类版本和代码拼写问题

更改了这两个地方就可以运行了。

(2)但是当输入:lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4)这个时,会出现需要下载文件的提示,这个时候按照提示下载labeled faces in the wild里面的图片文件就可以了


(3)当运行下面的语句时:
python用sklearn分类版本和代码拼写问题
会报错:python用sklearn分类版本和代码拼写问题
python用sklearn分类版本和代码拼写问题

上网上搜问题,解决方法如下

Warning 1:

源代码:

from sklearn.cross_validation import train_test_split
from sklearn.decomposition import RandomizedPCA
from sklearn.grid_search import GridSearchCV

警告信息:

python用sklearn分类版本和代码拼写问题
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)
python用sklearn分类版本和代码拼写问题

 

改正后代码:

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)

然后运行程序通过:)


相关文章:

  • 2021-06-21
  • 2021-07-09
  • 2021-10-06
  • 2022-12-23
  • 2021-07-10
  • 2021-11-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-07-07
  • 2021-10-12
  • 2021-04-06
相关资源
相似解决方案