import pandas as pd
from sklearn.datasets import load_iris
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
import seaborn as sns
import matplotlib.pyplot as plt
df=pd.read_csv("iris.csv")
print(df.head())
print(df.isnull().sum())
#df.fillna(df.mean(),inplace=True)
df_encoded=pd.get_dummies(df,columns=['Species'],drop_first=True)
print(df_encoded.head())
x=df_encoded
x_scaled=StandardScaler().fit_transform(x)
pca=PCA(n_components=2)
x_pca=pca.fit_transform(x_scaled)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter