tslearn-team / tslearn

The machine learning toolkit for time series analysis in Python
https://tslearn.readthedocs.io
BSD 2-Clause "Simplified" License
2.85k stars 336 forks source link

tuning gamma for tslearn.svm.TimeSeriesSVC - Question #340

Open markus-mich opened 3 years ago

markus-mich commented 3 years ago

Hello,

I have a small question about classifying multivariate time series using SVM. In tslearn, there is an option to classify time series or multivariate time series using tslearn.svm.TimeSeriesSVC. Here, according to the documentation, "gak" kernel is used. Now I haven't seen anywhere a detailed explanation how actually the parameter gamma works with this kernel "GAK". Should it always stay in the default value "auto"? Because I have used other gamma parameters like (0.1, 1, 10) but got very bad results compared to "auto". So I wanted to ask how the gamma works with this kernel and I haven't seen a formula anywhere. Or is there a specific article for this ?

Thanks in advance

felixdivo commented 3 years ago

As is stated in the documentation of TimeSeriesSVC, tslearn.metrics.gamma_soft_dtw is used to compute gamma:

gamma : float, optional (default=’auto’) Kernel coefficient for ‘gak’, ‘rbf’, ‘poly’ and ‘sigmoid’. If gamma is ‘auto’ then:

  • for ‘gak’ kernel, it is computed based on a sampling of the training set (cf tslearn.metrics.gamma_soft_dtw)
  • for other kernels (eg. ‘rbf’), 1/n_features will be used.

The method also references an original paper.

rtavenar commented 3 years ago

Hi,

You can find information on this kernel here, for example: https://marcocuturi.net/GA.html

In tslearn, we use the parameter $\gamma$ in place of $\sigma$ since it is the one used in recent related work by Cuturi and colleagues (softDTW), and the link between $\sigma$ and $\gamma$ is the following:

$\gamma = 2 \sigma^2$

Docs could probably be clearer on this point, any help on this would be welcome.