tslearn-team/tslearn

Coefficient attribute not found on TimeSeriesSVC object after fitting.

delacylab opened this issue · 0 comments

Describe the bug
coef_ attribute not found when using tslearn.svm.TimeSeriesSVC. I am guessing this qualifies as a bug instead of a feature request since the documentation says this should be available when using a linear kernel.

To Reproduce
clf = tslearn.svm.TimeSeriesSVC(C=1.0, kernel="linear")
clf.fit(X,y)
clf.coef_

AttributeError: 'TimeSeriesSVC' object has no attribute 'coef_'

Expected behavior
An array of coefficients.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • tslearn version 0.5.3.2 installed from conda

Additional context
I added the following lines to the tslearn source code svm.py at line 261 and got what I think are expected results (an array of numClasses * sz * d). I had one class. This is the shape I would expect for a coef listing for time series 3D arrays since I will have a feature coefficient for each feature/time period. The below code also throws the appropriate error if a non-linear kernel is used. Can you confirm that if I have e.g. 3 time periods and 50 dimensions, that the resulting length 150 array would be represented as: 0-49 features in time period 1, 50-99 features in time period 2, 100-149 features in time period 3. I want to be sure that I am interpreting the results correctly and that the data isn't arranged in some different way.

@Property
def coef_(self):
check_is_fitted(self, 'X_fit')
return self.svm_estimator
.coef_