#πŸ”’ Index out of bounds error

23 messages Β· Page 1 of 1 (latest)

signal wyvern
#

Hi guys, so im currently learning about SHAP values, and im going through a dataset from kaggle (https://www.kaggle.com/datasets/fedesoriano/stroke-prediction-dataset), its a stroke prediction dataset. I've sent the link to the colab (the code is too long to post here), the code is to calculate the SHAP values and ultimately plot a force plot and a summary plot to visualize feature importance when predicting the likelihood of a stroke. The problem is that there are no predictions from the SVM that result in a prediction of class 1, when someone has a stroke, the data is pretty imbalanced whereby there are 4000 rows of not having a stroke, and around 400-500 for those having a stroke, does anyone know where im going wrong? that would be much appreciated

shap_values[1] always results in an index out of bounds error

https://colab.research.google.com/drive/1RzHAx5UfJ2iGHX-ZekWmWUPkMH0bA6Dl?usp=sharing

trim cobaltBOT
#

@signal wyvern

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

sweet hazel
#

looks like the shape of shap_values is (1, 21, 2), which means only contains one element

signal wyvern
sweet hazel
#

there is no predictions for class 1, but not yet figure out why there is no class 1 predictions

#

can check if the train data contain class 1 data

#

looks like there is only one sample to pass to the test

#

the X_test_row only contains one example

#
start_index = 1
end_index = 2
X_test_row = X_test.iloc[start_index:end_index]
trim cobaltBOT
#

Hey @sweet hazel!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
sweet hazel
#
start_index = 1
end_index = 2
X_test_row = X_test.iloc[start_index:end_index]
#

you should replace the end_index with a number biger than 2

#

to make sure there are class 1 and class 2 predictions

sweet hazel
signal wyvern
#

i see, alright ill test it out

#

thanks for replying really appreciate it man

#

god bless

#

so would it better if i made the end index the length of the test data?

sweet hazel
#

the more the data, the more the time to make the prediction

#

Gernerally , the testdata should not only contains one sample, it should contains enough data

signal wyvern
#

i see, thanks again

trim cobaltBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.