In [1]:
Copied!
import pickle
import numpy as np
from tslearn.datasets import UCR_UEA_datasets
import pickle
import numpy as np
from tslearn.datasets import UCR_UEA_datasets
Parameters¶
In [2]:
Copied!
dataset='GunPoint'
dataset='GunPoint'
Load Data¶
In [3]:
Copied!
train_x,train_y, test_x, test_y=UCR_UEA_datasets().load_dataset(dataset)
train_x,train_y, test_x, test_y=UCR_UEA_datasets().load_dataset(dataset)
In [4]:
Copied!
print(train_x.shape)
print(test_x.shape)
print(train_x.shape)
print(test_x.shape)
(50, 150, 1) (150, 150, 1)
In [5]:
Copied!
train_x.shape
train_x.shape
Out[5]:
(50, 150, 1)
In [6]:
Copied!
train_y.shape
train_y.shape
Out[6]:
(50,)
Load Model¶
In [7]:
Copied!
model= pickle.load(open(f'../../ClassificationModels/models/GunPoint/GunPoint_SVM.sav','rb')).fit(train_x,train_y)
#/media/jacqueline/Data/InterpretabiltyTimeSeries/ClassificationModels/models/GunPoint/GunPoint_SVM.sav
model= pickle.load(open(f'../../ClassificationModels/models/GunPoint/GunPoint_SVM.sav','rb')).fit(train_x,train_y)
#/media/jacqueline/Data/InterpretabiltyTimeSeries/ClassificationModels/models/GunPoint/GunPoint_SVM.sav
Explanation Algo¶
In [8]:
Copied!
explained_instance = train_x[0]
nb_interpretable_feature = 10
explanation_size = 5
nb_neighbors = 1000
learning_process_name = 'Lime'
transform_name = 'straight_line'
explained_instance = train_x[0]
nb_interpretable_feature = 10
explanation_size = 5
nb_neighbors = 1000
learning_process_name = 'Lime'
transform_name = 'straight_line'
In [9]:
Copied!
from TSInterpret.InterpretabilityModels.leftist.leftist import LEFTIST
from TSInterpret.InterpretabilityModels.leftist.leftist import LEFTIST
2022-10-27 11:59:39.218998: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory 2022-10-27 11:59:39.219023: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
In [10]:
Copied!
model_to_explain = model
random_state=0
model_to_explain = model
random_state=0
In [11]:
Copied!
leftist = LEFTIST(model_to_explain,(test_x,None),mode='time', backend='SK')
leftist = LEFTIST(model_to_explain,(test_x,None),mode='time', backend='SK')
In [12]:
Copied!
explanations = leftist.explain(np.array(explained_instance),1000,explanation_size=explanation_size)
explanations = leftist.explain(np.array(explained_instance),1000,explanation_size=explanation_size)
In [13]:
Copied!
%matplotlib inline
leftist.plot(np.array([explained_instance]).reshape(1,-1,1), np.array([explanations[0]]))
%matplotlib inline
leftist.plot(np.array([explained_instance]).reshape(1,-1,1), np.array([explanations[0]]))
time mode (1, 150) (1, 150) -1 1 0