python-3.x/ scikit-learn

For the below line of code to get the metrics, I'm getting the ValueError mentioned

f1_test.append(f1_score(y_test, y_pred_test, pos_label="str"))

ValueError: pos_label='str' is not a valid label: array([' <=50K', ' >50K'], dtype='

My data has Income vlaue <=50k or >50k.

Please advise.

The parameter pos_label is used to indicate the positive class. In your data, your labels are string based '<=50K' and '>50K'.

You can do one of the following:

  1. Leave pos_label to the default value, set pos_label = 1.
  2. Set pos_label = '>50K' or '<=50K', based on what your +ve class. The positive class is normally attributed to the best outcome, for example, the income that you are trying to predict, is it better if its more than 50K or less than <=50K?

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question f1_score : ValueError all the input arrays must have same number of dimensions lightgbm Manual scoring function : F1_SCORE How to use f1 score metrics from sklearn using libact? TypeError: f1_score() got an unexpected keyword argument 'average' f1_score() takes 2 positional arguments but 3 positional arguments (and 1 keyword-only argument) were given F1 score values different for F1 score metric and classification report sklearn How to calculate Precision,Recall and F1 score using sklearn tf.contrib.metrics.f1_score can not be imported How to find the error rate when sklearn's roc_auc_score is used as metrics? Cross Validation for Different Metrics - Sklearn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM