.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_padtrunc.py: ================================================= Pipeline using Time Series Padding and Truncation ================================================= This is a basic example using the pipeline to learn a feature representation of the time series data using padding and truncation instead of sliding window segmentation. .. image:: /auto_examples/images/sphx_glr_plot_padtrunc_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none N series in train: 105 N series in test: 35 N segments in train: 105 N segments in test: 35 Accuracy score: 0.8285714285714286 | .. code-block:: default # Author: David Burns # License: BSD import matplotlib.image as mpimg import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.svm import LinearSVC from seglearn.datasets import load_watch from seglearn.pipe import Pype from seglearn.transform import FeatureRep, PadTrunc # load the data data = load_watch() X = data['X'] y = data['y'] # create a feature representation pipeline with PadTrunc segmentation # the time series are between 20-40 seconds # this truncates them all to the first 5 seconds (sampling rate is 50 Hz) pipe = Pype([('trunc', PadTrunc(width=250)), ('features', FeatureRep()), ('scaler', StandardScaler()), ('svc', LinearSVC())]) # split the data X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, shuffle=True, random_state=42) pipe.fit(X_train, y_train) score = pipe.score(X_test, y_test) print("N series in train: ", len(X_train)) print("N series in test: ", len(X_test)) print("N segments in train: ", pipe.N_train) print("N segments in test: ", pipe.N_test) print("Accuracy score: ", score) img = mpimg.imread('trunk.jpg') plt.imshow(img) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.201 seconds) .. _sphx_glr_download_auto_examples_plot_padtrunc.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_padtrunc.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_padtrunc.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_