Reader small image

You're reading from  Deep Learning for Time Series Cookbook

Product typeBook
Published inMar 2024
PublisherPackt
ISBN-139781805129233
Edition1st Edition
Right arrow
Authors (2):
Vitor Cerqueira
Vitor Cerqueira
author image
Vitor Cerqueira

​Vitor Cerqueira is a time series researcher with an extensive background in machine learning. Vitor obtained his Ph.D. degree in Software Engineering from the University of Porto in 2019. He is currently a Post-Doctoral researcher in Dalhousie University, Halifax, developing machine learning methods for time series forecasting. Vitor has co-authored several scientific articles that have been published in multiple high-impact research venues.
Read more about Vitor Cerqueira

Luís Roque
Luís Roque
author image
Luís Roque

Luís Roque, is the Founder and Partner of ZAAI, a company focused on AI product development, consultancy, and investment in AI startups. He also serves as the Vice President of Data & AI at Marley Spoon, leading teams across data science, data analytics, data product, data engineering, machine learning operations, and platforms. In addition, he holds the position of AI Advisor at CableLabs, where he contributes to integrating the broadband industry with AI technologies. Luís is also a Ph.D. Researcher in AI at the University of Porto's AI&CS lab and oversees the Data Science Master's program at Nuclio Digital School in Barcelona. Previously, he co-founded HUUB, where he served as CEO until its acquisition by Maersk.
Read more about Luís Roque

View More author details
Right arrow

Resampling a multivariate time series

This recipe revisits the topic of resampling but focuses on multivariate time series. We’ll explain why resampling can be a bit tricky for multivariate time series due to the eventual need to use distinct summary statistics for different variables.

Getting ready

When resampling a multivariate time, you may need to apply different summary statistics depending on the variable. For example, you may want to sum up the solar radiation observed at each hour to get a sense of how much power you could generate. Yet, taking the average, instead of the sum, is more sensible when summarizing wind speed because this variable is not cumulative.

How to do it…

We can pass a Python dictionary that details which statistic should be applied to each variable. Then, we can pass this dictionary to the agg () method, as follows:

stat_by_variable = {
    'Incoming Solar': 'sum',
    'Wind Dir': 'mean',
    'Snow Depth': 'sum',
    'Wind Speed': 'mean',
    'Dewpoint': 'mean',
    'Precipitation': 'sum',
    'Vapor Pressure': 'mean',
    'Relative Humidity': 'mean',
    'Air Temp': 'max',
}
data_daily = data.resample('D').agg(stat_by_variable)

We aggregate the time series into a daily periodicity using different summary statistics. For example, we want to sum up the solar radiation observed each day. For the air temperature variable (Air Temp), we take the maximum value observed each day.

How it works…

By using a dictionary to pass different summary statistics, we can adjust the frequency of the time series in a more flexible way. Note that if you wanted to apply the mean for all variables, you would not need a dictionary. A simpler way would be to run data.resample('D').mean().

Previous PageNext Page
You have been reading a chapter from
Deep Learning for Time Series Cookbook
Published in: Mar 2024Publisher: PacktISBN-13: 9781805129233
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Vitor Cerqueira

​Vitor Cerqueira is a time series researcher with an extensive background in machine learning. Vitor obtained his Ph.D. degree in Software Engineering from the University of Porto in 2019. He is currently a Post-Doctoral researcher in Dalhousie University, Halifax, developing machine learning methods for time series forecasting. Vitor has co-authored several scientific articles that have been published in multiple high-impact research venues.
Read more about Vitor Cerqueira

author image
Luís Roque

Luís Roque, is the Founder and Partner of ZAAI, a company focused on AI product development, consultancy, and investment in AI startups. He also serves as the Vice President of Data & AI at Marley Spoon, leading teams across data science, data analytics, data product, data engineering, machine learning operations, and platforms. In addition, he holds the position of AI Advisor at CableLabs, where he contributes to integrating the broadband industry with AI technologies. Luís is also a Ph.D. Researcher in AI at the University of Porto's AI&CS lab and oversees the Data Science Master's program at Nuclio Digital School in Barcelona. Previously, he co-founded HUUB, where he served as CEO until its acquisition by Maersk.
Read more about Luís Roque