machine_learning.dimensionality_reduction

Requirements:
  • numpy version 1.21

  • scipy version 1.3.3

Notes:
  • Each column of the features matrix corresponds to a class item

Functions

column_reshape(→ numpy.ndarray)

Function to reshape a row Numpy array into a column Numpy array

covariance_between_classes(→ numpy.ndarray)

Function to compute the covariance matrix between multiple classes

covariance_within_classes(→ numpy.ndarray)

Function to compute the covariance matrix inside each class.

linear_discriminant_analysis(→ numpy.ndarray)

Linear Discriminant Analysis.

principal_component_analysis(→ numpy.ndarray)

Principal Component Analysis.

test_linear_discriminant_analysis(→ None)

test_principal_component_analysis(→ None)

Module Contents

machine_learning.dimensionality_reduction.column_reshape(input_array: numpy.ndarray) numpy.ndarray

Function to reshape a row Numpy array into a column Numpy array >>> input_array = np.array([1, 2, 3]) >>> column_reshape(input_array) array([[1],

[2], [3]])

machine_learning.dimensionality_reduction.covariance_between_classes(features: numpy.ndarray, labels: numpy.ndarray, classes: int) numpy.ndarray

Function to compute the covariance matrix between multiple classes >>> features = np.array([[9, 2, 3], [4, 3, 6], [1, 8, 9]]) >>> labels = np.array([0, 1, 0]) >>> covariance_between_classes(features, labels, 2) array([[ 3.55555556, 1.77777778, -2.66666667],

[ 1.77777778, 0.88888889, -1.33333333], [-2.66666667, -1.33333333, 2. ]])

machine_learning.dimensionality_reduction.covariance_within_classes(features: numpy.ndarray, labels: numpy.ndarray, classes: int) numpy.ndarray

Function to compute the covariance matrix inside each class. >>> features = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> labels = np.array([0, 1, 0]) >>> covariance_within_classes(features, labels, 2) array([[0.66666667, 0.66666667, 0.66666667],

[0.66666667, 0.66666667, 0.66666667], [0.66666667, 0.66666667, 0.66666667]])

machine_learning.dimensionality_reduction.linear_discriminant_analysis(features: numpy.ndarray, labels: numpy.ndarray, classes: int, dimensions: int) numpy.ndarray

Linear Discriminant Analysis.

For more details, see: https://en.wikipedia.org/wiki/Linear_discriminant_analysis. Parameters:

  • features: the features extracted from the dataset

  • labels: the class labels of the features

  • classes: the number of classes present in the dataset

  • dimensions: to filter the projected data for the desired dimension

>>> test_linear_discriminant_analysis()
machine_learning.dimensionality_reduction.principal_component_analysis(features: numpy.ndarray, dimensions: int) numpy.ndarray

Principal Component Analysis.

For more details, see: https://en.wikipedia.org/wiki/Principal_component_analysis. Parameters:

  • features: the features extracted from the dataset

  • dimensions: to filter the projected data for the desired dimension

>>> test_principal_component_analysis()
machine_learning.dimensionality_reduction.test_linear_discriminant_analysis() None
machine_learning.dimensionality_reduction.test_principal_component_analysis() None