コード例 #1
0
def priceActual():
	for k,v in priceDic.items():
		print(k,v)
		series = pd.read_csv('../Data/Final/Wholesale/'+k,names = [0.1],index_col=0,header=None)
		near_file = v[:-4]+'.npy'
		near = np.load('../Data/Results/Near/'+near_file)
		daysToForecast = 30
		series_train = np.squeeze(series.values)
		n = len(series_train)
		near_train =  near[:n]
		near_test = near[-30:]
		trans = FourierFeaturizer(365.25, 1)
		y_prime, exogen = trans.fit_transform(series_train)
		exogen = exogen.mul(pd.Series(series_train),axis=0)
		futureExog =  trans.transform(y = series_train, n_periods = 30)
		futureExog = pd.DataFrame(futureExog[1])
		futureExog = futureExog.mul(pd.Series(near_test),axis=0)
		exogen['near'] = near_train
		futureExog['near'] = near_test
		#print('MODel searching')
		model=pm.arima.auto_arima(series_train, exogenous = exogen, start_p=0, d=None, start_q=0, max_p=3, max_d=1, max_q=3,start_P=0, D=None, start_Q=0, max_P=2, max_D=1, max_Q=2,suppress_warnings =True,seasonal=True,max_order=4,m=7,stepwise=True) 
		model.fit(series_train)
		pred = (model.predict(daysToForecast,exogenous = futureExog))
		series = np.concatenate((series_train,pred),axis=0)
		series = pd.DataFrame(series)
		series.index = pd.date_range(start = '2006-01-01',periods = len(series))
		fileName = '../Data/Results/Actual/'+str(k)
		#print(fileName)
		series.to_csv(fileName)
コード例 #2
0
def forecast(series,near):

	train_near = np.squeeze(near.values[:-30])
	train_series = np.squeeze(series.values[:len(train_near)])

	test_near = np.squeeze(near.values[-30:])
	test_series = np.squeeze(series.values[-30:])
	df = pd.DataFrame(columns=['aic','nonSeasonal','seasonal','k'])
	for i in range(25):
		print('value of i is:',i)
		nonSeasonalParams = ch(nonSeasonal)
		seasonalParams = ch(seasonal)
		val = sum(list(nonSeasonalParams)) + sum(list(seasonalParams))
		#try:
		if(val>8):
			continue
		seasonalParams = seasonalParams + (7,)
		#print(nonSeasonalParams,seasonalParams)
		try:
			trans = FourierFeaturizer(365.25, 1)
			y_prime, exogen = trans.fit_transform(train_series)
			#exogen = exogen.mul(pd.Series(train_series),axis=0)
			exogen['near'] = train_near
			model = sm.tsa.statespace.SARIMAX(endog = train_series, exog = train_near, order = nonSeasonalParams, seasonal_order = seasonalParams,initialization='approximate_diffuse',enforce_stationarity=False) 
			res = model.fit(disp=False)
			#print(res.aic)
			to_append = [res.aic,nonSeasonalParams,seasonalParams,1]
			a_series = pd.Series(to_append, index = df.columns)
			df = df.append(a_series, ignore_index=True)
		except:
			print('inside except block now.....')
			x = pd.Series([10000000,(1,1,1),(1,1,1),1],index = df.columns)
			df = df.append(x, ignore_index=True)
	x = pd.Series([10000000,(1,1,1),(1,1,1),1],index = df.columns)
	df = df.append(x, ignore_index=True)
	print('df is :',df)
	dx = (df[df.aic == df.aic.min()])
	dx.reset_index(inplace=True,drop=True)
	print('baest parameters are:',dx)
	value = [dx.iloc[0][0],dx.iloc[0][1],dx.iloc[0][2],dx.iloc[0][3]]
	print('final parameters are:',value)
	return value
コード例 #3
0
                     header=None)
near = pd.read_csv('../Data/Final/Wholesale/YeolaPrice.csv',
                   names=[0.1],
                   index_col=0,
                   header=None)

train_near = np.squeeze(near.values[:-30])
train_series = np.squeeze(series.values[:len(train_near)])

test_near = np.squeeze(near.values[-30:])
test_series = np.squeeze(series.values[-30:])

for k in range(1, 4):
    print(k)
    trans = FourierFeaturizer(365.25, k)
    y_prime, exogen = trans.fit_transform(train_series)
    exogen = exogen.mul(pd.Series(train_series), axis=0)
    exogen['near'] = train_near
    model = pm.arima.auto_arima(train_series,
                                exogenous=pd.DataFrame(exogen),
                                start_p=0,
                                d=None,
                                start_q=0,
                                max_p=5,
                                max_d=2,
                                max_q=5,
                                start_P=0,
                                D=None,
                                start_Q=0,
                                max_P=5,
                                max_D=2,