我遇到了一个之前没有发生过的问题,可能是一些规则被更改了。
Traceback (most recent call last)
<ipython-input-3-f47687e192a7> in <module>()
5 n_examples = X.shape[0]
6 n_train = n_examples * 0.5
----> 7 train_idx = np.random.choice(range(0,n_examples), size=n_train, replace=False)
8 test_idx = list(set(range(0,n_examples))-set(train_idx))
9 X_train = X[train_idx]
mtrand.pyx in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:18822)()
TypeError: 'float' object cannot be interpreted as an index
n_train = n_examples * 0.5
可能不是整数。尝试使用n_train = int(n_examples * 0.5)
? - fredtantini