Python提示AttributeError 或者DeprecationWarning: This module was deprecated解決方法


Python提示AttributeError 或者DeprecationWarning: This module was deprecated解決方法

在使用Python的sklearn庫時,發現sklearn的cross_validation不能使用,在pycharm上直接顯示為被橫線划掉。
運行程序:

import sklearn
...
X, Xt, y, yt = sklearn.cross_validation.train_test_split(X, y)

報錯:

AttributeError: 'module' object has no attribute 'cross_validation'

這里嘗試修改為:

from sklearn.cross_validation import train_test_split
X, Xt, y, yt = train_test_split(X, y)

發現不再報錯,而是提示警告信息:

**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) **
程序能夠正常執行。

但是注意看提示信息,實際上是說cross_validation模塊被棄用了,改為支持model_selection這個模塊,因此,將程序改為:

from sklearn.model_selection import train_test_split
X, Xt, y, yt = train_test_split(X, y)

不再出現警告信息,一切正常。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM