handson-ml3
handson-ml3 copied to clipboard
[BUG]: Chp2 - ValueError
Hi Aurélien,
Describe the bug
Chapter 2, page 75.
When I run a piece of code word for word from the book, I obtain an error.
The code
df_output = pd.DataFrame(cat_encoder.transform(df_test_unknown),
columns=cat_encoder.get_feature_names_out(),
index=df_test_unknown.index)
And if you got an exception, please copy the full stacktrace here:
Output exceeds the size limit. Open the full output data in a text editor
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[183], line 1
----> 1 df_output = pd.DataFrame(cat_encoder.transform(df_test_unknown),
2 columns=cat_encoder.get_feature_names_out(),
3 index=df_test_unknown.index)
File [~/ml/studysession/lib/python3.10/site-packages/pandas/core/frame.py:762](https://file+.vscode-resource.vscode-cdn.net/Users/[user]/ml/~/ml/studysession/lib/python3.10/site-packages/pandas/core/frame.py:762), in DataFrame.__init__(self, data, index, columns, dtype, copy)
754 mgr = arrays_to_mgr(
755 arrays,
756 columns,
(...)
759 typ=manager,
760 )
761 else:
--> 762 mgr = ndarray_to_mgr(
763 data,
764 index,
765 columns,
766 dtype=dtype,
767 copy=copy,
768 typ=manager,
769 )
770 else:
771 mgr = dict_to_mgr(
...
418 passed = values.shape
419 implied = (len(index), len(columns))
--> 420 raise ValueError(f"Shape of passed values is {passed}, indices imply {implied}")
ValueError: Shape of passed values is (2, 1), indices imply (2, 5)
Expected behavior
I am supposed to receive a DataFrame
Screenshots
Versions (please complete the following information):
- OS: MacOSX 12.6
- Python: 3.10
- Scikit-Learn: 1.2.1
Thank you for your time