[英]sklearn model.fit “setting an array element with a sequence.”
I'm currently trying to call my model's train() function by passing my X and Y data and receiving this error setting an array element with a sequence.
我正在尝试通过传递我的X和Y数据并接收此错误来
setting an array element with a sequence.
来调用模型的train()函数setting an array element with a sequence.
I tried creating fake data anbd passing it and it works just fine. 我尝试创建假数据和传递它,它工作得很好。 fake data:
假数据:
X = [[1,2,3], [2,1,3]]
Y = [0,1]
knn_model.train(X,Y)
But when passing the real data, I get the error. 但是当传递真实数据时,我得到了错误。 The real data is the value of pixels extracted from images.
实际数据是从图像中提取的像素的值。 I get the same data structure as the fake data above but for some reason I get the error.
我获得与上面的假数据相同的数据结构但由于某种原因我得到了错误。
The data is created by instanciating the variable images = []
and then appending every array of pixels of each image. 通过实现变量
images = []
来创建数据,然后附加每个图像的每个像素阵列。
In the debug console, here is both the fake data and the real data: 在调试控制台中,这里是假数据和真实数据:
real data: array dtype('O') of list containing array dtype('uint8')
fake data: array dtype('int32') of list containing array dtype('int32')
The error received is when the function fit() is called and the error is 收到的错误是调用函数fit()并且错误是
"setting an array element with a sequence." “使用序列设置数组元素。”
train function: 火车功能:
def train(self, X, Y): self.model.fit(X, Y)
The solution is in the error message. 解决方案在错误消息中。 Your model is expecting an array while you are sending a sequence/list.
在发送序列/列表时,您的模型需要一个数组。 Convert your training data from sequence to array using
numpy
before you append it. 在追加之前,使用
numpy
将训练数据从序列转换为数组。
numpy.array([1.2, "abc"], dtype=float)
or 要么
numpy.array([1.2, 1, 42, 46])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.