-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (24 loc) · 992 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import tableOCR
from sklearn.decomposition import PCA
from sklearn import preprocessing
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
vars, labels, observations = tableOCR.ocrTable('./testtable.png')
dataframe = pd.DataFrame(columns=vars, index=labels, data=observations)
scaled_data = preprocessing.scale(dataframe)
pca = PCA().fit(scaled_data)
per_var = np.round(pca.explained_variance_ratio_ * 100, decimals=1) #type: ignore
pca_labels = ['PC' + str(x) for x in range(1, len(per_var) + 1)]
plt.bar(x=range(1, len(per_var) + 1), height=per_var, tick_label= pca_labels)
plt.ylabel("Pourcentages de la variance expliqué ")
plt.xlabel("Composant Principal")
plt.title("Éboulis")
plt.show()
pca_data = pca.transform(scaled_data)
pca_df = pd.DataFrame(pca_data, index=labels, columns=pca_labels)
plt.scatter(pca_df.PC1, pca_df.PC2)
plt.title("My PCA Graph")
plt.xlabel("PC1 - {0}%".format(per_var[0]))
plt.ylabel("PC2 - {0}%".format(per_var[1]))
plt.show()