.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/classification/plot_time_series_forest.py" .. LINE NUMBERS ARE GIVEN BELOW. .. 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_classification_plot_time_series_forest.py: ================== Time Series Forest ================== This example illustrates which information is considered important by the algorithm in order to classify time series. The index of the most important window is retrieved via the ``feature_importance_`` and ``indices_`` attributes. The first time series for both classes are plotted and the most important window is highlighted with a larger line width. It is implemented as :class:`pyts.classification.TimeSeriesForest`. .. GENERATED FROM PYTHON SOURCE LINES 15-47 .. image-sg:: /auto_examples/classification/images/sphx_glr_plot_time_series_forest_001.png :alt: The most important window according to the feature importance scores :srcset: /auto_examples/classification/images/sphx_glr_plot_time_series_forest_001.png :class: sphx-glr-single-img .. code-block:: default # Author: Johann Faouzi # License: BSD-3-Clause import numpy as np from pyts.datasets import load_gunpoint from pyts.classification import TimeSeriesForest import matplotlib.pyplot as plt X_train, X_test, y_train, y_test = load_gunpoint(return_X_y=True) clf = TimeSeriesForest(random_state=43) clf.fit(X_train, y_train) start_idxmax, end_idxmax = clf.indices_[ np.argmax(clf.feature_importances_) // 3] plt.figure(figsize=(12, 5)) plt.plot(X_train[y_train == 1][0], label='First sample in class 1') plt.plot(np.arange(start_idxmax, end_idxmax), X_train[y_train == 1][0, start_idxmax:end_idxmax], color='C0', lw=4) plt.plot(X_train[y_train == 2][0], label='First sample in class 2') plt.plot(np.arange(start_idxmax, end_idxmax), X_train[y_train == 2][0, start_idxmax:end_idxmax], color='C1', lw=4) plt.legend(loc='best', fontsize=14) plt.title('The most important window according to the feature importance ' 'scores', fontsize=16) plt.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.733 seconds) .. _sphx_glr_download_auto_examples_classification_plot_time_series_forest.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_time_series_forest.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_time_series_forest.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_