<jupyter_start><jupyter_text>PCA Analysis- To Reduce the Dimensions- For Plotting- Encrypting the data  IRIS dataset<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
df=pd.read_csv("iris.csv")
df.tail()
len(df)
df.species.values
df["species"].value_counts()<jupyter_output><empty_output><jupyter_text>Visualization of the Dataset<jupyter_code>sns.pairplot(df);
sns.pairplot(df,hue="species",diag_kind="hist")<jupyter_output><empty_output><jupyter_text>Preparing Data for PCA Analysis<jupyter_code>X=df.iloc[:,:4]
X.head()
from sklearn.decomposition import PCA
bha=PCA(n_components=2)
bha1=bha.fit_transform(X)
bha1
bha2=pd.DataFrame(bha1,columns=["x1","x2"])
print(len(bha2))
bha2.head()
plt.figure(dpi=120)
sns.scatterplot(x=bha2.x1,y=bha2.x2)
plt.figure(dpi=120)
sns.scatterplot(x=bha2.x1,y=bha2.x2,hue=df.species)<jupyter_output><empty_output><jupyter_text>Clustering> Grouping- K Means Clustering<jupyter_code>from sklearn.cluster import KMeans
km = KMeans(n_clusters=3)
km.fit(X)
y_cluster_kmeans = km.predict(X)
y_cluster_kmeans
plt.figure(dpi=120)
sns.scatterplot(x=bha2.x1,y=bha2.x2,hue=y_cluster_kmeans,palette="copper")
plt.figure(dpi=120,figsize=(12,3))
plt.subplot(1,2,1)
sns.scatterplot(x=bha2.x1,y=bha2.x2,hue=df.species)
plt.title("Actual Species")
plt.subplot(1,2,2)
sns.scatterplot(x=bha2.x1,y=bha2.x2,hue=y_cluster_kmeans,palette="Accent")
plt.title("Predicted Species")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15508021390374332, 'fraction_numerical': 0.034759358288770054, 'mean_word_length': 10.171641791044776, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '559826', 'license': 'MIT', 'n_tokens_mistral': 716, 'n_tokens_neox': 679, 'n_words': 82, 'path': 'python/MachineLearning/Unsupervised .ipynb', 'repo_name': 'BharathC15/NielitChennai', 'size': '1496'}