Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7 . 7 LAB: PCA using . cov and eig ( ) The forestfires.csv data base contains meteorological information and the area burned for 5

7.7 LAB: PCA using .cov and eig()
The forestfires.csv data base contains meteorological information and the area burned for 517 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:
[6.35187225e+042.12678877e+031.13496502e+013.31868702e+01][[0.00739596-0.02478582-0.585033370.81059664]
[0.17946956-0.98322216-0.0012556-0.03260793]
[0.983726460.179649160.00110826-0.00268257]
[0.00426876-0.019647360.811007490.58469018]]
0.9669459017392729
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
X_cov = # calculate the covariance matrix
w,v = # calculate the eigenvalues and eigenvectors of matrix X_cov
var = # calculate the percentage of the variance contained in the first principle component
print(w, v)
print(var)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the distribution of B(s) + B(t), s t?

Answered: 1 week ago

Question

What are the HRM implications of this type of merger?

Answered: 1 week ago

Question

What is an RPIC, and where was it required?

Answered: 1 week ago