Translate

Sunday, July 17, 2022

StatModels in SQL Server Python

Python in SQL Server is an important feature that is provided especially for data scientists. However, there are additional libraries that you need to install to achieve your goals. statsmodels is a Python module that provides classes and functions for the estimation of many different statistical models, as well as for conducting statistical tests and statistical data exploration.

In statmodels, there are multiple versions and you need to pick the right version for you. For example, STL is available only after 0.12.0 statmodels. By default SQL Server 2019 will get you the statmodels 0.9.0 which may not be enough so you have to upgrade which can be done from the following python pip.

python -m pip install statsmodels

However, this will give you an error saying that you need to upgrade the python to the higher version of 3.8 as SQL Server as the python 3.7.1 version. Now you need to upgrade python for SQL Server. 

But the better thing to do is to upgrading relevant statsmodels version which is 0.12.0. Therefore you need to run the command python -m pip install statsmodels==0.12.0 at the folder.

C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES