python - 我正在尝试加载和拆分我的数据,但是我得到 TypeError:'只有整数标量数组可以转换为标量索引'
问题描述
进口
import numpy as np
from sklearn.linear_model import LogisticRegression # Architecture model
from sklearn.datasets import _olivetti_faces # Dataset
from sklearn.model_selection import train_test_split
### Loading and splitting the data
data = np.load("/content/Face_Recognition/olivetti_faces.npy")
Xtrain, Xtest, Ytrain, Ytest = train_test_split(data.data, test_size=0.3, random_state=0)
#Error to show if x and y rows mismatch
print(X.shape)
print(y.shape)
if X.shape[0] != y.shape[0]:
print("X and y rows are mismatched, check dataset again")
解决方案
似乎您正在使用数据集的过时版本。您可以在此处看到更新的链接。您拥有的代码将不起作用,因为您要求拆分数据和目标,而您只提供目标。
像这样的东西应该可以工作(在 sklearn 0.24.1 上):
from sklearn.datasets import fetch_olivetti_faces
data = fetch_olivetti_faces()
Xtrain, Xtest, Ytrain, Ytest = train_test_split(data.data, data.target, test_size=0.3, random_state=0)
推荐阅读
- buffer - 如何识别区域重叠(相交)?
- javascript - .load() jQuery 函数返回空白 div
- javascript - 如何将字符串数组中的字母提取到数组中,并在 JavaScript 中按空格分隔?
- javascript - Vanilla-tilt-react 为我的卡片提供了额外的样式
- python - 将全名输入转换为姓氏+首字母
- javascript - 如何在 React App 中使用导航栏重新路由到页面然后滚动到元素?
- python - 为什么变量总是设置为列表中的最后一项?
- go - 在完成时处理任意数量的 goroutines 的输出
- reactjs - 使用 nginx 和 react/django 部署应用程序失败
- javascript - 如何计算围绕其中心旋转的矩形的边界框?