+4 votes
in Programming Languages by (37.5k points)

In the following code, I am extracting labels from the data and checking whether labels are numerical or not. But the code is throwing an error: "TypeError: not all arguments converted during string formatting".

It seems that it did not like logging.info() code; what is wrong with the logging.info() code?

y = data[data.columns[self.label_pos]].to_numpy()

labels = np.unique(y)

if not isinstance(labels[0], int):  # if one label is char, array will convert all labels to char

    logging.info("Label is not numeric", labels)

    for i in range(len(labels)):

        y[y == labels[i]] = i

return y

1 Answer

+1 vote
by (233k points)

Your logging.info() code is wrong. If you want to display labels, you can use format().

Make the following change in your code and it should work:

From

logging.info("Label is not numeric", labels)

to

logging.info("labels are not numeric: {0}".format(labels))


...