sklearn usewarning / Process finished with exit code 245 (python)

1.第一个报错

报错信息

/home/disk1/lstm/venv/lib/python3.8/site-packages/sklearn/base.py:329: UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.24.2 when using version 0.23.2. This might lead to breaking code or invalid results. Use at your own risk.
warnings.warn(

Process finished with exit code 245

报错解释

在使用版本0.23.2时,尝试从版本0.24.2取消勾选estimator MinMaxScaler 。
这会导致代码中断或者结果无效。使用风险自负。
程序完成,退出代码245.

报错分析

这个报错是sklearn版本的问题。即模型训练时的sklearn版本 0.24.2 和模型调用时的sklearn版本0.23.2不匹配。
版本不对的时候也会报下面的错误:
AttributeError: ‘MinMaxScaler’ object has no attribute ‘clip’

解决方法

匹配训练、调用模型的sklearn版本。
要么把训练模型的sklearn版本将为0.23.2;要么把调用模型的sklearn版本升级为 0.24.2 。
我的解决方法是把调用模型的python工程sklearn环境升级版本,如下:
pip install scikit-learn==0.24.0
然后就不报use warning了,但是还有Process finished with exit code 245。

2.第二个报错

报错信息

/home/disk1/core/model.py:38: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify ‘dtype=object’ when creating the ndarray

Process finished with exit code 245

报错解释

可见的不推荐使用的警告:不推荐使用不规则(ragged)嵌套(nested)序列(即具有不同长度或形状的列表或列表元组、元组或数据数组)创建数据数组。如果要执行此操作,则必须在创建数据阵列时指定“dtype=object”。

报错分析

在使用不同长度或形状的序列创建数组,执行numpy.array(sequence)时,要对数据转为object格式,即改为:

numpy_s = numpy.array(sequence, dtype=object)

更改后,不再有warning。
但是245的代码退出还没解决。
最后245退出的问题解决方法:
在py文件中加入下面两句:

import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

STATUS 245: the specified policy is not of the correct client type
还是没解决,只维持了两天。
不知道是不是和内存有关系,是不是代码有需要优化得地方,运行一段时间内存满了所以退出?
打算用守护进程来变相解决这个问题了。
我觉得是内存泄漏的问题。因为我观察程序每次被调用,占用的内存就会增长,然后到达4-5GB就会以245退出。

3. IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

这是一个低级错误,原因是因为我使用了sklearn的from sklearn.preprocessing import MinMaxScaler,把数据归一化后,他输出的是array,不再是dataframe,所以后面我使用dataframe的一些属性方法就会报这个错误了。
solution:
通过df = pd.DataFrame(df)转一下。

猜你喜欢

转载自blog.csdn.net/weixin_46870583/article/details/121030476