我正在努力解决从sklearn.cross_validation
IndexError
。我解决了这个问题,似乎是sklearn
的错误.
我在 ipython 并行引擎上运行以下代码:
kf = cross_validation.KFold(num_data, k_fold)
for k, (train, test) in enumerate(kf):
# do something
和发生的错误
IndexError: arrays used as indices must be of integer (or boolean) type
发生的位置错误是:
def _iter_test_masks(self):
"""Generates boolean masks corresponding to test sets.
By default, delegates to _iter_test_indices()
"""
for test_index in self._iter_test_indices():
test_mask = self._empty_mask()
test_mask[test_index] = True # <============= Here error occurs
yield test_mask
如何解决这个问题?
我终于解决了这个问题。
只需添加.astype('int64)
def _iter_test_masks(self):
"""Generates boolean masks corresponding to test sets.
By default, delegates to _iter_test_indices()
"""
for test_index in self._iter_test_indices():
test_mask = self._empty_mask()
test_mask[test_index.astype('int64')] = True # convert to int type
yield test_mask