ML 2.3 Prashant
ML 2.3 Prashant
Worksheet 2.3
iris.head()
sepal_length
sepal_width petal_length petal_width species
sepal_length
sepal_width petal_length petal_width species
print('Centroids :',centers)
print('\nLabels :',new_labels)
//Output:
Centroids : [[5.77358491 2.69245283]
[6.81276596 3.07446809]
[5.006 3.428 ]]
Labels : [2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2
2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 0 1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 0 1 1 1 1
1 1 0 0 1 1 1 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0 0 1 1 1 0 1 1 1 0 1 1 1 0 1
1 0]
Text(0.5,
1.0,
'Unclustered
Data')
plt.figure(figsize=(8,6))
plt.scatter(X[:, 0], X[:, 1], c=new_labels,s=60) plt.scatter(centers[:, 0],
centers[:, 1], c='r', s=400, marker = '*', zorder=10);
plt.xlabel('Sepal length', fontsize=18) plt.ylabel('Sepal width', fontsize=18)
plt.title('Clustered Data',fontsize=18)
Text(0.5,
1.0, 'Clustered Data')
Output:
Result : virginica