Challenge Solution Review
In this lesson, we explain the solution to the last challenge lesson.
import pandas as pdfrom sklearn.model_selection import train_test_splitfrom sklearn.linear_model import LinearRegressionimport sklearn.metrics as metrcisdf = pd.read_csv("./auto_insurance_sweden.csv", sep=",", header=0)df.columns = ["x", "y"]y = df.pop("y").valuesX = dftrain_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.