To make time series data more smooth in Pandas, we can use the exponentially weighted window functions and calculate the exponentially weighted average.

First, I am going to load a dataset which contains Bitcoin prices recorded every minute.

data = pd.read_csv('../input/bitstampUSD_1-min_data_2012-01-01_to_2019-03-13.csv')
data['date'] = pd.to_datetime(data['Timestamp'], unit="s")

input_data = data[["date", "Close"]]

subset = input_data[input_data["date"] >= "2019-01-01"]
subset.set_index('date', inplace=True)

I want to plot their daily weighted average, so I must compress 3600 values into one using this function:

subset['Close'].ewm(span = 3600).mean()

We see that by default the adjusted version of the weighted average function is used, so the first element of the time series is not 0.

Stop AI Hallucinations Before They Cost You.
Join engineering leaders getting weekly tactics to prevent failure in customer-facing AI systems. Straight from real production deployments.

Finally, I can plot the original data and both the smoothed time series:

subset['Close'].plot(style = 'r--', label = 'Bitcoin prices')
subset['Close'].ewm(span = 3600).mean().plot(style = 'b', label = ' Exponential moving average')

plt.legend()
plt.title("Bitcoin prices")
plt.xlabel('Date')
plt.ylabel('Price (USD)')
Stop AI Hallucinations Before They Cost You.
Join engineering leaders getting weekly tactics to prevent failure in customer-facing AI systems. Straight from real production deployments.
Older post

Which hyperparameters of deep learning model are important and how to find them

How to speed up finding the right hyperparameters of a machine learning model

Newer post

How to increase accuracy of a deep learning model

Debugging a machine learning model

Engineering leaders: Is your AI failing in production? Take the 10-minute assessment
>
×
Stop AI Hallucinations Before They Cost You.
Join engineering leaders getting weekly tactics to prevent failure in customer-facing AI systems. Straight from real production deployments.