Question: I need help with my python lab. I completed the first part which is to load data with Pandas, output the basic information, and to

 I need help with my python lab. I completed the first

part which is to load data with Pandas, output the basic information,and to check for missing values, but I don't know how to

I need help with my python lab. I completed the first part which is to load data with Pandas, output the basic information, and to check for missing values, but I don't know how to do part 1.2, split the preprocessed dataset , or how to do part 1.3, train the linear regression model. How do I complete this? I also attached a picture of what insurance.csv looks like

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. 2.1 Preprocess the raw data Based on your Lab Assignment 3, deal with the missing values and categorical features. In [14]: # your code 1.2 Split the preprocessed dataset into training set and testing set Use 80% of samples as the training set and 20% of samples as the testing set In [15]: # your code 1.3 Train the linear regression model Use the Linear regression model to do prediction minw || y Xw 11 Please output the learned model parameter w and see how the learned model fit the training set. import pandas as pd import numpy as np from sklearn.preprocessing import LabelEncoder from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LinearRegression, Ridge, Lasso from sklearn.metrics import mean_absolute_error,mean_squared_error import matplotlib.pyplot as plt data = pd.read_csv('insurance.csv') print("Basic Information:") print(data.info( ) categorical_features [x for x in data.columns if data[x].dtype "object"] numerical_features = [x for x in data.columns if data[x].dtype != "object"] print("Categorical features:",categorical_features) print("Numerical features:", numerical_features) print(data.isnull().any ( ) ) 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 O no northwest 28923.13692 25 male 26.22 0 no northeast 2721.3208 62 female 26.29 0 yes southeast 27808.7251

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!