Question: 7 . 7 LAB: PCA using . cov and eig ( ) The forestfires.csv data base contains meteorological information and the area burned for 5
LAB: PCA using cov and eig
The forestfires.csv data base contains meteorological information and the area burned for forest fires that occurred in Montesinho Natural Park in Portugal. The columns of interest are FFMC DMC DC ISI, temp, RH wind, and rain.
Read in the file forestfires.csv
Create a new data frame X from the columns FFMC DMC DC ISI, temp, RH wind, and rain, in that order.
Calculate the covariance matrix for the data in X
Calculate the eigenvalues and eigenvectors for the covariance matrix.
Calculate the amount of variance contained in the first component.
Ex: If only the columns FFMC DMC DC and ISI are used, the output is:
eeee
Template:
# import the necessary modules
fires # read in forestfires.csv
X # create a new dataframe with the columns FFMC DMC DC ISI, temp, RH wind, and rain, in that order
Xcov # calculate the covariance matrix
wv # calculate the eigenvalues and eigenvectors of matrix Xcov
var # calculate the percentage of the variance contained in the first principle component
printw v
printvar
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
