我一直这样:
DeprecationWarning: integer argument expected, got float
Run Code Online (Sandbox Code Playgroud)
如何让这条消息消失?有没有办法避免Python中的警告?
当参数n_jobs 设置为 -1时,如何从命令行使用 sklearn 的GridsearchCV()运行脚本而不打印所有警告?使用 warnings.simplefilter('ignore') 它不起作用。
当 n_jobs = 1 时,它工作正常并且不会打印任何警告
当我从spyder运行脚本时,即使n_jobs = -1,它也能正常工作
我尝试了这里描述的多种方法消除来自 scikit-learn 的警告,但是当从命令行和 Gridsearch 运行 n_jobs = -1 的脚本时,它们都不起作用
我还尝试将 with 语句放在忽略之后的警告if __name__ == '__main__'
声明,但这也不起作用
我有 scikit-learn 0.21.3。
这是一个可重现的小示例,它多次打印来自 IsolationForest 的 FutureWarning 和 DepreciationWarning。
from sklearn import datasets
from sklearn.cluster import KMeans
from sklearn.pipeline import Pipeline
from sklearn.model_selection import GridSearchCV
from sklearn.preprocessing import StandardScaler, MinMaxScaler
from sklearn.ensemble import IsolationForest
import warnings
import numpy as np
from sklearn.base import …Run Code Online (Sandbox Code Playgroud) 我相信这个问题已经被提出很多次了,但我有一个特定的用例,我无法用网络上描述的许多方法解决这个问题。
在我的一个项目中,我正在使用joblib库,它显示是DeprecationWarning因为它在imp内部某处使用了库:
from sklearn.externals.joblib import Parallel, delayed
def main():
xs = Parallel()(delayed(lambda x: x**2)(i) for i in range(1, 6))
print(sum(xs))
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
我试图用解释器选项过滤掉警告,-W但它没有帮助:
$ python -W ignore example.py
[...]/lib/python3.7/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py:47:
DeprecationWarning: the imp module is deprecated in favour of importlib;
see the module's documentation for alternative uses import imp
55
Run Code Online (Sandbox Code Playgroud)
另外,我正在尝试使用warnings模块进行显式过滤,但它也无济于事:
import warnings
warnings.simplefilter('ignore', category=DeprecationWarning)
from sklearn.externals.joblib import Parallel, delayed
def main():
xs = Parallel()(delayed(lambda x: x**2)(i) for …Run Code Online (Sandbox Code Playgroud) 我该如何处理这个警告?
Warning (from warnings module):
File "C:\Users\SAMSUNG\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\linear_model\_logistic.py", line 762
extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)
ConvergenceWarning: lbfgs failed to converge (status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
Increase the number of iterations (max_iter) or scale the data as shown in:
https://scikit-learn.org/stable/modules/preprocessing.html
Please also refer to the documentation for alternative solver options:
https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
Run Code Online (Sandbox Code Playgroud)
urls_data = pd.read_csv("data.csv")
TEST_SIZE = 0.001
type(urls_data)
urls_data.head()
def makeTokens(f):
tkns_BySlash = str(f.encode('utf-8')).split('/')
total_Tokens = []
for i in tkns_BySlash :
tokens = str(i).split('-')
tkns_ByDot = []
for j in range(0, len(tokens)): …Run Code Online (Sandbox Code Playgroud)