How to install statsmodels in Python?
If you aspire for a flourishing career in the field of machine learning, let us introduce you to one more interesting package whose functionalities would leave you awestruck.
So, let’s see what is statsmodels and what are its features?
Statsmodels is a popular library in Python that enables us to estimate and analyze various statistical models. It is built on numeric and scientific libraries like NumPy and SciPy.
Some of the essential features of this package are-
- It includes various models of linear regression like ordinary least squares, generalized least squares, weighted least squares, etc.
- It provides some efficient functions for time series analysis.
- It also has some datasets for examples and testing.
- Models based on survival analysis are also available.
- All the statistical tests that we can imagine for data on a large scale are present.
Let’s have a look at the steps of installing statsmodels in Python-
- Checking the version of Python installed in our PCs, we have discussed this already in the previous articles but let’s talk about this again-
There are two ways to check the version of Python in Windows-
- Using Powershell
- Using Command Prompt
Follow the below steps to check the version of Python using PowerShell.
- Click ‘Win+R’ or type ‘Run’ on the taskbar’s search pane.
- Type ‘Powershell’
- A window will appear on your screen named ‘Windows Powershell’
- Click on ‘Enter’
- Type python -version and click on ‘Enter’
- The version would be displayed in the next line.
Using Command Prompt
Type ‘Command Prompt’ on the taskbar’s search pane and you’ll see its icon. Click on it to open the command prompt.
Also, you can directly click on its icon if it is pinned on the taskbar.
- Once the ‘Command Prompt’ screen is visible on your screen.
- Type python -version and click on ‘Enter’.
- The version installed in your system would be displayed in the next line.
Checking the Version of Python in Linux
In Linux, we have a shell where we type our commands that are interpreted and tells the operating system about what the user wants.
The steps to check the version of Python in Linux is-
- Start your system and switch on to the Linux operating system (you might find it with the name Ubuntu).
- Once the desktop screen of Linux appears, click on ‘Terminal’ to open it.
- In the terminal window, type python -version and click on ‘Enter’.
In the next line, it will display the current version of python installed in your system.
Installation of statsmodels
Now let us discuss the steps for installing statsmodels in our system. We will look at two methods of installation
- Using Anaconda Prompt
- Using Command Prompt
In the first method, we will open the Anaconda Prompt and type the following command-
In the second method, we will open the Command Prompt, type the following command and click on ‘Enter’.
It’s time to look have a program in which we will import statsmodels-
Here, we will perform OLS(Ordinary Least Squares) regression, in this technique we will try to minimize the net sum of squares of difference between the calculated value and observed value.
In this tutorial, we discussed what are the steps involved in installing statsmodels and how we can obtain a detailed statistical summary of our dataset with its aid.