<jupyter_start><jupyter_text>Data Science and Business Analytics Internship-Dec20 GRIP @ The Sparks Foundation K- Means Clustering Task-2 : Prediction Iris Data Using Unsupervised Machine Learning Author: <NAME> Batch: December-2020<jupyter_code># Import Neccessary Dependancy 
import pandas as pd
import numpy as np
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
import seaborn as sns
# Import Dataset from Sklearn
from sklearn import datasets
# Load iris Dataset
dataset = datasets.load_iris()
# to view Feature Name
dataset.feature_names
# to view iris Data
dataset.data
# To Find the Shape of Data 
dataset.shape
# Create dataframe to include the data and feature name
dataset = pd.DataFrame(dataset.data, columns = dataset.feature_names )
# to show top five Row
dataset.head()
# To Describe Dataset
dataset.describe()
# To see the informaton of dataset
dataset.info()
# To check duplicates Data
dataset.duplicated()
# To see number of Duplicates data
dataset.duplicated().sum()
# TO Drop Duplicates Data 
dataset.drop_duplicates(inplace=True)
# Again to see is there have any duplicates data
dataset.duplicated().sum()
# To Count the sepal length (cm) value
sns.countplot(dataset.iloc[:,0])
# To Count the sepal width (cm) value
sns.countplot(dataset.iloc[:,1])
# To Count the petal length (cm) value
sns.countplot(dataset.iloc[:,2])
# To Count the petal width (cm) value
sns.countplot(dataset.iloc[:,3])
# To see the pair of All features values
sns.pairplot(dataset)
# To Finding the optimum number of clusters for k-means classification Algorithm
X = dataset.iloc[:,0:].values

DataList = []

for i in range(1, 15):
    kmeans = KMeans(n_clusters = i, init = 'k-means++', max_iter = 300, n_init = 10, random_state = 0)
    kmeans.fit(X)
    DataList.append(kmeans.inertia_)
# Plotting the results onto a line graph 
plt.plot([1,2,3,4,5,6,7,8,9,10,11,12,13,14], DataList)
plt.title('Clustering method')
plt.xlabel('Number of clusters')
plt.ylabel('Within cluster sum of squares')
plt.show()
# Applying kmeans to the dataset / Creating the kmeans classifier
Kmeans = KMeans(n_clusters = 3, init = 'k-means++',max_iter = 300, n_init = 10, random_state = 0)
y_kmeans = Kmeans.fit_predict(X)
y_kmeans
# To Visualising the clusters On the first two columns
plt.scatter(X[y_kmeans == 0, 0], X[y_kmeans == 0, 1], s = 100, c = 'red', label = 'Iris-setosa')
plt.scatter(X[y_kmeans == 1, 0], X[y_kmeans == 1, 1], s = 100, c = 'blue', label = 'Iris-versicolour')
plt.scatter(X[y_kmeans == 2, 0], X[y_kmeans == 2, 1], s = 100, c = 'green', label = 'Iris-virginica')

# Plotting the centroids of the clusters
plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:,1], s = 100, c = 'yellow', label = 'Centroids')
plt.legend(loc='best')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12038695807954139, 'fraction_numerical': 0.026155499820852742, 'mean_word_length': 5.204444444444444, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '283896', 'license': 'MIT', 'n_tokens_mistral': 1046, 'n_tokens_neox': 952, 'n_words': 311, 'path': 'Task2 - Prediction Iris Data Using Unsupervised Machine Learning.ipynb', 'repo_name': 'AbuBakkar32/Data-Science-Internship', 'size': '2803'}