Challenge Solution Review

In this lesson, we explain the solution to the last challenge lesson.

Press + to interact
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import sklearn.metrics as metrcis
df = pd.read_csv("./auto_insurance_sweden.csv", sep=",", header=0)
df.columns = ["x", "y"]
y = df.pop("y").values
X = df
train_x, test_x, train_y, test_y = train_test_split(X,
y,
test_size=0.2,
random_state=42)
lr = LinearRegression()
lr.fit(train_x, train_y)
pred_y = lr.predict(test_x)
mse = metrcis.mean_squared_error(test_y, pred_y)
print("The MSE is {}.".format(mse))

Get hands-on with 1400+ tech skills courses.