Member-only story

Perform simple linear regression with Scipy

Crystal X
3 min readNov 1, 2023

--

In my last blog post I discussed how to perform simple linear regression using Python libraries sklearn and statsmodels, and that post can be found here:- https://medium.com/@tracyrenee61/interview-question-perform-simple-linear-regression-on-the-mtcars-dataset-fc997de88660

In this blog post I intend to discuss how to perform simple linear regression with Python’s scientific library, scipy.

Scipy is Python’s scientific computing library. It provides algorithms for optimization, integration, interpolation, eigenvalue problems, algebraic equations, differential equations, statistics and many other classes of problems. Scipy extends NumPy, providing additional tools for array computing and provides specialised data structures, such as sparse matrices and k-dimensional trees. In this post, however, I am just going to focus on scipy’s linear regression method, linregress.

I have used the mtcars dataset to carry out linear regression using scipy’s linregress method. I have written the program in Google Colab, which is a free online Jupyter Notebook hosted by Google.

When the Jupyter Notebook was created, I used the pandas library to read the mtcars csv file in and convert it to a dataframe, df:-

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet