Time series interpolating with aeon¶
Suppose we have a set of time series with different lengths, i.e. different number of time points. Currently, most of aeon’s functionality requires equal-length time series, so to use aeon, we need to first converted our data into equal-length time series. In this tutorial, you will learn how to use the TSInterpolator to do so.
[2]:
from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from aeon.classification.convolution_based import RocketClassifier
from aeon.datasets import load_basic_motions
Ordinary situation¶
Here is a normal situation, when all time series have same length. We load an example data set from aeon and train a classifier.
[3]:
X, y = load_basic_motions()
X_train, X_test, y_train, y_test = train_test_split(X, y)
clf = RocketClassifier(num_kernels=200)
clf.fit(X_train, y_train)
clf.score(X_test, y_test)
[3]:
1.0
If time series are unequal length, aeon’s algorithm may raise an error¶
Ifwe have unequal-length time series, classifiers without the capability to handle this will raise an error.
[4]:
from aeon.datasets import load_plaid
X, y = load_plaid()
X_train, X_test, y_train, y_test = train_test_split(X, y)
try:
clf = RocketClassifier(num_kernels=200)
clf.fit(X_train, y_train)
clf.score(X_test, y_test)
except ValueError as e:
print(f"ValueError: {e}")
ValueError: Data seen by instance of RocketClassifier has unequal length series, but RocketClassifier cannot handle unequal length series.
Now the interpolator enters¶
Now we use our interpolator to resize time series of different lengths to user-defined length. Internally, it uses linear interpolation from scipy and draws equidistant samples on the user-defined number of points.
After interpolating the data, the classifier works again.
[5]:
from aeon.transformations.collection.interpolate import TSInterpolator
steps = [
("transform", TSInterpolator(50)),
("classify", RocketClassifier()),
]
clf = Pipeline(steps)
clf.fit(X_train, y_train)
clf.score(X_test, y_test)
[5]:
0.7732342007434945
[ ]:
Generated using nbsphinx. The Jupyter notebook can be found here.