File:The effect of z-score normalization on k-means clustering.svg
Contents
This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.
Summary
| DescriptionThe effect of z-score normalization on k-means clustering.svg |
English: ```python
import matplotlib.pyplot as plt import numpy as np from sklearn.cluster import KMeans from sklearn.preprocessing import StandardScaler
n_samples = 300 cluster_std = 0.15
np.random.seed(0) cluster_centers_scales = (([-1, -1], 0.2), ([1, -1], 0.5), ([1.5, 1], 0.2), ([-0.5, 1], 0.5)) data = np.concatenate([ np.random.normal(loc=center, scale=scale, size=(n_samples, 2)) for center, scale in cluster_centers_scales ])
kmeans = KMeans(n_clusters=4, random_state=0)
data_stretched = data * np.array([1, 0.02])
labels_stretched = kmeans.fit_predict(data_stretched)
scaler = StandardScaler() data_normalized = scaler.fit_transform(data_stretched)
labels_normalized = kmeans.fit_predict(data_normalized)
plt.figure(figsize=(10, 5)) plt.subplot(1, 2, 1) plt.scatter(data_stretched[:, 0], data_stretched[:, 1], c=labels_stretched, marker='+') plt.title('Stretched Data') plt.subplot(1, 2, 2) plt.scatter(data_normalized[:, 0], data_normalized[:, 1], c=labels_normalized, marker='+') plt.title('Z-score Normalized Data') plt.savefig('z_score_normalization.svg') plt.show() ``` |
| Date | |
| Source | Own work |
| Author | Cosmia Nebula |
Licensing
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
This media file is uncategorized.
Please help improve this media file by adding it to one or more categories, so it may be associated with related media files (how?), and so that it can be more easily found.
Please notify the uploader with {{subst:Please link images|File:The effect of z-score normalization on k-means clustering.svg}} ~~~~ |
Captions
Items portrayed in this file
depicts
some value
6 August 2024
image/svg+xml
512,382 byte
be4d873841c7e16806618e5733b137a4cb1e7733
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | Thumbnail | Dimensions | User | Comment | |
|---|---|---|---|---|---|
| current | 07:20, 7 August 2024 | 960 × 480 (500 KB) | wikimediacommons>Cosmia Nebula | Uploaded while editing "Normalization (machine learning)" on en.wikipedia.org |
File usage
There are no pages that use this file.