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?


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'))
| improve this answer | |
  • $\begingroup$ Thanks for sharing this. $\endgroup$ – AjayMurala Jun 26 '19 at 9:41
  • $\begingroup$ I have encoded the "Loan_Status" before training the data to model and this also resolved the error $\endgroup$ – AjayMurala Jun 26 '19 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.