ageron / ageron/handson-ml

Chapter 2 (page90), full_pipeline.transform()

未關閉
#637 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Jupyter Notebook
星號
25.6k
分支
12.7k
PR 合併指標
PR 指標待擷取

描述

Hi Aurélien,

Thank you for a GREAT book! I really enjoy reading it and practicing the examples in the book.
In chapter 2, when we need to transform the test data, you mention that not using the `fit_transform()` as we don't want to fit the test data, and we should use the `transform()` function. But the SimpleImputer needs to run the `fit()` first before running the `transform()`. Can you please illustrate a solution for that? Thank you!!

Lu

**Code**:

```python
num_pipeline = Pipeline([
('imputer', SimpleImputer(strategy = 'median')),
('std_scaler', StandardScaler()),
])

#
num_attr = list(test_num)
cat_attr = ['ocean_proximity']
full_pipeline = ColumnTransformer([
("num", num_pipeline, num_attr),
("cat", OneHotEncoder(), cat_attr),
])
test_x_tr = full_pipeline.transform(test_x)
test_x_tr
```

**Error**:

```stacktrace
NotFittedError: This ColumnTransformer instance is not fitted yet. Call 'fit' with
appropriate arguments before using this estimator.
```

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。