K means clustering on IRIS dataset on Sapel length and Sapel width
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
dataset = pd.read_csv("C://Users//DITU//Documents//Jupyter//iris_dataset.csv")
Here, I have taken Sepal Length and Sepal Width as X and Y attributes respectively.
X = dataset["sepal length (cm)"]
X
Y = dataset["sepal width (cm)"]
Y
dataset_new = list(zip(X,Y))
dataset_new
iris_model = KMeans(n_clusters = 4)
iris_model.fit(dataset_new)
plt.figure(figsize=(16,9))
plt.scatter(X,Y, c= iris_model.labels_, marker= "*", s = 300)
plt.xlabel("Iris Sepal Length", fontsize = 12)
plt.ylabel("Iris Sepal Width", fontsize = 12)
plt.title("K Means cluster", fontsize = 16)
plt.show()