When I use the following code to calculate precision_recall_fscore_support
for one-class ( only the 1
s)
import numpy as np
from sklearn.metrics import precision_recall_fscore_support
#make arrays
ytrue = np.array(['1', '1', '1', '1', '1','1','1','1'])
ypred = np.array(['0', '0', '0', '1', '1','1','1','1'])
#keep only 1
y_true, y_pred = zip(*[[ytrue[i], ypred[i]] for i in range(len(ytrue)) if ytrue[i]=="1"])
#get scores
precision_recall_fscore_support(y_true, y_pred, average='weighted')
I get the following Warning:
UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples.
'recall', 'true', average, warn_for)
and output:
(1.0, 0.625, 0.76923076923076927, None)
I found the following on SO UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples that has similar warning but I don't think it applies to my problem.
Question: Are the results of my output valid or should I be concerned about the warning message? If so, what is wrong with my code and how to fix?