Last active
February 8, 2022 05:33
-
-
Save sebadima/bddb150e111ff2cebf2a0626021729c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
from sklearn.datasets import make_blobs | |
from matplotlib import pyplot as plt | |
from sklearn.cluster import AffinityPropagation | |
from sklearn import metrics | |
# generazione dei dati casuali | |
X, y = make_blobs(n_samples=40, centers=4, cluster_std=0.80) | |
plt.scatter(X[:, 0], X[:, 1], cmap='Accent') | |
afprop = AffinityPropagation(preference=-50) | |
afprop.fit(X) | |
labels = afprop.predict(X) | |
plt.scatter(X[:, 0], X[:, 1], c=labels, s=40, cmap='Accent') | |
centro_cluster = afprop.cluster_centers_indices_ | |
numero_cluster = len(centro_cluster) | |
print('Numero di cluster: %d' % numero_cluster) | |
afprop.cluster_centers_ | |
print("Omogeneità: %0.4f" % metrics.homogeneity_score(y, labels)) | |
print("Completezza: %0.4f" % metrics.completeness_score(y, labels)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment