我运行以下代码来编码和解码标签,而我的终端显示错误:
if diff:DeprecationWarning:空数组的真值不明确。返回False,但是将来会导致错误。使用array.size > 0
检查数组是否为空。
from sklearn import preprocessing as pp
import numpy as np
decode_values=['a','b','c','d','e','f','g']
encoder=pp.LabelEncoder()
encoder.fit(decode_values)
print(encoder.inverse_transform(np.array([0,1])))
我打开label.py并获取导致错误的代码:
def inverse_transform(self, y):
"""Transform labels back to original encoding.
Parameters
----------
y : numpy array of shape [n_samples]
Target values.
Returns
-------
y : numpy array of shape [n_samples]
"""
check_is_fitted(self, 'classes_')
diff = np.setdiff1d(y, np.arange(len(self.classes_)))
if diff:
raise ValueError("y contains new labels: %s" % str(diff))
y = np.asarray(y)
return self.classes_[y]
在我的情况下,变量“ diff”应该为空,但是机器无法理解“ if diff”。将其更改为“ if list(diff)”后,错误消失了。我检查了我的课本和其他视频,但未发生此错误。我为差异感到困惑。