Question
age,sex,bmi,children,smoker,region,charges 19,female,27.9,0,yes,southwest,16884.924 18,male,33.77,1,no,southeast,1725.5523 28,male,33,3,no,southeast,4449.462 33,male,22.705,0,no,northwest,21984.47061 32,male,28.88,0,no,northwest,3866.8552 31,female,25.74,0,no,southeast,3756.6216 46,female,33.44,1,no,southeast,8240.5896 37,female,27.74,3,no,northwest,7281.5056 37,male,29.83,2,no,northeast,6406.4107 60,female,25.84,0,no,northwest,28923.13692 25,male,26.22,0,no,northeast,2721.3208 62,female,26.29,0,yes,southeast,27808.7251 23,male,34.4,0,no,southwest,1826.843 56,female,39.82,0,no,southeast,11090.7178 27,male,42.13,0,yes,southeast,39611.7577 19,male,24.6,1,no,southwest,1837.237 52,female,30.78,1,no,northeast,10797.3362 23,male,23.845,0,no,northeast,2395.17155 56,male,40.3,0,no,southwest,10602.385 30,male,35.3,0,yes,southwest,36837.467 60,female,36.005,0,no,northeast,13228.84695 30,female,32.4,1,no,southwest,4149.736 18,male,34.1,0,no,southeast,1137.011 34,female,31.92,1,yes,northeast,37701.8768
age,sex,bmi,children,smoker,region,charges 19,female,27.9,0,yes,southwest,16884.924 18,male,33.77,1,no,southeast,1725.5523 28,male,33,3,no,southeast,4449.462 33,male,22.705,0,no,northwest,21984.47061 32,male,28.88,0,no,northwest,3866.8552 31,female,25.74,0,no,southeast,3756.6216 46,female,33.44,1,no,southeast,8240.5896 37,female,27.74,3,no,northwest,7281.5056 37,male,29.83,2,no,northeast,6406.4107 60,female,25.84,0,no,northwest,28923.13692 25,male,26.22,0,no,northeast,2721.3208 62,female,26.29,0,yes,southeast,27808.7251 23,male,34.4,0,no,southwest,1826.843 56,female,39.82,0,no,southeast,11090.7178 27,male,42.13,0,yes,southeast,39611.7577 19,male,24.6,1,no,southwest,1837.237 52,female,30.78,1,no,northeast,10797.3362 23,male,23.845,0,no,northeast,2395.17155 56,male,40.3,0,no,southwest,10602.385 30,male,35.3,0,yes,southwest,36837.467 60,female,36.005,0,no,northeast,13228.84695 30,female,32.4,1,no,southwest,4149.736 18,male,34.1,0,no,southeast,1137.011 34,female,31.92,1,yes,northeast,37701.8768 37,male,28.025,2,no,northwest,6203.90175 59,female,27.72,3,no,southeast,14001.1338 63,female,23.085,0,no,northeast,14451.83515 55,female,32.775,2,no,northwest,12268.63225 23,male,17.385,1,no,northwest,2775.19215 31,male,36.3,2,yes,southwest,38711 22,male,35.6,0,yes,southwest,35585.576 18,female,26.315,0,no,northeast,2198.18985 19,female,28.6,5,no,southwest,4687.797 63,male,28.31,0,no,northwest,13770.0979 28,male,36.4,1,yes,southwest,51194.55914 19,male,20.425,0,no,northwest,1625.43375 62,female,32.965,3,no,northwest,15612.19335 26,male,20.8,0,no,southwest,2302.3 35,male,36.67,1,yes,northeast,39774.2763 60,male,39.9,0,yes,southwest,48173.361 24,female,26.6,0,no,northeast,3046.062 31,female,36.63,2,no,southeast,4949.7587 41,male,21.78,1,no,southeast,6272.4772 37,female,30.8,2,no,southeast,6313.759 38,male,37.05,1,no,northeast,6079.6715 55,male,37.3,0,no,southwest,20630.28351 18,female,38.665,2,no,northeast,3393.35635 28,female,34.77,0,no,northwest,3556.9223 60,female,24.53,0,no,southeast,12629.8967 36,male,35.2,1,yes,southeast,38709.176 18,female,35.625,0,no,northeast,2211.13075 21,female,33.63,2,no,northwest,3579.8287 48,male,28,1,yes,southwest,23568.272 36,male,34.43,0,yes,southeast,37742.5757 40,female,28.69,3,no,northwest,8059.6791 58,male,36.955,2,yes,northwest,47496.49445 58,female,31.825,2,no,northeast,13607.36875 18,male,31.68,2,yes,southeast,34303.1672 53,female,22.88,1,yes,southeast,23244.7902 34,female,37.335,2,no,northwest,5989.52365 43,male,27.36,3,no,northeast,8606.2174 25,male,33.66,4,no,southeast,4504.6624 64,male,24.7,1,no,northwest,30166.61817 28,female,25.935,1,no,northwest,4133.64165 20,female,22.42,0,yes,northwest,14711.7438 19,female,28.9,0,no,southwest,1743.214 61,female,39.1,2,no,southwest,14235.072 40,male,26.315,1,no,northwest,6389.37785 40,female,36.19,0,no,southeast,5920.1041
2. Task: Linear Regression for Medical Cost Prediction 2.1 Preprocess the raw data Based on your Lab Arsigrenent 2. deal with ihe missing valyes and casegoncal fertures. rour code 1.2 Split the preprocessed dataset into training set and testing set Use ges of sampes as tie trining set and 20k ot bamples at the isting kt 4 mour cose 1.3 Train the linear regression model Uie the Linear roprestion model is de prodiction minw211yxwi21 ryour cosfe 1.4 Evaluate the linear regression model a your cosel 1.5 Use the ridge regression model to do prediction * your rede When given a new dacaset, we nesd to deal with the missing values and categorical features. the testing set is used to evakate the learned model. Note that the testing set is NOT allowed to be used in the training phase. Q 2. eplit mapples boaad_foa - df -dropl'sodilar heuat bose price - df I "medisn house_vi boune priee = how priee p.M \[ x_{-} t r a i x_{1}, x_{\text {test }} y_{\text {trat }}, y_{\text {_test }}=1 \] print X erain.skape } Print (Xtast,_hape } Q normarila fiecurap comalizer = standardsonler( X train = nermalizer. fit eranater I_test - normalizer, tranafarmi x _ [14512,9] (412%2,9) 1.3 Train the linear regression model minwn1yXw22 Here, wo use the training set to iearn the model parameter w=(w9,w1+w2,,wa). Then, we compute MAE, MSE, and RMSE to see how well the learnec model fit the training set. printl' brediction for traininq ad 2. Task: Linear Regression for Medical Cost Prediction Following the given example, build a linear regression model for the insurance dataset to predict the medical cost
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started