ageron / ageron/handson-ml2

Chapter 9 notebook minor issues

Open
#312 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Jupyter Notebook
Stars
30k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

Hi,

It seems that there are somes issues or differences with my execution of the chapter 9 handbook.

My configuration :
```
print(sys.version_info)
print(sklearn.__version__)
print(np.__version__)
print(mpl.__version__)
```
> sys.version_info(major=3, minor=8, micro=5, releaselevel='final', serial=0)
> 0.23.2
> 1.19.2
> 3.3.2
>

**9.1 : Iris classification and GaussianMixture**

It seems that the mapping of the prediction has changed in the GaussianMixture class in the sklearn version I use. Here is the code that works in my case :
```
y_pred = GaussianMixture(n_components=3, random_state=42).fit(X).predict(X)
mapping = np.array([1, 2, 0])
y_pred = np.array([mapping[cluster_id] for cluster_id in y_pred])
```

**9.1.1 : plot_centroid function**

The size of the cross is not correct in the handbook : it creates this (i used a different random_state for input data) :
![image](https://user-images.githubusercontent.com/73541689/98441387-351ff180-20fe-11eb-8e55-4c2f0a433b11.png)
instead of this :
![image](https://user-images.githubusercontent.com/73541689/98441423-70babb80-20fe-11eb-8951-6cd911903942.png)
This image was generated with the following code :
```
def plot_centroids(centroids, weights=None, circle_color='w', cross_color='k'):
if weights is not None:
centroids = centroids[weights > weights.max() / 10]
plt.scatter(centroids[:, 0], centroids[:, 1],
marker='o', s=50, linewidths=8,
color=circle_color, zorder=10, alpha=0.9)
plt.scatter(centroids[:, 0], centroids[:, 1],
marker='x', s=50, linewidths=2,
color=cross_color, zorder=11, alpha=1)
```

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.