statsmodels

AttributeError: module 'statsmodels.formula.api' has no attribute 'OLS'

青春壹個敷衍的年華 提交于 2020-02-14 05:45:48
问题 I am trying to use Ordinary Least Squares for multivariable regression. But it says that there is no attribute 'OLS' from statsmodels. formula. api library. I am following the code from a lecture on Udemy The code is as follows: import statsmodels.formula.api as sm X_opt = X[:,[0,1,2,3,4,5]] #OrdinaryLeastSquares regressor_OLS = sm.OLS(endog = y, exog = X_opt).fit( The error is as follows: AttributeError Traceback (most recent call last) <ipython-input-19-3bdb0bc861c6> in <module>() 2 X_opt =

What is first value that is passed into StatsModels predict function?

邮差的信 提交于 2020-01-25 22:04:49
问题 I have the following OLS model from StatsModels: X = df['Grade'] y = df['Results'] X = statsmodels.tools.tools.add_constant(X) mod = sm.OLS(y,X) results = mod.fit() When trying to predict a new Y value for an X value of 4, I have to pass the following: results.predict([1,4]) I don't understand why an array with the first value being '1' needs to be passed in order for the predict function to work correctly. Why do I need to include a 1 instead of just saying: results.predict([4]) I'm not

What is first value that is passed into StatsModels predict function?

六月ゝ 毕业季﹏ 提交于 2020-01-25 22:04:22
问题 I have the following OLS model from StatsModels: X = df['Grade'] y = df['Results'] X = statsmodels.tools.tools.add_constant(X) mod = sm.OLS(y,X) results = mod.fit() When trying to predict a new Y value for an X value of 4, I have to pass the following: results.predict([1,4]) I don't understand why an array with the first value being '1' needs to be passed in order for the predict function to work correctly. Why do I need to include a 1 instead of just saying: results.predict([4]) I'm not

Johansen cointegration test in python

你离开我真会死。 提交于 2020-01-22 14:50:49
问题 I can't find any reference on funcionality to perform Johansen cointegration test in any Python module dealing eith statistics and time series analysis (pandas and statsmodel). Does anybpdy know if there's some code around that can perform such a test for cointegration among time series? Thanks for your help, Maruizio 回答1: statsmodels doesn't have a Johansen cointegration test. And, I have never seen it in any other python package either. statsmodels has VAR and structural VAR, but no VECM

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

不问归期 提交于 2020-01-22 04:36:09
问题 I'm calculating the Autocorrelation Function for a stock's returns. To do so I tested two functions, the autocorr function built into Pandas, and the acf function supplied by statsmodels.tsa . This is done in the following MWE: import pandas as pd from pandas_datareader import data import matplotlib.pyplot as plt import datetime from dateutil.relativedelta import relativedelta from statsmodels.tsa.stattools import acf, pacf ticker = 'AAPL' time_ago = datetime.datetime.today().date() -

Using describe() with weighted data — mean, standard deviation, median, quantiles

走远了吗. 提交于 2020-01-20 06:01:54
问题 I'm fairly new to python and pandas (from using SAS as my workhorse analytical platform), so I apologize in advance if this has already been asked / answered. (I've searched through the documentation as well as this site searching for answer and haven't been able to find something yet.) I've got a dataframe (called resp) containing respondent level survey data. I want to perform some basic descriptive statistics on one of the fields (called anninc [short for annual income]). resp["anninc"]

Using describe() with weighted data — mean, standard deviation, median, quantiles

一曲冷凌霜 提交于 2020-01-20 06:00:06
问题 I'm fairly new to python and pandas (from using SAS as my workhorse analytical platform), so I apologize in advance if this has already been asked / answered. (I've searched through the documentation as well as this site searching for answer and haven't been able to find something yet.) I've got a dataframe (called resp) containing respondent level survey data. I want to perform some basic descriptive statistics on one of the fields (called anninc [short for annual income]). resp["anninc"]

Using describe() with weighted data — mean, standard deviation, median, quantiles

烈酒焚心 提交于 2020-01-20 06:00:05
问题 I'm fairly new to python and pandas (from using SAS as my workhorse analytical platform), so I apologize in advance if this has already been asked / answered. (I've searched through the documentation as well as this site searching for answer and haven't been able to find something yet.) I've got a dataframe (called resp) containing respondent level survey data. I want to perform some basic descriptive statistics on one of the fields (called anninc [short for annual income]). resp["anninc"]

Why can't I import statsmodels directly?

末鹿安然 提交于 2020-01-14 14:35:13
问题 I'm certainly missing something very obvious here, but why does this work: a = [0.2635,0.654654,0.365,0.4545,1.5465,3.545] import statsmodels.robust as rb print rb.scale.mad(a) 0.356309343367 but this doesn't: import statsmodels as sm print sm.robust.scale.mad(a) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-5-1ce0c872b0be> in <module>() ----> 1 print statsmodels.robust.scale.mad(a) AttributeError:

R Arima works but Python statsmodels SARIMAX throws invertibility error

混江龙づ霸主 提交于 2020-01-14 09:02:46
问题 I am comparing SARIMAX fitting results between R (3.3.1) forecast package (7.3) and Python's (3.5.2) statsmodels (0.8). The R-code is: library(forecast) data("AirPassengers") Arima(AirPassengers, order=c(2,1,1), seasonal=list(order=c(0,1,0), period=12))$aic [1] 1017.848 The Python code is: from statsmodels.tsa.statespace import sarimax import pandas as pd AirlinePassengers = pd.Series([112,118,132,129,121,135,148,148,136,119,104,118,115,126, 141,135,125,149,170,170,158,133,114,140,145,150,178