我在IndexError
筹集sklearn.cross_validation
时遇到了困难。我解决了这个问题,似乎是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
如何解决这个问题?
答案 0 :(得分:2)
我终于解决了这个问题。
只需添加.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