I have just followed this tutorial in order to try to understand PCA.
https://towardsdatascience.com/pca-using-python-scikit-learn-e653f8989e60
However I used a different dataset (Water potability).
ph Hardness Solids Chloramines Sulfate Conductivity Organic_carbon Trihalomethanes Turbidity Potability
0 NaN 204.890455 20791.318981 7.300212 368.516441 564.308654 10.379783 86.990970 2.963135 0
1 3.716080 129.422921 18630.057858 6.635246 NaN 592.885359 15.180013 56.329076 4.500656 0
2 8.099124 224.236259 19909.541732 9.275884 NaN 418.606213 16.868637 66.420093 3.055934 0
3 8.316766 214.373394 22018.417441 8.059332 356.886136 363.266516 18.436524 100.341674 4.628771 0
4 9.092223 181.101509 17978.986339 6.546600 310.135738 398.410813 11.558279 31.997993 4.075075 0
I normalized the data:
from sklearn.preprocessing import StandardScaler
features = ['ph', 'Hardness', 'Solids', 'Chloramines', 'Sulfate','Conductivity','Organic_carbon','Trihalomethanes','Turbidity']
# Separating out the features
x = df.loc[:, features].values
# Separating out the target
y = df.loc[:,['Potability']].values
# Standardizing the features
x = StandardScaler().fit_transform(x)
and then I did PCA:
import pandas as pd
from sklearn.decomposition import PCA
pca = PCA(n_components=2)
principalComponents = pca.fit_transform(x)
principalDf = pd.DataFrame(data = principalComponents, columns = ['principal component 1', 'principal component 2'])
principalDf.head(5)
When I tried to plot, I dont see a clear separation on the scatter plot
And then I checked the variance, it sums 50% only
pca.explained_variance_ratio_
array([0.25580228, 0.2538827 ])
THe question is:
What does this means? I mean its not closed to 90%, so it means features are not correlated at all to the target potability field?
What could you conclude from the plot here?
Or maybe I used PCA incorrectly