Package: tsmoothie
tsmoothieA python library for time-series smoothing and outlier detection in a vectorized way.Overviewtsmoothie computes, in a fast and efficient way, the smoothing of single or multiple time-series.The smoothing techniques available are:Exponential SmoothingConvolutional Smoothing with various window types (constant, hanning, hamming, bartlett, blackman)Spectral Smoothing with Fourier TransformPolynomial SmoothingSpline Smoothing of various kind (linear, cubic, natural cubic)Gaussian SmoothingBinner SmoothingLOWESSSeasonal Decompose Smoothing of various kind (convolution, lowess, natural cubic spline)Kalman Smoothing with customizable components (level, trend, seasonality, long seasonality)tsmoothie provides the calculation of intervals as result of the smoothing process. This can be useful to identify outliers and anomalies in time-series.In relation to the smoothing method used, the interval types available are:sigma intervalsconfidence intervalspredictions intervalskalman intervalstsmoothie can carry out a sliding smoothing approach to simulate an online usage. This is possible splitting the time-series into equal sized pieces and smoothing them independently. As always, this functionality is implemented in a vectorized way through theWindowWrapperclass.tsmoothie can operate time-series bootstrap through theBootstrappingWrapperclass.The supported bootstrap algorithms are:none overlapping block bootstrapmoving block bootstrapcircular block bootstrapstationary bootstrapMediaBlog Posts:Time Series Smoothing for better ClusteringTime Series Smoothing for better ForecastingReal-Time Time Series Anomaly DetectionExtreme Event Time Series PreprocessingTime Series Bootstrap in the age of Deep LearningInstallationpipinstall--upgradetsmoothieThe module depends only on NumPy, SciPy and simdkalman. Python 3.6 or above is supported.Usage:smoothingBelow a couple of examples of how tsmoothie works. Full examples are available in thenotebooks folder.# import librariesimportnumpyasnpimportmatplotlib.pyplotaspltfromtsmoothie.utils_funcimportsim_randomwalkfromtsmoothie.smootherimportLowessSmoother# generate 3 randomwalks of lenght 200np.random.seed(123)data=sim_randomwalk(n_series=3,timesteps=200,process_noise=10,measure_noise=30)# operate smoothingsmoother=LowessSmoother(smooth_fraction=0.1,iterations=1)smoother.smooth(data)# generate intervalslow,up=smoother.get_intervals('prediction_interval')# plot the smoothed timeseries with intervalsplt.figure(figsize=(18,5))foriinrange(3):plt.subplot(1,3,i+1)plt.plot(smoother.smooth_data[i],linewidth=3,color='blue')plt.plot(smoother.data[i],'.k')plt.title(f"timeseries{i+1}");plt.xlabel('time')plt.fill_between(range(len(smoother.data[i])),low[i],up[i],alpha=0.3)# import librariesimportnumpyasnpimportmatplotlib.pyplotaspltfromtsmoothie.utils_funcimportsim_seasonal_datafromtsmoothie.smootherimportDecomposeSmoother# generate 3 periodic timeseries of lenght 300np.random.seed(123)data=sim_seasonal_data(n_series=3,timesteps=300,freq=24,measure_noise=30)# operate smoothingsmoother=DecomposeSmoother(smooth_type='lowess',periods=24,smooth_fraction=0.3)smoother.smooth(data)# generate intervalslow,up=smoother.get_intervals('sigma_interval')# plot the smoothed timeseries with intervalsplt.figure(figsize=(18,5))foriinrange(3):plt.subplot(1,3,i+1)plt.plot(smoother.smooth_data[i],linewidth=3,color='blue')plt.plot(smoother.data[i],'.k')plt.title(f"timeseries{i+1}");plt.xlabel('time')plt.fill_between(range(len(smoother.data[i])),low[i],up[i],alpha=0.3)All the available smoothers are fully integrable with sklearn (seehere).Usage:bootstrap# import librariesimportnumpyasnpimportmatplotlib.pyplotaspltfromtsmoothie.utils_funcimportsim_seasonal_datafromtsmoothie.smootherimportConvolutionSmootherfromtsmoothie.bootstrapimportBootstrappingWrapper# generate a periodic timeseries of lenght 300np.random.seed(123)data=sim_seasonal_data(n_series=1,timesteps=300,freq=24,measure_noise=15)# operate bootstrapbts=BootstrappingWrapper(ConvolutionSmoother(window_len=8,window_type='ones'),bootstrap_type='mbb',block_length=24)bts_samples=bts.sample(data,n_samples=100)# plot the bootstrapped timeseriesplt.figure(figsize=(13,5))plt.plot(bts_samples.T,alpha=0.3,c='orange')plt.plot(data[0],c='blue',linewidth=2)ReferencesPolynomial, Spline, Gaussian and Binner smoothing are carried out building a regression on custom basis expansions. These implementations are based on the amazing intuitions of Matthew Drury availablehereTime Series Modelling with Unobserved Components, Matteo M. PelagattiBootstrap Methods in Time Series Analysis, Fanny BergstrÃ¶m, Stockholms universitet