<jupyter_start><jupyter_text>**<NAME>**

**Sparks Foundation - Data Science & Analytics Internship!**
Task_2 - Prediction using Unsupervised ML<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.cluster import KMeans
from sklearn.preprocessing import LabelEncoder
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
from sklearn import datasets
from sklearn.metrics import classification_report,confusion_matrix,accuracy_score<jupyter_output><empty_output><jupyter_text>**Load the iris dataset**

```
PRINT FIRST 10 ROW
```<jupyter_code>df=pd.read_csv('Iris.csv')
df.head(10)
df.shape
df.info()
df.describe()
df.isnull().sum()
df["Species"].value_counts()
df['Species'].nunique()<jupyter_output><empty_output><jupyter_text>*Data* *Visualization* **Scatter plot**

SepalLengthCm vs SepalWidthCm<jupyter_code>df.plot(kind="scatter", x="SepalLengthCm", y="SepalWidthCm",color="purple")
o=sns.pairplot(df)
o.fig.set_size_inches(8,8)<jupyter_output><empty_output><jupyter_text>**Box plot**<jupyter_code># checking Outliers
for i in df1.describe().columns:
    sns.boxplot(df1[i])
    plt.show()
ax = sns.boxplot(x="Species", y="SepalWidthCm",data=df)
ax = sns.boxplot(x="Species", y="PetalWidthCm",data=df)
ax = sns.boxplot(x="Species", y="SepalLengthCm",data=df)<jupyter_output><empty_output><jupyter_text>**Scatter plot**<jupyter_code>fig,ax = plt.subplots(figsize=(8,6))
ax.scatter(df['SepalLengthCm'],df['SepalWidthCm'])            #Plotting the distribution of scores
plt.title('SepalLengthCm and SepalWidthCm') 
ax.set_ylabel('SepalLengthCm')
ax.set_xlabel('SepalWidthCm')
plt.show()
fig,ax = plt.subplots(figsize=(8,6))
ax.scatter(df['PetalLengthCm'],df['PetalWidthCm'])            #Plotting the distribution of scores
plt.title('PetalLengthCm and PetalWidthCm') 
ax.set_ylabel('PetalLengthCm')
ax.set_xlabel('PetalWidthCm')
plt.show()

sns.catplot(x='SepalLengthCm',y='SepalWidthCm',data=df,kind='boxen')
a=sns.pairplot(df,hue="Species")
a.fig.set_size_inches(8,8)
df.corr()<jupyter_output><empty_output><jupyter_text>**Heatmap**<jupyter_code>fig=plt.figure(figsize=(8,8))
sns.heatmap(df.corr(),linewidths=1,annot=True)<jupyter_output><empty_output><jupyter_text>**Jointplot**<jupyter_code>with sns.axes_style('white'):
    sns.jointplot("SepalLengthCm", "SepalWidthCm", df, kind='kde',color="#900C3F");


sns.jointplot(x="SepalLengthCm", y="SepalWidthCm", data=df,color="#357107")<jupyter_output><empty_output><jupyter_text>**Statistical estimation**<jupyter_code>sns.lmplot(data=df, x="SepalLengthCm", y="SepalWidthCm", col="Species", hue="Species")
df1=df

from pandas.plotting import andrews_curves
andrews_curves(df1.drop("Id", axis=1), "Species")
from pandas.plotting import parallel_coordinates
parallel_coordinates(df1.drop("Id", axis=1), "Species")<jupyter_output><empty_output><jupyter_text>**Elbow Method using within-cluster-sum-of-squares(wcss)**<jupyter_code>x = df.iloc[:, [0, 1, 2, 3]].values
from sklearn.cluster import KMeans
wcss = []

for i in range(1, 11):
    kmeans = KMeans(n_clusters = i, init = 'k-means++', 
                    max_iter = 300, n_init = 10, random_state = 0)
    kmeans.fit(x)
    wcss.append(kmeans.inertia_)
wcss<jupyter_output><empty_output><jupyter_text>**Elbow graph to find optimum no. of Clusters**<jupyter_code>plt.figure(figsize=(10,5))
sns.set(style='whitegrid')
sns.lineplot(range(1, 11), wcss,marker='o',color='red')
plt.title('The Elbow Method')
plt.xlabel('Number of clusters')
plt.ylabel('WCSS')
plt.show()<jupyter_output>/usr/local/lib/python3.6/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning<jupyter_text>**Initialization and fitting using K-means++**<jupyter_code># 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<jupyter_output><empty_output><jupyter_text>**Visualizing the Clusters**<jupyter_code># 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.title('Iris Flower Clusters')
plt.ylabel('Petal Width in cm')
plt.xlabel('Petal Length in cm')
plt.legend()<jupyter_output><empty_output><jupyter_text>**THANK YOU**

---<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15292062875994566, 'fraction_numerical': 0.01785367746943528, 'mean_word_length': 6.738738738738738, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '431389', 'license': 'MIT', 'n_tokens_mistral': 2096, 'n_tokens_neox': 1989, 'n_words': 351, 'path': 'Task_2_Prediction_using_Unsupervised_ML.ipynb', 'repo_name': 'thejaswin123/Task-2-Prediction-using-Unsupervised-ML', 'size': '5158'}