Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

"mpg","cylinders","displacement","horsepower","weight","acceleration","year","origin" 14.5,8,351,152,4215,12.8,76,1 25.5,4,140,89,2755,15.8,77,1 22.5,6,232,90,3085,17.6,76,1 13,8,307,130,4098,14,72,1...

1 answer below »
"mpg","cylinders","displacement","horsepower","weight","acceleration","year","origin"
14.5,8,351,152,4215,12.8,76,1
25.5,4,140,89,2755,15.8,77,1
22.5,6,232,90,3085,17.6,76,1
13,8,307,130,4098,14,72,1
27.9,4,156,105,2800,14.4,80,1
18.6,6,225,110,3620,18.7,78,1
33.5,4,151,90,2556,13.2,79,1
12,8,383,180,4955,11.5,71,1
29.5,4,98,68,2135,16.6,78,3
14,8,351,148,4657,13.5,75,1
24.3,4,151,90,3003,20.1,80,1
36.1,4,91,60,1800,16.4,78,3
27.2,4,141,71,3190,24.8,79,2
16.5,6,168,120,3820,16.7,76,2
17.5,6,258,95,3193,17.8,76,1
38,4,91,67,1995,16.2,82,3
14,8,455,225,4425,10,70,1
25,4,121,115,2671,13.5,75,2
17,6,163,125,3140,13.6,78,2
27,4,151,90,2950,17.3,82,1
22,4,121,98,2945,14.5,75,2
32.2,4,108,75,2265,15.2,80,3
21,6,231,110,3039,15,75,1
13,8,400,150,4464,12,73,1
10,8,307,200,4376,15,70,1
18,6,232,100,3288,15.5,71,1
16,8,400,230,4278,9.5,73,1
22,6,225,100,3233,15.4,76,1
21.5,4,121,110,2600,12.8,77,2
24,4,120,97,2489,15,74,3
32.7,6,168,132,2910,11.4,80,3
12,8,350,180,4499,12.5,73,1
29,4,97,75,2171,16,75,3
19,4,121,112,2868,15.5,73,2
26,4,97,75,2265,18.2,77,3
14,8,318,150,4237,14.5,73,1
25,4,90,71,2223,16.5,75,2
20.3,5,131,103,2830,15.9,78,2
27,4,97,88,2130,14.5,71,3
38.1,4,89,60,1968,18.8,80,3
22.4,6,231,110,3415,15.8,81,1
27.4,4,121,80,2670,15,79,1
24,4,121,110,2660,14,73,2
29,4,68,49,1867,19.5,73,2
26.6,8,350,105,3725,19,81,1
32.1,4,98,70,2120,15.5,80,1
34.2,4,105,70,2200,13.2,79,1
16,8,302,140,4141,14,74,1
30.9,4,105,75,2230,14.5,78,1
29.8,4,89,62,1845,15.3,80,2
26,4,108,93,2391,15.5,74,3
43.1,4,90,48,1985,21.5,78,2
13,8,350,150,4699,14.5,74,1
18,3,70,90,2124,13.5,73,3
19.4,6,232,90,3210,17.2,78,1
12,8,350,160,4456,13.5,72,1
30.5,4,97,78,2190,14.1,77,2
14,8,318,150,4096,13,71,1
23,4,120,97,2506,14.5,72,3
18,6,250,88,3139,14.5,71,1
22,4,122,86,2395,16,72,1
26,4,97,46,1835,20.5,70,2
13,8,350,145,4055,12,76,1
15.5,8,351,142,4054,14.3,79,1
23.5,6,173,110,2725,12.6,81,1
19.2,8,305,145,3425,13.2,78,1
35.1,4,81,60,1760,16.1,81,3
18,6,225,105,3613,16.5,74,1
18.1,8,302,139,3205,11.2,78,1
29,4,90,70,1937,14.2,76,2
16.5,8,350,180,4380,12.1,76,1
26,4,98,90,2265,15.5,73,2
13,8,350,145,3988,13,73,1
29.8,4,134,90,2711,15.5,80,3
29.5,4,97,71,1825,12.2,76,2
13,8,350,155,4502,13.5,72,1
27.2,4,135,84,2490,15.7,81,1
19,6,225,95,3264,16,75,1
18.5,8,360,150,3940,13,79,1
15.5,8,304,120,3962,13.9,76,1
28.8,6,173,115,2595,11.3,79,1
16,8,400,180,4220,11.1,77,1
30,4,135,84,2385,12.9,81,1
43.4,4,90,48,2335,23.7,80,2
22,4,140,72,2408,19,71,1
17,8,302,140,3449,10.5,70,1
33.5,4,85,70,1945,16.8,77,3
25,4,113,95,2228,14,71,3
39.1,4,79,58,1755,16.9,81,3
29,4,85,52,2035,22.2,76,1
34.1,4,91,68,1985,16,81,3
31,4,79,67,2000,16,74,2
24,4,90,75,2108,15.5,74,2
30,4,88,76,2065,14.5,71,2
20.5,6,231,105,3425,16.9,77,1
37.7,4,89,62,2050,17.3,81,3
18,6,250,105,3459,16,75,1
13,8,350,165,4274,12,72,1
37,4,119,92,2434,15,80,3
19,6,232,90,3211,17,75,1
20,6,232,100,2914,16,75,1
25,4,104,95,2375,17.5,70,2
15,8,383,170,3563,10,70,1
17.5,8,305,140,4215,13,76,1
37,4,85,65,1975,19.4,81,3
24,4,119,97,2545,17,75,3
15,6,258,110,3730,19,75,1
34.5,4,105,70,2150,14.9,79,1
19.8,6,200,85,2990,18.2,79,1
32,4,83,61,2003,19,74,3
32,4,135,84,2295,11.6,82,1
24,4,134,96,2702,13.5,75,3
11,8,429,208,4633,11,72,1
44,4,97,52,2130,24.6,82,2
32,4,85,70,1990,17,76,3
19,6,232,100,2901,16,74,1
23,4,122,86,2220,14,71,1
20,4,130,102,3150,15.7,76,2
9,8,304,193,4732,18.5,70,1
33.5,4,98,83,2075,15.9,77,1
31.9,4,89,71,1925,14,79,2
19.1,6,225,90,3381,18.7,80,1
15,8,318,150,3777,12.5,73,1
33,4,105,74,2190,14.2,81,2
23,8,350,125,3900,17.4,79,1
16.2,6,163,133,3410,15.8,78,2
26,4,79,67,1963,15.5,74,2
17.6,6,225,85,3465,16.6,81,1
13,8,302,140,4294,16,72,1
26,4,91,70,1955,20.5,71,1
14,8,318,150,4077,14,72,1
24.2,6,146,120,2930,13.8,81,3
29.9,4,98,65,2380,20.7,81,1
22,6,232,112,2835,14.7,82,1
37.2,4,86,65,2019,16.4,80,3
18,6,232,100,2789,15,73,1
18,6,199,97,2774,15.5,70,1
14,8,304,150,3672,11.5,73,1
26,4,98,79,2255,17.7,76,1
20.5,6,225,100,3430,17.2,78,1
17,6,231,110,3907,21,75,1
27,4,140,86,2790,15.6,82,1
31.5,4,98,68,2045,18.5,77,3
16,6,250,100,3278,18,73,1
12,8,455,225,4951,11,73,1
15.5,8,318,145,4140,13.7,77,1
20.5,6,200,95,3155,18.2,78,1
25,4,116,81,2220,16.9,76,2
28,4,112,88,2605,19.6,82,1
17.5,8,305,145,3880,12.5,77,1
15,8,304,150,3892,12.5,72,1
19,6,250,100,3282,15,71,1
13,8,302,130,3870,15,76,1
15,8,318,150,3399,11,73,1
19,6,156,108,2930,15.5,76,3
18,6,258,110,2962,13.5,71,1
36,4,120,88,2160,14.5,82,3
30.7,6,145,76,3160,19.6,81,2
17,8,260,110,4060,19,77,1
31,4,79,67,1950,19,74,3
34.4,4,98,65,2045,16.2,81,1
12,8,429,198,4952,11.5,73,1
26,4,121,113,2234,12.5,70,2
22,6,146,97,2815,14.5,77,3
14,8,351,153,4129,13,72,1
16.9,8,350,155,4360,14.9,79,1
21,6,199,90,2648,15,70,1
34,4,112,88,2395,18,82,1
21.5,3,80,110,2720,13.5,77,3
34.1,4,86,65,1975,15.2,79,3
20,4,140,90,2408,19.5,72,1
27.2,4,119,97,2300,14.7,78,3
46.6,4,86,65,2110,17.9,80,3
23,4,97,54,2254,23.5,72,2
14,8,351,153,4154,13.5,71,1
21,6,155,107,2472,14,73,1
21.1,4,134,95,2515,14.8,78,3
11,8,318,210,4382,13.5,70,1
27,4,97,60,1834,19,71,2
15,6,250,72,3432,21,75,1
28,4,97,75,2155,16.4,76,3
24,4,107,90,2430,14.5,70,2
16.5,8,351,138,3955,13.2,79,1
18,6,250,78,3574,21,76,1
28,4,120,79,2625,18.6,82,1
15,8,318,150,4135,13.5,72,1
32.9,4,119,100,2615,14.8,81,3
40.8,4,85,65,2110,19.2,80,3
24.5,4,98,60,2164,22.1,76,1
13,8,400,190,4422,12.5,72,1
35,4,72,69,1613,18,71,3
16,6,225,105,3439,15.5,71,1
20.8,6,200,85,3070,16.7,78,1
26,4,97,46,1950,21,73,2
25,4,140,92,2572,14.9,76,1
23,6,198,95,2904,16,73,1
30,4,79,70,2074,19.5,71,2
15,8,390,190,3850,8.5,70,1
32.4,4,107,72,2290,17,80,3
13,8,302,129,3169,12,75,1
17,8,305,130,3840,15.4,79,1
10,8,360,215,4615,14,70,1
17.5,6,250,110,3520,16.4,77,1
32.4,4,108,75,2350,16.8,81,3
17.5,8,318,140,4080,13.7,78,1
26,4,122,80,2451,16.5,74,1
16,8,318,150,4190,13,76,1
11,8,400,150,4997,14,73,1
23.7,3,70,100,2420,12.5,80,3
28,4,98,80,2164,15,72,1
44.3,4,90,48,2085,21.7,80,2
13,8,360,170,4654,13,73,1
20,8,262,110,3221,13.5,75,1
22,6,250,105,3353,14.5,76,1
26.4,4,140,88,2870,18.1,80,1
14,8,350,165,4209,12,71,1
18,4,121,112,2933,14.5,72,2
15.5,8,400,190,4325,12.2,77,1
28,4,97,92,2288,17,72,3
33,4,91,53,1795
Answered 1 days After Mar 23, 2021

Solution

Vicky answered on Mar 24 2021
152 Votes
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q1. The purpose of this question is to implement your own version of PCR. Overall the PCR implementation is no more than a dozen lines of code, but I would be walking you through the steps, so that\n",
"you fully understand what is being done. The advantage of knowing this is you will not be restricted to\n",
"what PCR does for fitting (meaning that first doing a dimension reduction and then doing a linear fit). In\n",
"the future you can perform the dimension reduction step, and then instead of doing a linear fit, pick any\n",
"other algorithm of your choice, such as random forest, neural networks, etc. To answer this question, you\n",
"may find Slide 24 of lecture 8 useful. Also, during the afternoon session recording (video time 3:18:18) one\n",
"of the students asked a question and you may find the answer to it very related to this question."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# import li
aries\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.preprocessing import scale \n",
"from sklearn.decomposition import PCA\n",
"from sklearn import model_selection\n",
"from sklearn.linear_model import LinearRegression \n",
"from sklearn import metrics"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"