TransWikia.com

ValueError: pos_label=1 is not a valid label: array(['N', 'Y'], dtype='<U1')

Data Science Asked by AjayMurala on June 12, 2021

X = train_encoded_df.iloc[:, 1: ]
y = train_encoded_df["Loan_Status"]

print("Precision:",metrics.precision_score(y_test, y_pred))

My training data contains the categorical features encoded using get_dummies().

This is causing the error:

> ValueError: pos_label=1 is not a valid label: array(['N', 'Y'], dtype='U1')

How to fix this?

One Answer

pos_label is an argument of scikit-learn's precision_score (docs); its purpose is, well, to indicate which label is the positive one and, if not given explicitly (like in your case here), it assumes the default value of 1 (again, check the docs).

Since it seems that the positive label in your case is 'Y', replace the last line with:

print("Precision:",metrics.precision_score(y_test, y_pred, pos_label='Y'))

Correct answer by desertnaut on June 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP