y_test_predicted = linear_regressor.predict(X_test)
y_test_predicted here contains the predicted y-values.
So, how did the model perform. We will first see the performance using a graph.
pyplot.scatter(df["total_bill"], df["tip"]) pyplot.plot(X_test, y_test_predicted, color="green") pyplot.xlabel("Total Bill") pyplot.ylabel("Tip") pyplot.savefig("tips-regression.png") pyplot.close()
The graph looks like the following:
Here, the green line is the regression line. We can see the line fits the blue dots quite well.
We can also see the performance of the linear regression model using the following code:
r2 = r2_score(y_test, y_test_predicted) rmse = mean_squared_error(y_test, y_test_predicted, squared=False) print("R2: ", r2) print("RMSE: ", rmse)
Here, r2 variable contains the r-squared score (What is R-squared score?) and the rmse variable contains the root mean squared error (What is the Root Mean Squared Error or RMSE?).
The output will be like the following for our model:
R2: 0.53268096783414 RMSE: 1.108991226128831
So, smaller the RMSE, better the model. And if R2 is closer to 1, that means the model performs better.






0 Comments