Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

y contains previously unseen labels #7

Open
pokekarat opened this issue Apr 16, 2020 · 0 comments
Open

y contains previously unseen labels #7

pokekarat opened this issue Apr 16, 2020 · 0 comments

Comments

@pokekarat
Copy link

After executing this command "sh run.sh randomforest", I got the following error messages.

Traceback (most recent call last):
File "/opt/anaconda3/envs/kaggle/lib/python3.8/runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/opt/anaconda3/envs/kaggle/lib/python3.8/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/Users/ekaratrattagan/Program/Course/machine_learning/kaggle/e01/src/train.py", line 45, in
train_df.loc[:, c] = lbl.transform(train_df[c].values.tolist())
File "/opt/anaconda3/envs/kaggle/lib/python3.8/site-packages/sklearn/preprocessing/_label.py", line 273, in transform
_, y = encode(y, uniques=self.classes, encode=True)
File "/opt/anaconda3/envs/kaggle/lib/python3.8/site-packages/sklearn/preprocessing/_label.py", line 117, in _encode
return _encode_numpy(values, uniques, encode,
File "/opt/anaconda3/envs/kaggle/lib/python3.8/site-packages/sklearn/preprocessing/_label.py", line 49, in _encode_numpy
raise ValueError("y contains previously unseen labels: %s"
ValueError: y contains previously unseen labels: [nan, nan, nan, nan, nan, nan, nan, nan, ....

I then fixed it by adding the following two lines,
train_df[c].replace(np.nan, 'NAN', inplace=True)
valid_df[c].replace(np.nan, 'NAN', inplace=True)

,after for c in train_df.columns: and before lbl = preprocessing.LabelEncoder()
in train.py

label_encoders = {}
for c in train_df.columns:
train_df[c].replace(np.nan, 'NAN', inplace=True)
valid_df[c].replace(np.nan, 'NAN', inplace=True)

lbl = preprocessing.LabelEncoder()

After that, it worked perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant