K Means Algorithm
K Means Algorithm
Prgm By ROHAN
GA
In [1]: import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
In [23]: df=pd.read_csv("IRIS.csv")
df.head(10)
In [3]: df.info()
<class 'pandas.core.frame.DataFr
ame'>
RangeIndex: 150 entries, 0 to 14
9
Data columns (total 5 columns):
# Column Non-Null Coun
t Dtype
--- ------ -------------
- -----
0 sepal_length 150 non-null
float64
1 sepal_width 150 non-null
float64
2 petal_length 150 non-null
float64
3 petal_width 150 non-null
float64
4 species 150 non-null
object
dtypes: float64(4), object(1)
memory usage: 6.0+ KB
In [4]: df.shape
Out[4]: (150, 5)
In [30]: df.describe()
In [5]: df.columns
In [ ]:
In [6]: x=df.iloc[:,[0,1,2,3]].values
In [ ]:
In [ ]:
In [25]: plt.scatter(x[y_kmeans==0,0],x[y_
s=100,c='red',label='
plt.scatter(x[y_kmeans==1,0],x[y_
s=100,c='blue',label=
plt.scatter(x[y_kmeans==2,0],x[y_
s=100,c='yellow',labe
plt.scatter(kmeans.cluster_cente
s=100,c='yellow',labe
plt.legend()
In [ ]:
In [ ]: