user8373086
user8373086

Reputation:

Why do I get an Index Error in MACE for TimeSeries XAI?

for a university project I am currently testing XAI techniques for TimeSeriesData. In particular I am testing MACE and SHAP from OmniXAI MACE from OmniXAI. Even though implementing and running SHAP works completely fine, I am getting an error posted further down. While implementing I oriented myself by the tutorials posted on their website.

This is my implementation of SHAP. It works completely fine for me.

train_df = pd.DataFrame(df.iloc[:1000])
test_df = pd.DataFrame(df.iloc[1000:1500])

THRESHOLD = np.percentile(train_df.values, 90)

def detector(ts: Timeseries):
    anomaly_scores = np.sum((ts.values > THRESHOLD).astype(int))
    return anomaly_scores / ts.shape[0]

explainers = ShapTimeseries(
    training_data = Timeseries.from_pd(train_df),
    predict_function=detector,
    mode="anomaly_detection"
)

explanations = explainers.explain(Timeseries.from_pd(test_df))

#Darstellen der Explanations
fig = explanations.plot(index=0, max_num_variables_to_plot=4)
dict = explanations.get_explanations()

This is my implementation of MACE:

train_df = pd.DataFrame(df.iloc[:1000])
test_df = pd.DataFrame(df.iloc[1000:1500])

threshold = np.percentile(train_df.values, 90)

def detector(ts: Timeseries):
    anomaly_scores = np.sum((ts.values > threshold).astype(int))
    return anomaly_scores / ts.shape[0]

explainers = MACEExplainer(
    training_data = Timeseries.from_pd(train_df),
    predict_function=detector,
    mode="anomaly_detection",
    threshold = 0.1
)

explanations = explainers.explain(Timeseries.from_pd(test_df))

fig = explanations.plot(index=0, max_num_variables_to_plot=18)
plt.savefig("mace.png")

While running this, I get the following error:

 File "neural.py", line 111, in mace
  explanations = explainers.explain(Timeseries.from_pd(test_df))
 File "/home/y/.local/lib/python3.8/site-              packages/omnixai/explainers/timeseries/counterfactual/mace.py", line 306, in            explainself._build_explainer(X.ts_len)
 File "/home/y/.local/lib/python3.8/site-      packages/omnixai/explainers/timeseries/counterfactual/mace.py", line 188, in       _build_explainerself._candidates(ts_len)
 File "/home/y/.local/lib/python3.8/site-             packages/omnixai/explainers/timeseries/counterfactual/mace.py", line 156, in       _candidates values = transformer.invert(np.array([range(n_bins)] *       ts.shape[1]).T)
 File "/home/y/.local/lib/python3.8/site-      packages/omnixai/preprocessing/encode.py", line 40, in invert
  return self.encoder.inverse_transform(x)
 File "/home/y/.local/lib/python3.8/site-      packages/sklearn/preprocessing/_discretization.py", line 425, in       inverse_transform
  Xinv[:, jj] = bin_centers[np.int_(Xinv[:, jj])]
 IndexError: index 1 is out of bounds for axis 0 with size 1

I am completely stuck and don't know how to approach this problem any further. Do you have any tips?

Upvotes: 0

Views: 27

Answers (0)

Related Questions