ValueError: Unknown label type, but I run it well in my terminal

I believe my code is good, since it runs smoothly in the terminal. Thus, I am confused. How can I try to solve this problem? Thanks for any insight.

I believe my code is good

Then maybe your data is bad.

How can I try to solve this problem? Thanks for any insight.

Make sure X_train_t and Y_train conform to the expectations of selector.fit_transform.

Hey @Qin_Li,

Please share a code snippet and link to your GitHub repo so we can try to reproduce the error

1 Like

Thank you guys for your helps so far. I got some insights and trying to work on that.
Here is my Github page.

The file named as is the original file that I typically put into the terminal to generate how the streamlit work looks like eventually.
Thank you so much guys for your any help!!

Thank you for replying to me and your insights!! I run this line of code from my side, it doesn’t show any error so far, but you did notify me someplace I need to double check!!

I ran your script in a standard python interpreter and got the same error. I don’t now what the root cause is yet, but I bet you have an old version of scikit-learn or some other library in your local environment.

This is due to a a change in pandas. You have this in your code

df_all.iloc[:, -1] = Y

Where df_all.iloc[:, -1].dtype is object and Y.dtype is int64.

  • In pandas 1.3.5 this changes both the values and the type of the column.
  • In pandas 2.0.1 only the values change, but the type remains the same (at least in this case where the types are compatible) and sklearn gets mad when passed this data.

The behavior changed at some point between 1.3.5 and 2.0.1. To make it work in both versions do this instead:

df_all["RiskPerformance"] = Y
1 Like

Thank you so much Goyo. I cannot express my appreciation more. It works. The value error disappers. Thank you so so much. Let me know if I can do anything else to help enlarge your reputation hahaha! Have a great day!!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.