Conteúdo do Curso
Mathematics for Data Analysis and Modeling
Mathematics for Data Analysis and Modeling
Eigenvalues and Eigenvectors
Eigenvectors and eigenvalues are concepts related to linear transformations and matrices. An eigenvector v
is a non-zero vector that results in a scaled version of itself when multiplied by a given matrix. The eigenvalue λ
associated with an eigenvector represents the scalar value by which the eigenvector is scaled.
If we have some matrix A
and provide linear transformation A * v
, where v
- eigenvector of matrix A
, we will get the vector with the same direction but with different length:
Calculating eigenvalues and eigenvectors
To find eigenvectors and corresponding eigenvalues of a matrix, we can use np.linalg.eig()
method:
import numpy as np # Define a square matrix matrix = np.array([[2, 1, 3], [1, 3, 0], [3, 0, 4]]) # Calculate eigenvectors and eigenvalues eigenvalues, eigenvectors = np.linalg.eig(matrix) # Print the eigenvalues and eigenvectors for i in range(len(eigenvalues)): print(f'Eigenvalue {i+1}: {eigenvalues[i]:.3f}') print(f'Eigenvector {i+1}: {np.round(eigenvectors[:, i], 3)}\n')
In this example, we create a 3x3 matrix
matrix. We then use the np.linalg.eig()
method from NumPy
to calculate the eigenvalues and eigenvectors. The function returns two arrays: eigenvalues contain the eigenvalues, and eigenvectors contain the corresponding eigenvectors.
Practical applications
Eigenvalues and vectors are often used to solve various applied problems. One of these problems is the problem of dimensionality reduction for which the PCA algorithm is used: this algorithm is based on using eigenvalues of the feature covariance matrix.
Note
Dimensionality reduction is a fundamental problem in data analysis and machine learning, aiming to reduce the number of features or variables in a dataset while preserving as much relevant information as possible.
Obrigado pelo seu feedback!