ageron / ageron/handson-ml2

Chapter 2 Analyze the Best Models and Their Errors

Đang mở
#247 3 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Jupyter Notebook
Star
30k
Fork
13.1k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

To analyze the relative importance of each attribute for making accurate predictions, the book use the next code (with its output):

```pycon
>>> feature_importances = grid_search.best_estimator_.feature_importances_
>>> feature_importances
array([7.33442355e-02, 6.29090705e-02, 4.11437985e-02, 1.46726854e-02,
1.41064835e-02, 1.48742809e-02, 1.42575993e-02, 3.66158981e-01,
5.64191792e-02, 1.08792957e-01, 5.33510773e-02, 1.03114883e-02,
1.64780994e-01, 6.02803867e-05, 1.96041560e-03, 2.85647464e-03])
```

And to add their corresponding attribute names:

```pycon
>>> extra_attribs = ["rooms_per_hhold", "pop_per_hhold", "bedrooms_per_room"]
>>> cat_encoder = full_pipeline.named_transformers_["cat"]
>>> cat_one_hot_attribs = list(cat_encoder.categories_[0])_

>>> attributes = num_attribs + extra_attribs + cat_one_hot_attribs
>>> sorted(zip(feature_importances, attributes), reverse=True)
[(0.3661589806181342, 'median_income'),
(0.1647809935615905, 'INLAND'),
(0.10879295677551573, 'pop_per_hhold'),
(0.07334423551601242, 'longitude'),
(0.0629090704826203, 'latitude'),
(0.05641917918195401, 'rooms_per_hhold'),
(0.05335107734767581, 'bedrooms_per_room'),
(0.041143798478729635, 'housing_median_age'),
(0.014874280890402767, 'population'),
(0.014672685420543237, 'total_rooms'),
(0.014257599323407807, 'households'),
(0.014106483453584102, 'total_bedrooms'),
(0.010311488326303787, '<1H OCEAN'),
(0.002856474637320158, 'NEAR OCEAN'),
(0.00196041559947807, 'NEAR BAY'),
(6.028038672736599e-05, 'ISLAND')]
```

My question is: Why do I have to add `extra_attribs`? or How do I know that I must add this attributes?

I add the output without add `extra_attribs`

```pycon
>>> feature_importances=grid_search.best_estimator_.feature_importances_

>>> #extra_attribs = ["rooms_per_hhold", "pop_per_hhold", "bedrooms_per_room"]
>>> cat_encoder = full_pipeline.named_transformers_["cat"]
>>> cat_one_hot_attribs = list(cat_encoder.categories_[0])

>>> attributes = num_attribs + cat_one_hot_attribs #+ extra_attribs
>>> sorted(zip(feature_importances, attributes), reverse=True)

[(0.303268232301214, 'median_income'),
(0.1730639450304893, 'NEAR OCEAN'),
(0.10895862174634888, 'INLAND'),
(0.0844196144263057, 'ISLAND'),
(0.07557206707255014, 'longitude'),
(0.06398786252477989, 'latitude'),
(0.06315655490931624, '<1H OCEAN'),
(0.04240720593117474, 'housing_median_age'),
(0.01829282732311651, 'total_rooms'),
(0.017560189966804522, 'population'),
(0.01689244166020893, 'total_bedrooms'),
(0.01668817806453196, 'households'),
(0.008535150622100876, 'NEAR BAY')]
```

How do I know that is wrong? Because without `extra_attribs` I can not say _apparently only one `ocean_proximity` category is really useful, so you could try dropping the others_

Thanks for your time.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.