In [1]:
Copied!
import numpy as np
from tslearn.datasets import UCR_UEA_datasets
import numpy as np
from tslearn.datasets import UCR_UEA_datasets
Parameters¶
In [2]:
Copied!
dataset='ElectricDevices'
dataset='ElectricDevices'
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)
(8926, 96, 1) (7711, 96, 1)
In [5]:
Copied!
train_x.shape
train_x.shape
Out[5]:
(8926, 96, 1)
In [6]:
Copied!
train_y.shape
train_y.shape
Out[6]:
(8926,)
Load Model¶
In [7]:
Copied!
import tensorflow as tf
model_to_explain = tf.keras.models.load_model(f'../../ClassificationModels/models/{dataset}/cnn/best_model.hdf5')
import tensorflow as tf
model_to_explain = tf.keras.models.load_model(f'../../ClassificationModels/models/{dataset}/cnn/best_model.hdf5')
2023-06-15 11:04:50.284047: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2023-06-15 11:04:50.505469: W tensorflow/compiler/xla/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 2023-06-15 11:04:50.505494: I tensorflow/compiler/xla/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 2023-06-15 11:04:51.418759: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory 2023-06-15 11:04:51.418867: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory 2023-06-15 11:04:51.418879: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly. 2023-06-15 11:04:52.395804: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory 2023-06-15 11:04:52.395839: W tensorflow/compiler/xla/stream_executor/cuda/cuda_driver.cc:265] failed call to cuInit: UNKNOWN ERROR (303) 2023-06-15 11:04:52.395861: I tensorflow/compiler/xla/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (jacqueline-ThinkPad-P53): /proc/driver/nvidia/version does not exist 2023-06-15 11:04:52.396059: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
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
In [10]:
Copied!
leftist = LEFTIST(model_to_explain,(test_x, test_y),mode='time',backend='TF',transform_name='straight_line',learning_process_name='Lime')
#,'straight_line',segmentator,,learning_process_name
leftist = LEFTIST(model_to_explain,(test_x, test_y),mode='time',backend='TF',transform_name='straight_line',learning_process_name='Lime')
#,'straight_line',segmentator,,learning_process_name
In [11]:
Copied!
explanations = leftist.explain(np.array(explained_instance))
explanations = leftist.explain(np.array(explained_instance))
32/32 [==============================] - 0s 5ms/step
In [13]:
Copied!
leftist.plot(np.array([explained_instance]), np.array([explanations[1]]))
leftist.plot(np.array([explained_instance]), np.array([explanations[1]]))
time mode (1, 96) (1, 96) -1 1 0