Using statsmodel estimations with scikit-learn cross validation, is it possible?

Indeed, you cannot use cross_val_score directly on statsmodels objects, because of different interface: in statsmodels training data is passed directly into the constructor a separate object contains the result of model estimation However, you can write a simple wrapper to make statsmodels objects look like sklearn estimators: import statsmodels.api as sm from sklearn.base import BaseEstimator, … Read more

ImportError: No module named statsmodels

you shouldn’t untar it to /usr/local/lib/python2.7/dist-packages (you could use any temporary directory) you might have used by mistake a different python executable e.g., /usr/bin/python instead of the one corresponding to /usr/local/lib/python2.7 You should use pip corresponding to a desired python version (use python -V to check the version) to install it: $ python -m pip … Read more

Converting statsmodels summary object to Pandas Dataframe

The answer from @Michael B works well, but requires “recreating” the table. The table itself is actually directly available from the summary().tables attribute. Each table in this attribute (which is a list of tables) is a SimpleTable, which has methods for outputting different formats. We can then read any of those formats back as a … Read more

Highest Posterior Density Region and Central Credible Region

From my understanding “central credible region” is not any different from how confidence intervals are calculated; all you need is the inverse of cdf function at alpha/2 and 1-alpha/2; in scipy this is called ppf ( percentage point function ); so as for Gaussian posterior distribution: >>> from scipy.stats import norm >>> alpha = .05 … Read more

What’s the difference between pandas ACF and statsmodel ACF?

The difference between the Pandas and Statsmodels version lie in the mean subtraction and normalization / variance division: autocorr does nothing more than passing subseries of the original series to np.corrcoef. Inside this method, the sample mean and sample variance of these subseries are used to determine the correlation coefficient acf, in contrary, uses the … Read more

How to extract the regression coefficient from statsmodels.api?

You can use the params property of a fitted model to get the coefficients. For example, the following code: import statsmodels.api as sm import numpy as np np.random.seed(1) X = sm.add_constant(np.arange(100)) y = np.dot(X, [1,2]) + np.random.normal(size=100) result = sm.OLS(y, X).fit() print(result.params) will print you a numpy array [ 0.89516052 2.00334187] – estimates of intercept … Read more