+4 votes
in Programming Languages by (14.6k 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 (48.7k 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:


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


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