Linear regression is a fundamental method in data analysis to understand the relationship between two variables. Here, I summarize four reusable Python functions for performing and visualizing linear fitting:
- Matplotlib: with and without intercept
- Plotly: with and without intercept
All methods:
- Drop NaN values in x and y
- Plot a scatter graph
- Fit a linear line
- Annotate the equation and correlation coefficient (R)