May I know how to modify my Python programming thus I will be able to obtain the same result as refer to the image file?
import numpy as np import pandas as pd df_wine = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data', header=None) np.random.seed(0) from sklearn.cross_validation import train_test_split from sklearn.preprocessing import StandardScaler X, y = df_wine.iloc[:, 1:].values, df_wine.iloc[:, 0].values X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0) sc = StandardScaler() X_train_std = sc.fit_transform(X_train) X_test_std = sc.transform(X_test) cov_mat = np.cov(X_train_std.T) eigen_vals, eigen_vecs = np.linalg.eig(cov_mat) print('\nEigenvalues \n%s' % eigen_vals) tot = sum(eigen_vals) var_exp = [(i / tot) for i in sorted(eigen_vals, reverse=True)] cum_var_exp = np.cumsum(var_exp) import matplotlib.pyplot as plt plt.bar(range(1,14), var_exp, alpha=0.5, align='center', label='individual explained variance') plt.step(range(1,14), cum_var_exp, where='mid', label='cumulative explained variance') plt.ylabel('Explained variance ratio') plt.xlabel('Principal components') plt.legend(loc='best') plt.show()
Please refer to the image file -
![[Image: GavCD.jpg]](https://i.stack.imgur.com/GavCD.jpg)
Please help me on this case
Attached Files