1

I tried to plot a boxplot with confidence intervals but I got an exception.

from sklearn import datasets

iris = datasets.load_iris()

iris = iris.data

iris = pd.DataFrame(iris)

iris.columns = ['a', 'b', 'c', 'd']

iris.boxplot(column='a', figsize=(15,20), showmeans = True, patch_artist = True, conf_intervals = True, bootstrap = 100)

plt.show()

IndexError: tuple index out of range

How can I resolve this error?

halfer
  • 19,824
  • 17
  • 99
  • 186
user8270077
  • 4,621
  • 17
  • 75
  • 140

1 Answers1

1

You need to specify the confidence intervals as a list of tuples corresponding to the features you are plotting. In your case, you are plotting only column 'a', therefore you need to specify a list with one tuple:

iris.boxplot(column='a', figsize=(15,20), notch=True, showmeans = True, \ 
             patch_artist = True, conf_intervals = [(4, 7)], bootstrap = 10000)

plt.show()

produces the following figure

enter image description here

However, according to the documentation conf_intervals should be None if you are bootstrapping because it overrides the parameters computed by bootstrapping. https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.boxplot.html

So, with conf_intervals None for 'a', the output is:

iris.boxplot(column='a', figsize=(15,20), notch=True, showmeans = True, \
             patch_artist = True, conf_intervals = [None], bootstrap = 10000)

plt.show()

enter image description here

KRKirov
  • 3,854
  • 2
  • 16
  • 20