Question 37
Please consider the following data and code for a regression problem with following symbols in mind:
- >>>: Represents input code
- # : Represents comment in a code
- ... : Represents code continuation
- Without any symbols at the beginning of a line then it is output of just above input line of code.
| Age | Car_color | Accidents_per_1000_Driver | |
|---|---|---|---|
| 0 | 19 | Black | 74 |
| 1 | 19 | Blue | 75 |
| 2 | 19 | Red | 85 |
| 3 | 24 | Black | 70 |
| 4 | 24 | Blue | 70 |
| 5 | 24 | Red | 89 |
| 6 | 30 | Black | 78 |
| 7 | 30 | Blue | 76 |
| 8 | 30 | Red | 90 |
Target column: Accidents_per_1000_Driver
>>> import pandas as pd>>> from sklearn.preprocessing import OneHotEncoder>>> from sklearn.linear_model import LinearRegression
>>> data = pd.DataFrame([[19, 'Black', 74],... [19, 'Blue', 75],... [19, 'Red', 85],... [24, 'Black', 70],... [24, 'Blue', 70],... [24, 'Red', 89],... [30, 'Black', 78],... [30, 'Blue', 76],... [30, 'Red', 90]], columns=["Age","Car_color","Accidents_per_1000_Driver"])
>>> X = data.drop("Accidents_per_1000_Driver", axis=1)>>> y = data["Accidents_per_1000_Driver"]
>>> ohe = OneHotEncoder(sparse_output=False)
>>> X[['Black', 'Blue', 'Red']] = ohe.fit_transform(X[["Car_color"]])>>> X.drop("Car_color", axis=1, inplace=True)
>>> lr = LinearRegression().fit(X, y)
>>> print(lr.coef_)[0.32, -4.55, -4.88, 9.44]
>>> print(lr.intercept_)70.75Based on the above data, answer the given subquestions.
How many Accidents per 1000 Driver happens for Age 25 and driving blue car ?