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:
- Let’s start by splitting the target variable from the explanatory variables:
y_train = train.iloc[:, 0] y_test =...