Question: Given a dataset created from the code fragment below, write code to apply PCA and linear regression on the dataset for various numbers of principal
Given a dataset created from the code fragment below, write code to apply PCA and linear regression on the dataset for various numbers of principal components, and plot the test scores and total variance explained ratios versus the number of principal components used. Do not use cross-validation.
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=500, n_features=30, n_informative=20, effective_rank=10, noise=4, tail_strength=0.1, random_state=42)
And then Write code to visualise the dataset in above part in a scatter plot using the first two principal components. Show the first principal component in the x-axis, the second principal component in the y-axis, and the target values in colours with the bwr Matplotlib colormap.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
