Simple Linear Regression Model using Scikit Learn : Part 2
In part 1 of this series, we discussed the basics of simple linear regression and how we can implement it using the Scikit Learn library in Python. In this article, we will take a deeper dive into the model evaluation and performance metrics for our simple linear regression model.
Evaluation Metrics
Once we have trained our simple linear regression model, we need to evaluate its performance using various metrics. Some of the common evaluation metrics for regression models are:
- Mean Absolute Error (MAE)
- Mean Squared Error (MSE)
- Root Mean Squared Error (RMSE)
- R-squared (R2)
These metrics help us understand how well our model is performing and make comparisons with other models or different hyperparameter settings.
Implementing Evaluation Metrics in Scikit Learn
Scikit Learn provides built-in functions to calculate these evaluation metrics for regression models. Here’s how you can implement them for your simple linear regression model:
“`python
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
# Make predictions on the test set
y_pred = model.predict(X_test)
# Calculate evaluation metrics
mae = mean_absolute_error(y_test, y_pred)
mse = mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)
r2 = r2_score(y_test, y_pred)
print(“Mean Absolute Error:”, mae)
print(“Mean Squared Error:”, mse)
print(“Root Mean Squared Error:”, rmse)
print(“R-squared:”, r2)
“`
By using these evaluation metrics, you can get a better understanding of how well your simple linear regression model is performing on unseen data.
Conclusion
In this article, we have discussed the evaluation metrics for simple linear regression models and how to implement them using Scikit Learn. By evaluating the performance of our model, we can make informed decisions on its effectiveness and make improvements if necessary.
Stay tuned for more articles on machine learning and data science topics!