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

[BUG] ValueError (converting boolean variables to 0 and 1) #162

Open
ShayanDodge opened this issue Sep 24, 2024 · 0 comments
Open

[BUG] ValueError (converting boolean variables to 0 and 1) #162

ShayanDodge opened this issue Sep 24, 2024 · 0 comments

Comments

@ShayanDodge
Copy link

Thanks for helping us improve this project!

Before you create this issue
Please make sure you are using the latest updated code and libraries: see https://github.com/ageron/handson-ml3/blob/main/INSTALL.md#update-this-project-and-its-libraries

Also please make sure to read the FAQ (https://github.com/ageron/handson-ml3#faq) and search for existing issues (both open and closed), as your question may already have been answered: https://github.com/ageron/handson-ml3/issues

Describe the bug
In the code '15_processing_sequences_using_rnns_and_cnns', at the section 'Multivariate Time Series', the one-hot boolean variables should be converted to 0 and 1; otherwise, it will cause an error.

'ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type float).'

To Reproduce
Please copy the code that fails here, using code blocks like this:

df_mulvar = df[["bus", "rail"]] / 1e6  # use both bus & rail series as input
df_mulvar["next_day_type"] = df["day_type"].shift(-1)  # we know tomorrow's type
df_mulvar = pd.get_dummies(df_mulvar)  # one-hot encode the day type

And if you got an exception, please copy the full stacktrace here:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in inverse
ZeroDivisionError: division by zero

Expected behavior
We should add some lines of code to avoid of error.

df_mulvar = df[["bus", "rail"]] / 1e6  # use both bus & rail series as input
df_mulvar["next_day_type"] = df["day_type"].shift(-1)  # we know tomorrow's type
df_mulvar = pd.get_dummies(df_mulvar)  # one-hot encode the day type

 # Explicitly convert the last three columns to integers
 for col in df_mulvar.columns[-3:]:
     df_mulvar[col] = df_mulvar[col].astype(int)  # Convert each column to 0s and 1s

Screenshots
image

Versions (please complete the following information):

  • OS: Win 11
  • Python: 3.10.8
  • TensorFlow: 2.10.0
  • Scikit-Learn: [e.g., 0.24.1]
  • Other libraries that may be connected with the issue: [e.g., gym 0.18.0]

Additional context
Add any other context about the problem here.

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