机器学习,在对莺尾花数据进行洗牌操作时报错
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784')
mnist
X, y = mnist["data"],mnist["target"]
# 构造训练集和测试集,分别取前6万和后1万
X_train, X_test, y_train, y_test = X[:60000], X[60000:], y[:60000], y[60000:]
# 洗牌操作
import numpy as np
shuffle_index = np.random.permutation(60000)
X_train, y_train = X_train[shuffle_index], y_train[shuffle_index]
C:\Users\ADMINI~1\AppData\Local\Temp/ipykernel_4680/859505846.py in <module>
3
4 shuffle_index = np.random.permutation(60000)
----> 5 X_train, y_train = X_train[shuffle_index], y_train[shuffle_index]
D:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
3462 if is_iterator(key):
3463 key = list(key)
-> 3464 indexer = self.loc._get_listlike_indexer(key, axis=1)[1]
3465
3466 # take() does not accept boolean indexers
D:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexing.py in _get_listlike_indexer(self, key, axis)
1312 keyarr, indexer, new_indexer = ax._reindex_non_unique(keyarr)
1313
-> 1314 self._validate_read_indexer(keyarr, indexer, axis)
1315
1316 if needs_i8_conversion(ax.dtype) or isinstance(
D:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_read_indexer(self, key, indexer, axis)
1372 if use_interval_msg:
1373 key = list(key)
-> 1374 raise KeyError(f"None of [{key}] are in the [{axis_name}]")
1375
1376 not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique())
KeyError: "None of [Int64Index([30014, 20704, 39358, 59901, 34204, 33490, 47212, 42902, 35485,\n 56263,\n ...\n 58028, 34403, 33149, 17932, 18264, 29486, 7317, 16650, 46800,\n 7085],\n dtype='int64', length=60000)] are in the [columns]"
搜索了一下,没有找到理想的解决方法
对数据集进行洗牌操作成功