Tabular Lime Explanation on Qiskit's QSVC runs into an infinite loop -

77 views Asked by At

I'm using the QSVM model to perform multiclass classification on Iris data.

exp = interpretor.explain_instance(
    data_row=test_features.iloc[5],
    predict_fn=qsvc.predict_proba
)

the above goes into an infinite loop,

But the code works fine for Random Forest or SVM.

I tried the following

Approach 1 => Try using Shap instead or other models instead of QSVC.

  1. Instead of Lime we tried using Shap package as well, but it also runs into an infinite loop with qsvc.predict_proba.

  2. The reason for picking QSVC was because its the only one that has the predict_proba method which needs to be passed for Lime/Shap explainers.

Approach 2 => Check the differences from other model's predict_proba

One observation I made was if I try to print qsvc.predict_proba, no error but randomforest.predict_proba(train[5]) produces the error.

    ValueError                                Traceback (most recent call last)
    <ipython-input-36-4364d2dab58d> in <cell line: 1>()
----> 1 exp = rf.predict_proba(train[5])

3 frames
/usr/local/lib/python3.10/dist-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name)
    900             # If input is 1D raise error
    901             if array.ndim == 1:
--> 902                 raise ValueError(
    903                     "Expected 2D array, got 1D array instead:\narray={}.\n"
    904                     "Reshape your data either using array.reshape(-1, 1) if "

ValueError: Expected 2D array, got 1D array instead:
array=[0.41666666 0.29166666 0.5254237  0.375     ].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

The above error gets fixed after the array is reshaped.

-------------------------------------------------------------------------------------------

While, qsvc.predict_proba(train[5]) returns the answer without any reshaping

array([[0.02428184, 0.62908388, 0.34663429]])

This is how the train, test have been split

features = iris_data.data
features = MinMaxScaler().fit_transform(features)

iris = sklearn.datasets.load_iris()
train, test, labels_train, labels_test = sklearn.model_selection.train_test_split(features, iris.target, train_size=0.80, random_state=65)
0

There are 0 answers