Sklearn obsolescence error about empty array without any empty array in my code

I just play around encoding and decoding, but get this error from sklearn:

Warning (from the warning module): File "C: \ Python36 \ lib \ site-packages \ sklearn \ preprocessing \ label.py", line 151 if diff: DeprecationWarning: the true value for an empty array is ambiguous. Return False, but in the future this will result in an error. Use array.size > 0to verify that the array is not empty.

Here is the complete code, you can run it yourself in python 3+

My question is why I am saying that I am using an empty array, since I obviously do not do this in my code, thanks for taking the time to answer my question.

### 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))
+4
1

TL;DR: . , sklearn - , .


numpy, :

- , , , .

, - if array:, , array . sklearn 0.19.1:

    diff = np.setdiff1d(y, np.arange(len(self.classes_)))
    if diff:
        raise ValueError("y contains new labels: %s" % str(diff))

numpy , .

​​ sklearn, , .

+8

Source: https://habr.com/ru/post/1693372/


All Articles