课程: R for Data Science: Lunch Break Lessons

Matrix: Eigenvalues and eigenvectors

- [Instructor] Eigenvalues and eigenvectors are a complex concept used in data science. R provides a way to quickly and easily calculate these from a given matrix. Let's take a look at how it works. First, I'll need a matrix. And I have one right here, I'll run it. And you can see in the environment that I've created the matrix, let's take a look and see what it looks like. It's a fairly simple matrix. And to calculate the eigenvalues and eigenvectors, I simply use E-I-G-E-N and give it the name of the matrix. And you'll see that I come back with two results, values or the eigenvalues and vectors, which is the matrix of returned values for the vectors. When you're using eigenvalues and eigenvectors, you'll often need to convert the eigenvalues to a diagonal matrix, and you'll recall that's fairly easy to do, but I'll remind you here. You simply use the D-I-A-G command, or diag command, and then you'll type in E-I-G-E-N, followed by the matrix that you're trying to decompose. And then use the dollar sign operator to retrieve the values. This will produce a diagonal matrix out of the eigenvalues. So, again, eigenvalues and eigenvectors are a valuable tool for use in data science, and R provides a simple way to calculate both of them.

内容