Example #1
0
rcParams['figure.figsize']=15,6

dateparse=lambda dates:pd.datetime.strptime(dates,'%Y-%m')
date=pd.read_csv('/home/ycc/Documents/data/AirPassengers.csv',parse_dates="Month",index_col="Month",date_parser=dateparse)

sampled_FC1=rsd.re_sam_data('FC1')
sampled_FC2=rsd.re_sam_data('FC2')

# divide the data into time and value
sampled_FC1_value=sampled_FC1[:,1]
sampled_FC2_value=sampled_FC2[:,1]
sampled_FC1_time=sampled_FC1[:,0]
sampled_FC2_time=sampled_FC2[:,0]

# implement the rloess filter
FC2_value_filtered=rloess.lowess(sampled_FC2_time,sampled_FC2_value,f=0.9,iter=3)

#plt.plot(sampled_FC2_value)
#plt.plot(FC2_value_filtered)
#plt.show()


ts_index_FC2=pd.date_range('1800-01-01','1970-03-01',freq='M')

ts_all=pd.Series(sampled_FC2_value,index=ts_index_FC2)

expweighted_avg_1=pd.ewma(ts_all,halflife=12)

plt.plot(ts_all)
plt.plot(expweighted_avg_1)
plt.show()
Example #2
0
from matplotlib.pylab import rcParams
import pdb
rcParams['figure.figsize']=15,6

sampled_FC2=rsd.re_sam_data('FC2')

FC2_time=sampled_FC2[:,0]
FC2_value=sampled_FC2[:,1]

ts_index_FC2=pd.date_range('1800-01-01','1970-03-01',freq='M')

ts_index_FC2_1=pd.date_range('1800-01-01','1900-03-01',freq='M')


FC2_learn_rloessed=rloess.lowess(FC2_time[0:1202],FC2_value[0:1202],f=0.9)
FC2_all_rloessed=rloess.lowess(FC2_time,FC2_value,f=0.9)

residual_FC2_learn=FC2_value[0:1202]-FC2_learn_rloessed
residual_FC2_all=FC2_value-FC2_all_rloessed


ts_all=pd.Series(residual_FC2_all,index=ts_index_FC2)
ts_learn=pd.Series(residual_FC2_learn,index=ts_index_FC2_1)


## -------------------------------------stationary the ts ---------------------------------------------------

# method 1 : remove the trend and seasonality with differencing

ts_learn_diff=ts_learn-ts_learn.shift()   # first order differencing