Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Deep Learning for Time Series Cookbook

You're reading from  Deep Learning for Time Series Cookbook

Product type Book
Published in Mar 2024
Publisher Packt
ISBN-13 9781805129233
Pages 274 pages
Edition 1st Edition
Languages
Authors (2):
Vitor Cerqueira Vitor Cerqueira
Profile icon Vitor Cerqueira
Luís Roque Luís Roque
Profile icon Luís Roque
View More author details

Table of Contents (12) Chapters

Preface Chapter 1: Getting Started with Time Series Chapter 2: Getting Started with PyTorch Chapter 3: Univariate Time Series Forecasting Chapter 4: Forecasting with PyTorch Lightning Chapter 5: Global Forecasting Models Chapter 6: Advanced Deep Learning Architectures for Time Series Forecasting Chapter 7: Probabilistic Time Series Forecasting Chapter 8: Deep Learning for Time Series Classification Chapter 9: Deep Learning for Time Series Anomaly Detection Index Other Books You May Enjoy

Tackling TSC with K-nearest neighbors

In this recipe, we’ll show you how to tackle TSC tasks using a popular method called K-nearest neighbors. The goal of this recipe is to show you how standard machine-learning models can be used to solve this problem.

Getting ready

First, let’s start by loading the data using pandas:

import pandas as pd
data_directory = 'assets/datasets/Car'
train = pd.read_table(f'{data_directory}/Car_TRAIN.tsv', header=None)
test = pd.read_table(f'{data_directory}/Car_TEST.tsv', header=None)

The dataset is already split into a training and testing set, so we read them separately. Now, let’s see how to build a K-nearest neighbor model using this dataset.

How to do it…

Here, we describe the steps necessary for building a time series classifier using scikit-learn:

  1. Let’s start by splitting the target variable from the explanatory variables:
    y_train = train.iloc[:, 0]
    y_test =...
lock icon The rest of the chapter is locked
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.
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}