![]() |
VOOZH | about |
Statsmodels is a Python library that enables us to estimate and analyze various statistical models. It is built on numeric and scientific libraries like NumPy and SciPy. It provides classes & functions for the estimation of many different statistical models.
Before installing Statsmodels, ensure that you have:
The easiest way to install Statsmodels is by using pip. Run the following command in your terminal or command prompt:
python -m venv env
.\env\Scripts\activate
pip install statsmodels
This will automatically install Statsmodels with its dependencies including NumPy, SciPy, Pandas, and Patsy. Patsy is used for handling formulas in statistical models.
If you use Anaconda, you can install Statsmodels using the Conda package manager:
conda install -c conda-forge statsmodels
To continue with installation type 'y':
We have successfully installed statsmodel library.
After installation, you can verify that Statsmodels is working correctly by running the following Python script:
Output
Statsmodels version: 0.14.4
Follow the below steps to install statsmodels in Python on Linux using pip:
$ python3 -m venv StatsM
$ source ./StatsM/bin/activate
$ pip install statsmodels
Hence, installation is successful.
To install Statsmodels in Python on Linux using Conda, follow these steps:
Step 1: Download and Install Miniconda
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh
Step 2: Activate the Conda Base Environment using following command:
source ~/miniconda3/bin/activate
Note: The (base) in the terminal prompt indicates that you have successfully entered the Conda environment. The base Conda environment is now active. You can install, manage, or run packages within this environment. Any Python commands executed will use the Conda-installed Python and dependencies.
Verify the active Conda environment by running:
conda info --envsStep 3: Install Statsmodels in the Conda environment using the following command:
conda install -c conda-forge statsmodels
This will display the installed version of Statsmodels, confirming that the installation was successful.
Step 4: Verify the Installation of Statsmodels by running the following command:
import statsmodels.api as sm
print(sm.__version__)
By following these steps, you can successfully install Statsmodels in a Conda environment on Linux.