Я работаю над проблемой новичков для мультиклассовой классификации на Kaggle:
Данные доступны здесь: http://s000.tinyupload.com/?file_id=00314054107124324293
Моя анаконда была только что обновлена до последней версии (pyton3, windows10 setup).
## usual imports
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
train = pd.read_csv('./train.csv', sep=',', low_memory=False, index_col='Id')
test = pd.read_csv('./test.csv', sep=',', low_memory=False, index_col='Id')
Затем я хотел проверить корреляции между объектами с помощью этого простого цикла:
## check numeric features: columns 10:-1
plt.rcParams["figure.figsize"] = (10,8)
covers = list(train.Cover_Type.unique())
covers.sort()
for cover_type in covers:
print(f'Cover Type: {cover_type}\n')
mask = train[train['Cover_Type']==cover_type].index
sns.heatmap(train.iloc[mask,:10].corr(),annot=True)
plt.show();
все будет работать, пока я не нажму Cover_Type 3 , затемвыдает ошибку:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-72-c559c9b2bf10> in <module>
9
10 plt.figure(figsize=(10,8))
---> 11 sns.heatmap(train.iloc[mask,:10].corr(),annot=True)
12 plt.show();
~\Anaconda3\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
1492 except (KeyError, IndexError, AttributeError):
1493 pass
-> 1494 return self._getitem_tuple(key)
1495 else:
1496 # we by definition only have the 0th axis
~\Anaconda3\lib\site-packages\pandas\core\indexing.py in _getitem_tuple(self, tup)
2141 def _getitem_tuple(self, tup):
2142
-> 2143 self._has_valid_tuple(tup)
2144 try:
2145 return self._getitem_lowerdim(tup)
~\Anaconda3\lib\site-packages\pandas\core\indexing.py in _has_valid_tuple(self, key)
221 raise IndexingError('Too many indexers')
222 try:
--> 223 self._validate_key(k, i)
224 except ValueError:
225 raise ValueError("Location based indexing can only have "
~\Anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_key(self, key, axis)
2079
2080 if len(arr) and (arr.max() >= len_axis or arr.min() < -len_axis):
-> 2081 raise IndexError("positional indexers are out-of-bounds")
2082 else:
2083 raise ValueError("Can only index by location with "
IndexError: positional indexers are out-of-bounds
<Figure size 720x576 with 0 Axes>
Почему это так?