ageron / ageron/handson-ml3

[BUG]: Chp2 - ValueError

Open
#53 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
14.1k
Forks
5.3k
PR merge metrics
No merged PRs in 30d

Description

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**

```python
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:

```stacktrace
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**
![Screenshot 2023-03-05 at 18 06 49](https://user-images.githubusercontent.com/72163077/222977973-889f1460-1157-4897-8bf8-e77987ff5509.png)
![Screenshot 2023-03-05 at 18 09 49](https://user-images.githubusercontent.com/72163077/222977977-f9bf81ab-3faa-4c86-a7ce-2c0de2fcfabd.png)

**Versions (please complete the following information):**
- OS: MacOSX 12.6
- Python: 3.10
- Scikit-Learn: 1.2.1

Thank you for your time

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.