1
1
# Copyright (c) 2023 Diego Gasco ([email protected] ), Diegomangasco on GitHub
2
2
3
3
import logging
4
+
4
5
import numpy as np
5
6
import scipy
6
7
@@ -61,9 +62,9 @@ def covariance_between_classes(
61
62
return covariance_sum / features .shape [1 ]
62
63
63
64
64
- def PCA (features : np .ndarray , dimensions : int ) -> np .ndarray :
65
+ def principal_component_analysis (features : np .ndarray , dimensions : int ) -> np .ndarray :
65
66
"""Principal Component Analysis. \n
66
- For more details, see here : https://en.wikipedia.org/wiki/Principal_component_analysis \n
67
+ For more details, see: https://en.wikipedia.org/wiki/Principal_component_analysis
67
68
Parameters: \n
68
69
* features: the features extracted from the dataset
69
70
* labels: the class labels of the features
@@ -76,7 +77,8 @@ def PCA(features: np.ndarray, dimensions: int) -> np.ndarray:
76
77
centered_data = features - np .reshape (data_mean , (data_mean .size , 1 ))
77
78
covariance_matrix = np .dot (centered_data , centered_data .T ) / features .shape [1 ]
78
79
_ , eigenvectors = np .linalg .eigh (covariance_matrix )
79
- # Take all the columns in the reverse order (-1), and then takes only the first columns
80
+ # Take all the columns in the reverse order (-1), and then takes only the first
81
+ # columns
80
82
filtered_eigenvectors = eigenvectors [:, ::- 1 ][:, 0 :dimensions ]
81
83
# Project the database on the new space
82
84
projected_data = np .dot (filtered_eigenvectors .T , features )
@@ -89,11 +91,11 @@ def PCA(features: np.ndarray, dimensions: int) -> np.ndarray:
89
91
raise AssertionError
90
92
91
93
92
- def LDA (
94
+ def linear_discriminant_analysis (
93
95
features : np .ndarray , labels : np .ndarray , classes : int , dimensions : int
94
96
) -> np .ndarray :
95
97
"""Linear Discriminant Analysis. \n
96
- For more details, see here : https://en.wikipedia.org/wiki/Linear_discriminant_analysis \n
98
+ For more details, see: https://en.wikipedia.org/wiki/Linear_discriminant_analysis
97
99
Parameters: \n
98
100
* features: the features extracted from the dataset
99
101
* labels: the class labels of the features
0 commit comments