11# Copyright (c) 2023 Diego Gasco (diego.gasco99@gmail.com), Diegomangasco on GitHub
22
33import logging
4+
45import numpy as np
56import scipy
67
@@ -61,9 +62,9 @@ def covariance_between_classes(
6162 return covariance_sum / features .shape [1 ]
6263
6364
64- def PCA (features : np .ndarray , dimensions : int ) -> np .ndarray :
65+ def principal_component_analysis (features : np .ndarray , dimensions : int ) -> np .ndarray :
6566 """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
6768 Parameters: \n
6869 * features: the features extracted from the dataset
6970 * labels: the class labels of the features
@@ -76,7 +77,8 @@ def PCA(features: np.ndarray, dimensions: int) -> np.ndarray:
7677 centered_data = features - np .reshape (data_mean , (data_mean .size , 1 ))
7778 covariance_matrix = np .dot (centered_data , centered_data .T ) / features .shape [1 ]
7879 _ , 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
8082 filtered_eigenvectors = eigenvectors [:, ::- 1 ][:, 0 :dimensions ]
8183 # Project the database on the new space
8284 projected_data = np .dot (filtered_eigenvectors .T , features )
@@ -89,11 +91,11 @@ def PCA(features: np.ndarray, dimensions: int) -> np.ndarray:
8991 raise AssertionError
9092
9193
92- def LDA (
94+ def linear_discriminant_analysis (
9395 features : np .ndarray , labels : np .ndarray , classes : int , dimensions : int
9496) -> np .ndarray :
9597 """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
9799 Parameters: \n
98100 * features: the features extracted from the dataset
99101 * labels: the class labels of the features
0 commit comments