Predict the miles per gallon from the curb weight and engine size, using Stochastic Gradient Descent and a linear model with L2 regularization. You need to code up SGD yourself such as in here.
import pandas as pd# Replace 'imports-85.csv' with the actual file path if it's not in the current directorydataset_url ="https://raw.githubusercontent.com/plotly/datasets/master/imports-85.csv"# Read the CSV file into a Pandas DataFramedf = pd.read_csv(dataset_url)# Now, you can work with the 'df' DataFrame as neededpd.set_option('display.max_columns', None) # Show all columnsdf.head(10)
symboling
normalized-losses
make
fuel-type
aspiration
num-of-doors
body-style
drive-wheels
engine-location
wheel-base
length
width
height
curb-weight
engine-type
num-of-cylinders
engine-size
fuel-system
bore
stroke
compression-ratio
horsepower
peak-rpm
city-mpg
highway-mpg
price
0
3
NaN
alfa-romero
gas
std
two
convertible
rwd
front
88.6
168.8
64.1
48.8
2548
dohc
4
130
mpfi
3.47
2.68
9.0
111.0
5000.0
21
27
13495.0
1
3
NaN
alfa-romero
gas
std
two
convertible
rwd
front
88.6
168.8
64.1
48.8
2548
dohc
4
130
mpfi
3.47
2.68
9.0
111.0
5000.0
21
27
16500.0
2
1
NaN
alfa-romero
gas
std
two
hatchback
rwd
front
94.5
171.2
65.5
52.4
2823
ohcv
6
152
mpfi
2.68
3.47
9.0
154.0
5000.0
19
26
16500.0
3
2
164.0
audi
gas
std
four
sedan
fwd
front
99.8
176.6
66.2
54.3
2337
ohc
4
109
mpfi
3.19
3.40
10.0
102.0
5500.0
24
30
13950.0
4
2
164.0
audi
gas
std
four
sedan
4wd
front
99.4
176.6
66.4
54.3
2824
ohc
5
136
mpfi
3.19
3.40
8.0
115.0
5500.0
18
22
17450.0
5
2
NaN
audi
gas
std
two
sedan
fwd
front
99.8
177.3
66.3
53.1
2507
ohc
5
136
mpfi
3.19
3.40
8.5
110.0
5500.0
19
25
15250.0
6
1
158.0
audi
gas
std
four
sedan
fwd
front
105.8
192.7
71.4
55.7
2844
ohc
5
136
mpfi
3.19
3.40
8.5
110.0
5500.0
19
25
17710.0
7
1
NaN
audi
gas
std
four
wagon
fwd
front
105.8
192.7
71.4
55.7
2954
ohc
5
136
mpfi
3.19
3.40
8.5
110.0
5500.0
19
25
18920.0
8
1
158.0
audi
gas
turbo
four
sedan
fwd
front
105.8
192.7
71.4
55.9
3086
ohc
5
131
mpfi
3.13
3.40
8.3
140.0
5500.0
17
20
23875.0
9
0
NaN
audi
gas
turbo
two
hatchback
4wd
front
99.5
178.2
67.9
52.0
3053
ohc
5
131
mpfi
3.13
3.40
7.0
160.0
5500.0
16
22
NaN
target_variable_column = df[['city-mpg']]feature_columns = df[['curb-weight', 'engine-size']]# Convert selected columns to a NumPy arrayy = target_variable_column.valuesX = feature_columns.valuesprint(X)