Skip to content

Commit 7e1fc35

Browse files
authored
Apply suggestions from code review
1 parent 041aa1d commit 7e1fc35

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

machine_learning/dimensionality_reduction.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) 2023 Diego Gasco ([email protected]), Diegomangasco on GitHub
22

33
import logging
4+
45
import numpy as np
56
import 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

Comments
 (0)