Arrays SKL中的弃用错误了解代码中没有任何空数组的空数组

Arrays SKL中的弃用错误了解代码中没有任何空数组的空数组,arrays,python-3.x,numpy,scikit-learn,Arrays,Python 3.x,Numpy,Scikit Learn,我只是在玩编码和解码的游戏,但我从sklearn得到了这个错误: 警告(来自警告模块): 文件“C:\Python36\lib\site packages\sklearn\preprocessing\label.py”,第151行 如果有差异: 弃用警告:空数组的真值不明确。返回False,但在将来这将导致错误。使用array.size>0检查数组是否为空 这是完整的代码,您可以自己在Python3中运行+ 我的问题是,为什么它说我使用空数组,因为我的代码中显然不使用空数组,感谢您花时间回答我的

我只是在玩编码和解码的游戏,但我从sklearn得到了这个错误:

警告(来自警告模块): 文件“C:\Python36\lib\site packages\sklearn\preprocessing\label.py”,第151行 如果有差异: 弃用警告:空数组的真值不明确。返回False,但在将来这将导致错误。使用
array.size>0
检查数组是否为空

这是完整的代码,您可以自己在Python3中运行+

我的问题是,为什么它说我使用空数组,因为我的代码中显然不使用空数组,感谢您花时间回答我的问题

### label encoding ###

import numpy as np
from sklearn import preprocessing

# Sample input labels
input_labels = ["red", "black", "red", "green",\
                "black", "yellow", "white"]

# Create label encoder abd fit the label
encoder = preprocessing.LabelEncoder()
encoder.fit(input_labels)

# Print the mapping
print("\nLabel mapping:")
for i, item in enumerate(encoder.classes_):
    print(item, "-->", i)

# Encode a set of labels using encoder
test_labels = ["green", "red", "black"]
encoded_values = encoder.transform(test_labels)
print("\nLabels =", test_labels)
print("Encoded values =", list(encoded_values))

# Decode a set of values using the encoder
encoded_values = [3, 0, 4, 1]
decoded_list = encoder.inverse_transform(encoded_values)
print("\nEncoded values =", encoded_values)
print("Decoded labels=", list(decoded_list))

TLDR:您可以忽略警告。这是因为sklearn在内部做了一些不太理想的事情


该警告实际上是由以下原因引起的
numpy

长话短说,在空数组上进行真实性测试是危险的、误导性的,而且在任何方面都没有用处,因此应该予以反对

这意味着不应该执行类似于
if-array:
的操作来检查
array
是否为空。但是,我们要学习:

因为你的numpy版本足够新,它会抱怨并发出警告


sklearn当前主分支中的问题,因此我希望该修复程序将包含在下一版本中。

更新numpy后,警告被清除:

conda update numpy

您也可以通过pip或其他方式进行更新。

您的sklearn版本是什么?我没有收到0.18.1(和numpy 1.13.3)上的警告。sklearn是0.19.1版,numpy是1.14.0版。您可以抑制此特定警告,如中的3个代码块中的第一个所示。
conda update numpy