当前位置: 首页>>代码示例>>Python>>正文


Python ARIMA.fit方法代码示例

本文整理汇总了Python中statsmodels.tsa.arima_model.ARIMA.fit方法的典型用法代码示例。如果您正苦于以下问题:Python ARIMA.fit方法的具体用法?Python ARIMA.fit怎么用?Python ARIMA.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在statsmodels.tsa.arima_model.ARIMA的用法示例。


在下文中一共展示了ARIMA.fit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: forecast_by_cluster

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
    def forecast_by_cluster(self, hold_out_n, n_ahead, order, exog):
        dfit = self.ds_agg_by_c
        
        efit = efor = None
        if hold_out_n > 0:
            # hold out validation required
            dfit = dfit[:-hold_out_n]
            if (exog is not None):
                efit = exog[:-hold_out_n]
                efor = exog[-hold_out_n:]
        else:
            if (exog is not None):
                efit = exog[:-n_ahead]
                efor = exog[-n_ahead:]
        ds_c_for = np.zeros((n_ahead, self.n_clusters))

        for c in tqdm(range(self.n_clusters)):
            cdfit = dfit[:,c]
            if sum(cdfit) == 0:
                ds_c_for[:,c] = 0
                continue
            m = ARIMA(cdfit, exog = efit, order = order)
            mf = m.fit()
            f = mf.forecast(n_ahead, exog = efor, alpha = .95)[0]
            ds_c_for[:,c] = f
        
        self.ds_c_for = ds_c_for
开发者ID:l1990790120,项目名称:l1990790120.github.io,代码行数:29,代码来源:COLLEGE_ENROLLMENT_FORECAST_INST_LEVEL_vaildation_mod.py

示例2: __init__

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
class ARIMAModelResult:
    def __init__(self, autoregressive_periods, integrated_order, moving_average_model_periods, training_data, test):
        self.autoregressive_periods = autoregressive_periods
        self.integrated_order = integrated_order
        self.moving_average_model_periods = moving_average_model_periods
        self.model = ARIMA(training_data, order=(
            self.autoregressive_periods,
            self.integrated_order,
            self.moving_average_model_periods
        )
                           )
        self.fit = self.model.fit()
        self.aic = self.fit.aic
        self.predictions = self.fit.forecast(steps=len(test))[0]
        self.model_fitness = mean_squared_error(test, self.predictions)

    def __eq__(self, other):
        return self.model_fitness == other.model_fitness

    def __lt__(self, other):
        return self.model_fitness < other.model_fitness

    def __gt__(self, other):
        return self.model_fitness > other.model_fitness

    def __str__(self):
        return "Autoregressive periods: {}\nIntegraded Order: {}\nMoving Average Model Periods: {}\n Predictions: {}\nMSE: {}".format(
            self.autoregressive_periods,
            self.integrated_order,
            self.moving_average_model_periods,
            self.predictions,
            self.model_fitness
        )
开发者ID:gracegreene,项目名称:FLEXCHAIN,代码行数:35,代码来源:arima.py

示例3: ARIMA_forcast2

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
 def ARIMA_forcast2(self):
     # this approach forecast 1 data pt at a time, then add the new forecast datapoint to the training data
     # then repeat
     import warnings
     warnings.filterwarnings('ignore')
     
     # test without taking log of data
     # using rolling avg 
     y = vr_df2_ts.values
     train = vr_df2_ts.values[286:574]
     prediction = list()
     for t in range(288):
         modelY = ARIMA(y, order=(1,1,1))
         results = modelY.fit(disp=-1)
         out = results.forecast()
         yhat = out[0]
         prediction.append(yhat)
         y = np.append(y,train[t])
         
     forecast = pd.Series(prediction,index=pd.date_range(start='2017-02-09 00:00:00', periods=288,freq='5min'))
     exog = vr_df2_ts.iloc[286:574]
     exog.set_index(pd.date_range(start='2017-02-09 00:00:00', periods=288,freq='5min'),inplace=True)
     
     plt.plot(vr_df2_ts)
     plt.plot(exog,'g')
     plt.plot(forecast,'r')
开发者ID:greatObelix,项目名称:datatoolbox,代码行数:28,代码来源:timeseries.py

示例4: get_grouped_data

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
    def get_grouped_data(self, forecast=False):
        cdf = self.cumulative_sum()
        gdf = self.group_by('M')

        if cdf.shape[0] > gdf.shape[0]:
            df = cdf.to_frame()
            df.columns = ['cumulative sum']
            df['total added'] = gdf.to_frame()['event']
        else:
            df = gdf.to_frame()
            df.columns = ['total added']
            df['cumulative sum'] = cdf.to_frame()['event']

        if forecast:
            mtotals = pd.to_numeric(df['cumulative sum'], downcast='float')
            model = ARIMA(mtotals, order=(10,1,0))
            model_fit = model.fit(disp=0)
            forecast = model_fit.forecast(steps=12)
            dates = pd.date_range('2017-04-30', '2018-06-01', freq='M')
            records = zip([x.to_datetime() for x in dates], forecast[0])
            ndf = pd.DataFrame.from_records(records)
            ndf.columns = ['date', 'forecast']
            ndf.set_index(['date'], inplace=True)
            df = pd.concat([df, ndf], axis=1)

        return df
开发者ID:jctanner,项目名称:pr-triage,代码行数:28,代码来源:statsmaker.py

示例5: arima_predict

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
def arima_predict(train_dat, n_predictions, p=2, d=0, q=0):
    arima = ARIMA(np.array(train_dat).astype(np.float), [p, d, q])
    diffed_logged_results = arima.fit(trend='c', disp=False)
    preds = diffed_logged_results.predict(len(train_dat),
                                          len(train_dat) + n_predictions - 1,
                                          exog=None, dynamic=False)
    return preds
开发者ID:boke168,项目名称:M3_ARIMA,代码行数:9,代码来源:M3+Arima.py

示例6: arimamodel

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
def arimamodel(ts):
	ts_log, ts_log_diff = trend(ts)
	model = ARIMA(ts_log, order = (2,1,2))
	result_ARIMA = model.fit(disp = -1)

	m = ARIMA(ts, order = (2,1,2)).fit()

	arimares = ARMAResults(m, params = '')

	pre = arimares.forcast(steps = 60)


	# pre = m.predict('20150901', '20151230', dynamic = True)
	print pre

	# prediction back to the original scale
	predictions_ARIMA = backorg(result_ARIMA, ts_log)
	plt.plot(predictions_ARIMA)
	# print (predictions_ARIMA - ts)[40:80]

	plt.plot(ts, color = 'red')

	# plt.plot(ts_log_diff)
	# plt.plot(result_ARIMA.fittedvalues, color = 'red')
	plt.title('RSS: %.4F' % np.sum((result_ARIMA.fittedvalues - ts_log_diff)**2))
	plt.show()
开发者ID:pthaike,项目名称:comp,代码行数:28,代码来源:process.py

示例7: mamodel

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
def mamodel(ts):
	ts_log, ts_log_diff = trend(ts)
	model = ARIMA(ts_log, order = (0,1,1))
	result_MA = model.fit(disp = -1)
	plt.plot(ts_log_diff)
	plt.plot(result_MA.fittedvalues, color = 'red')
	plt.title('RSS: %.4F' % np.sum((result_MA.fittedvalues - ts_log_diff)**2))
	plt.show(block = False)
开发者ID:pthaike,项目名称:comp,代码行数:10,代码来源:process.py

示例8: armodel

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
def armodel(ts):
	ts_log, ts_log_diff = trend(ts)
	model = ARIMA(ts_log, order = (1,1,0))
	result_AR = model.fit(disp = -1)
	plt.plot(ts_log_diff)
	plt.plot(result_AR.fittedvalues, color = 'red')
	# pdb.set_trace()
	plt.title('RSS: %.4F' % np.sum((result_AR.fittedvalues - ts_log_diff)**2))
	plt.show(block = False)
开发者ID:pthaike,项目名称:comp,代码行数:11,代码来源:process.py

示例9: ARIMA_fit

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
 def ARIMA_fit(self):
     # order=(p,d,q) AR and MA can also be modeled separately by enter 0 for either p or q
     model = ARIMA(ts_log, order=(5,1,5))
     self.results_ARIMA = model.fit(disp=-1)
     
     print(results_ARIMA.summary())
     
     plt.plot(ts_log_diff)
     plt.plot(results_ARIMA.fittedvalues, color='r')
     plt.title('RSS: %.4f'% sum((results_ARIMA.fittedvalues-ts_log_diff['in_tpkts'])**2))
开发者ID:greatObelix,项目名称:datatoolbox,代码行数:12,代码来源:timeseries.py

示例10: ARIMA_fun

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
def ARIMA_fun( data ):
    lag_pacf = pacf( data, nlags=20, method='ols' )
    lag_acf, ci2, Q  = acf( data, nlags=20 , qstat=True, unbiased=True)

    model = ARIMA(orig_data, order=(1, 1, int(ci2[0]) ) )  
    results_ARIMA = model.fit(disp=-1)
    plt.subplot(121)
    plt.plot( data )
    plt.plot(results_ARIMA.fittedvalues)
    #plt.show()
    return results_ARIMA.fittedvalues
开发者ID:s4hackathons,项目名称:singularity,代码行数:13,代码来源:arima.py

示例11: fit

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
 def fit(self):
   if len(self.df) < self.t_window: return None
   model = ARIMA(self.df, order=(2, 1, 1))
   results_ARIMA = model.fit(disp=-1)
   forecast = results_ARIMA.predict(start = self.t_window, end= self.t_window+2, dynamic= True)
   forecast = forecast.cumsum()
   predictions_ARIMA_log = pd.Series(self.df.ix[self.t_window-1], index=forecast.index)
   predictions_ARIMA_log = predictions_ARIMA_log.add(forecast,fill_value=0)
   predictions_ARIMA = np.exp(predictions_ARIMA_log)
   #print self.df
   return predictions_ARIMA
开发者ID:pandey957,项目名称:officework,代码行数:13,代码来源:series_arima.py

示例12: objfunc

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
    def objfunc(order, *params):
        series = params

        try:
            mod = ARIMA(series, order, exog=None)
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                res = mod.fit(disp=0, solver='bfgs', maxiter=5000)
        except:
            return float('inf')
        if math.isnan(res.aic):
            return float('inf')
        return res.aic
开发者ID:IASA2x,项目名称:sys-an-labs,代码行数:15,代码来源:forecast_arima.py

示例13: pridictNextNdays

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
    def pridictNextNdays(self,train):
        timeSerize = train[self.selected]
        timeSerize = timeSerize[self.start_train:self.end_train]
        model = ARIMA(timeSerize, order=(self.p,self.d,self.q), freq='D') # build a model
        fitting = model.fit(disp=False)
        forecast, fcasterr, conf_int = fitting.forecast(steps=self.next_ndays, alpha=.05)

        # params = fitting.params
        # residuals = fitting.resid
        # p = fitting.k_ar
        # q = fitting.k_ma
        # k_exog = fitting.k_exog
        # k_trend = fitting.k_trend
        # forecast = _arma_predict_out_of_sample(params,self.next_ndays,residuals, p, q, k_trend, k_exog, endog=timeSerize, exog=None, start=len(timeSerize))
        return  forecast
开发者ID:ChenLiangbo,项目名称:iloveme,代码行数:17,代码来源:MyArimaModel.py

示例14: predict_arima_next_days

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
    def predict_arima_next_days(self, item):
        ts = df_train[item]
        ts = ts.sort_index() # sorting index Date
        ts_last_day = ts[self.fc] # real last data
        ts = ts[0:self.fc] # index 0 until last data - 1

        model = ARIMA(ts, order=(self.p, self.d, self.q)) # build a model
        fitting = model.fit(disp=False)

        # n_days forecasting
        forecast, fcasterr, conf_int = fitting.forecast(steps=self.n_days, alpha=.05)
        # ts:          history until 1 day before self.fc
        # ts[self.fc]: last day
        # forecast:    1 day forecast (time equalto ts[self.fc])
        return ts, ts_last_day, forecast
开发者ID:ChenLiangbo,项目名称:iloveme,代码行数:17,代码来源:getDataWithArima.py

示例15: testArima

# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import fit [as 别名]
 def testArima(self,train):
     realSerize = train[self.selected]
     timeSerize = realSerize[self.start_train:self.end_train]
     realData = train[self.selected][self.end_train:self.next_ndays]
     model = ARIMA(timeSerize, order=(self.p,self.d, self.q)) # build a model
     fitting = model.fit(disp=False)
     forecast, fcasterr, conf_int = fitting.forecast(steps=self.next_ndays, alpha=.05)
     # params = fitting.params
     # residuals = fitting.resid
     # p = fitting.k_ar
     # q = fitting.k_ma
     # k_exog = fitting.k_exog
     # k_trend = fitting.k_trend
     # forecast = _arma_predict_out_of_sample(params,self.next_ndays,residuals, p, q, k_trend, k_exog, endog=timeSerize, exog=None, start=len(timeSerize))
     return  {'real':list(realSerize)[self.end_train:self.end_train+self.next_ndays],'pridiction':forecast}
开发者ID:ChenLiangbo,项目名称:iloveme,代码行数:17,代码来源:MyArimaModel.py


注:本文中的statsmodels.tsa.arima_model.ARIMA.fit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。