11import numpy as np
22
3+ import pytest
4+
5+ from sklearn .exceptions import NotFittedError
6+
37from tslearn .metrics import cdist_gak
48from tslearn .svm import TimeSeriesSVC , TimeSeriesSVR
59
610__author__ = 'Romain Tavenard romain.tavenard[at]univ-rennes2.fr'
711
812
13+
914def test_gamma_value_svm ():
1015 n , sz , d = 5 , 10 , 3
1116 rng = np .random .RandomState (0 )
@@ -22,3 +27,22 @@ def test_gamma_value_svm():
2227 cdist_mat = cdist_gak (time_series , sigma = np .sqrt (gamma / 2. ))
2328
2429 np .testing .assert_allclose (sklearn_X , cdist_mat )
30+
31+ def test_attributes ():
32+ n , sz , d = 5 , 10 , 3
33+ rng = np .random .RandomState (0 )
34+ time_series = rng .randn (n , sz , d )
35+ labels = rng .randint (low = 0 , high = 2 , size = n )
36+
37+ for ModelClass in [TimeSeriesSVC , TimeSeriesSVR ]:
38+ linear_model = ModelClass (kernel = "linear" )
39+
40+ for attr in ['coef_' , 'support_' , 'support_vectors_' ,
41+ 'dual_coef_' , 'coef_' , 'intercept_' ]:
42+ with pytest .raises (NotFittedError ):
43+ getattr (linear_model , attr )
44+
45+ linear_model .fit (time_series , labels )
46+ for attr in ['coef_' , 'support_' , 'support_vectors_' ,
47+ 'dual_coef_' , 'coef_' , 'intercept_' ]:
48+ assert hasattr (linear_model , attr )
0 commit comments