statsmodels | Statsmodels : statistical modeling and econometrics in Python | Analytics library

 by   statsmodels Python Version: 0.14.2 License: BSD-3-Clause

kandi X-RAY | statsmodels Summary

kandi X-RAY | statsmodels Summary

statsmodels is a Python library typically used in Analytics applications. statsmodels has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can install using 'pip install statsmodels' or download it from GitHub, PyPI.

Statsmodels: statistical modeling and econometrics in Python

            kandi-support Support

              statsmodels has a highly active ecosystem.
              It has 8572 star(s) with 2715 fork(s). There are 275 watchers for this library.
              There were 2 major release(s) in the last 6 months.
              There are 2454 open issues and 2673 have been closed. On average issues are closed in 216 days. There are 166 open pull requests and 0 closed requests.
              It has a positive sentiment in the developer community.
              The latest version of statsmodels is 0.14.2

            kandi-Quality Quality

              statsmodels has 0 bugs and 0 code smells.

            kandi-Security Security

              statsmodels has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              statsmodels code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              statsmodels is licensed under the BSD-3-Clause License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              statsmodels releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              statsmodels saves you 224309 person hours of effort in developing the same functionality from scratch.
              It has 233861 lines of code, 11576 functions and 1170 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed statsmodels and discovered the below as its top functions. This is intended to give you an instant insight into statsmodels implemented functionality, and help decide if they suit your requirements.
            • Plot a dot plot .
            • Compute the news distribution .
            • Rotates a matrix A .
            • Update the filter .
            • Plot the hdr box plot .
            • Fit the model using the given parameters .
            • Compute a robust covariance matrix .
            • r Compute a model .
            • Calculate the Hannan RANSEN algorithm .
            • Return a summary of the model .
            Get all kandi verified functions for this library.

            statsmodels Key Features

            No Key Features are available at this moment for statsmodels.

            statsmodels Examples and Code Snippets

            for loop to print logistic regression stats summary | statsmodels
            Pythondot img1Lines of Code : 11dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            def opportunites():
                indep = ['AGE', 'S0287', 'T0080', 'SALARY', 'T0329', 'T0333', 'T0159', 'T0165', 'EXPER', 'T0356']
                for i in indep:
                    model = smf.logit(f'LEAVER ~ {i} ', data = df).fit()
            Predicting future data using a single column as input data
            Pythondot img2Lines of Code : 16dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import pandas as pd
            import statsmodels as sm
            # df = your DataFrame
            endog = df.suicides_number
            endog.index = pd.period_range("1990", "2015", freq="Y") 
            # Construct the (very simple) AR model
            mod = sm.tsa.SARIMAX(endog, order=(1, 0, 0), t
            Python3 - How does using `super` inside a method being overridden works (more in body)
            Pythondot img3Lines of Code : 2dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            # keep method for docstring for now
            Create an ARIMA(5, d, q) without the AR(3) term in Python
            Pythondot img4Lines of Code : 6dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from statsmodels.tsa.arima.model import ARIMA
            model = ARIMA(df, order=([1, 2, 4, 5], 1, 2))
            model_fit =
            Error when trying to use seasonal_decompose from Statsmodels
            Pythondot img5Lines of Code : 2dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            result = seasonal_decompose(data['Revenue Index'], model='multiplicative', period=12)
            Fitting of GLM with statsmodels
            Pythondot img6Lines of Code : 4dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            sm.GLM(y, X, family=sm.families.Binomial(link=sm.families.links.loglog()))
            copy iconCopy
            name: Python3.9 
              - defaults
              - numpy
              - pandas
              - matplotlib
              - pip
              - python=3.9.*      
              - python-dateutil
              - pytz
              - scikit-learn
              - scipy
              - statsmodels
              - xlrd
              - openpyxl
              - lxml
              - html5lib
            Why this command cannot change figure size?
            Pythondot img8Lines of Code : 5dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            result = seasonal_decompose(series, model='additive', period=1)
            fig = result.plot()
            fig.set_size_inches(15, 8)
            Does it noise included in predicted and fitted value in statsmodel?
            Pythondot img9Lines of Code : 2dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            df_results.params * exog
            Cannot import name '_centered' from 'scipy.signal.signaltools'
            Pythondot img10Lines of Code : 13dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import  scipy.signal.signaltools
            def _centered(arr, newsize):
                # Return the center newsize portion of the array.
                newsize = np.asarray(newsize)
                currsize = np.array(arr.shape)
                startind = (currsize - newsize) // 2
                endind =

            Community Discussions


            How to install Python statsmodels on Apple M1?
            Asked 2022-Mar-22 at 15:53

            I cannot figure out how to install statsmodels on my M1 machine. After following the instructions in similar threads about scipy and numpy issues with M1, I am able to install these, but cannot install statsmodels.

            Statsmodels issues were also raised here, but unresolved:

            python --version Python 3.8.9

            pip --version pip 21.3.1

            The command pip install statsmodels==0.13.1 leads to the error message:

            ERROR: Could not find a version that satisfies the requirement statsmodels==0.13.1

            Has anyone managed to install it?

            Thank you!



            Answered 2021-Dec-29 at 19:24

            Have you tried installing it from conda-forge? This package page shows that there's a osx-arm64 version available.

            You can install Miniforge (or Mambaforge, if you prefer) for Apple Silicon platforms from the conda-forge GitHub repo. Then just follow the installation instructions and create an environment to install statsmodels into.

            Unfortunately, I don't have an M1 machine so I can't test if it's working.



            How to install local package with conda
            Asked 2022-Feb-05 at 04:16

            I have a local python project called jive that I would like to use in an another project. My current method of using jive in other projects is to activate the conda env for the project, then move to my jive directory and use python install. This works fine, and when I use conda list, I see everything installed in the env including jive, with a note that jive was installed using pip.

            But what I really want is to do this with full conda. When I want to use jive in another project, I want to just put jive in that projects environment.yml.

            So I did the following:

            1. write a simple meta.yaml so I could use conda-build to build jive locally
            2. build jive with conda build .
            3. I looked at the tarball that was produced and it does indeed contain the jive source as expected
            4. In my other project, add jive to the dependencies in environment.yml, and add 'local' to the list of channels.
            5. create a conda env using that environment.yml.

            When I activate the environment and use conda list, it lists all the dependencies including jive, as desired. But when I open python interpreter, I cannot import jive, it says there is no such package. (If use python install, I can import it.) How can I fix the build/install so that this works?

            Here is the meta.yaml, which lives in the jive project top level directory:



            Answered 2022-Feb-05 at 04:16

            The immediate error is that the build is generating a Python 3.10 version, but when testing Conda doesn't recognize any constraint on the Python version, and creates a Python 3.9 environment.

            I think the main issue is that python >=3.5 is only a valid constraint when doing noarch builds, which this is not. That is, once a package builds with a given Python version, the version must be constrained to exactly that version (up through minor). So, in this case, the package is built with Python 3.10, but it reports in its metadata that it is compatible with all versions of Python 3.5+, which simply isn't true because Conda Python packages install the modules into Python-version-specific site-packages (e.g., lib/python-3.10/site-packages/jive).

            Typically, Python versions are controlled by either the --python argument given to conda-build or a matrix supplied by the conda_build_config.yaml file (see documentation on "Build variants").

            Try adjusting the meta.yaml to something like



            Including parameters in state space model from statsmodels
            Asked 2022-Jan-03 at 16:00

            Building up the model from a previous post, and the helpful answer, I've subclassed the MLEModel to encapsulate the model. I'd like to allow for two parameters q1 and q2 so that the state noise covariance matrix is generalized as in Sarkka (2013)'s example 4.3 (terms re-arranged for my convention):

            I thought I would accomplish this with the update method below, but I'm running into problems with the fit method, as it returns a UFuncTypeError: Cannot cast ufunc 'multiply' output from dtype('complex128') to dtype('float64') with casting rule 'same_kind'. What am I missing here?



            Answered 2022-Jan-03 at 16:00

            The error message you are receiving is about trying to set a complex value in a dtype=float matrix. You would get the same error from:



            what does {sys.executable} do in jupyter notebook?
            Asked 2021-Dec-14 at 03:37

            I bought a book which comes with jupyter notebook. In the first chapter, it asks me to install required libraries. It use {sys.executable} -m. I never see it before. what does {sys.executable} and -m do? also why use --user at the end?

            typically, I just use ! pip install numpy==1.19.2

            Anyone can help me understand it? Thank you!



            Answered 2021-Dec-14 at 03:35

            sys.executable is refering to the Python interpreter for the current system. It comes handy when using virtual environments and have several interpreters on the same machine.

            The -m option loads and execute a module as a script, here pip.

            The --user is an option for pip install, see this answer describing its use.

            Then the !{} is jupyter-specific syntax to execute commands in a cell if I remember correctly.



            LogisticRegression from sk_learn and smf.logit() from statsmodels.formula.api return different results
            Asked 2021-Nov-28 at 14:38

            I am trying to calculate the variance of the coefficients for logistic regression using bootstrap and I am using scikit-learn and statsmodels to compare results. I am using the Default dataset from the ISLR website which can be found in the zip forlder here or here as a plain csv file. I am using the following codes to perform the bootstrap:

            Import the Dataset and create the response variable



            Answered 2021-Nov-28 at 14:38

            Although you set the C parameter to be high to minimize, sklearn by default uses lbfgs solver to find your optimal parameters while statsmodels uses newton .

            You can try doing this to get similar coefficients:



            What is Julia's equivalent ggplot code of R's?
            Asked 2021-Nov-23 at 15:47

            I would like to plot a sophisticated graph in Julia. The code below is in Julia's version using ggplot.



            Answered 2021-Nov-23 at 15:47

            I used Vega-Lite ( which is also grounded in the "Grammar of Graphics", and LinearRegression ( which provides similar features as GLM, although I think it is possible to get comparable results with the other plotting and linear regression packages. Nevertheless, I hope that this gives you a starting point.



            how to predict using statsmodels.formula.api logit
            Asked 2021-Nov-04 at 15:25

            I have the following problem. I would like to do an in-sample prediction using logit from statsmodels.formula.api.

            See my code:



            Answered 2021-Nov-04 at 15:25

            Using an example dataset:



            How to make Jupyter notebook python help function output colorful?
            Asked 2021-Sep-23 at 09:24

            I am new to Jupyter notebook and trying to see the some help about the functions. For example, when I print the help of statsmodels.OLS I got the following plain black and white help.

            Are there any python modules that colorize/beautify the help outputs?

            For example:

            • hightlight parameters names
            • highlight the code example in python syntax hightlight
            • and so on.

            If there are not some modules, what would be the starting point, to colorize the parameters and the python codes?

            The example output of help is given below:



            Answered 2021-Sep-23 at 09:24

            You can try to beautify the help using rich library (in jupyter, you can install it, using the command !pip install rich). In particular, you could study the inspect method.

            For example, with the following code:



            RandomizedSearchCV: All estimators failed to fit
            Asked 2021-Sep-07 at 19:33

            I am currently working on the "French Motor Claims Datasets freMTPL2freq" Kaggle competition ( Unfortunately I get a "NotFittedError: All estimators failed to fit" error whenever I am using RandomizedSearchCV and I cannot figure out why that is. Any help is much appreciated.



            Answered 2021-Sep-06 at 14:32

            According to your error message, KeyError: 'xgbr_regressor' the code cant find the key xgbr_regressor in your Pipeline. In your pipeline, you have defined the xgb_regressor:



            OLS fit for python with coefficient error and transformed target
            Asked 2021-Aug-12 at 22:23

            There seems to be two methods for OLS fits in python. The Sklearn one and the Statsmodel one. I have a preference for the statsmodel one because it gives the error on the coefficients via the summary() function. However, I would like to use the TransformedTargetRegressor from sklearn to log my target. It would seem that I need to choose between getting the error on my fit coefficients in statsmodel and being able to transform my target in statsmodel. Is there a good way to do both of these at the same time in either system?

            In stats model it would be done like this



            Answered 2021-Aug-06 at 09:15

            In short, Scikit learn cannot help you in calculating coefficient standard errors. However, if you opt to use it, you can just calculate the errors by yourself. In the question Python scikit learn Linear Model Parameter Standard Error @grisaitis provided a great answer explaining the main concepts behind it.

            If you only want to use a plug-and-play function that will work with sciait-learn you can use this:


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install statsmodels

            You can install using 'pip install statsmodels' or download it from GitHub, PyPI.
            You can use statsmodels like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.


            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • PyPI

            pip install statsmodels

          • CLONE
          • HTTPS


          • CLI

            gh repo clone statsmodels/statsmodels

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link