简体   繁体   English

sklearn model.fit“使用序列设置数组元素。”

[英]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.

相关问题 ValueError:使用序列设置数组元素。 关于Keras model.fit - ValueError: setting an array element with a sequence. On Keras model.fit 收到“ ValueError:使用序列设置数组元素。” - receiving “ValueError: setting an array element with a sequence.” sklearn GMM在稀疏矩阵上引发“ ValueError:设置具有序列的数组元素。” - sklearn GMM raises “ValueError: setting an array element with a sequence.” on sparse matrix ValueError:使用序列设置数组元素。 熊猫 - ValueError: setting an array element with a sequence. for Pandas “ ValueError:使用序列设置数组元素。” TensorFlow - “ValueError: setting an array element with a sequence.” TensorFlow sklearn SVM fit()“ValueError:使用序列设置数组元素” - sklearn SVM fit() “ValueError: setting an array element with a sequence” 将来自 dataframe 的样本输入到 ARMA model 并得到“ValueError:设置具有序列的数组元素”。 - Inputing samples from a dataframe into an ARMA model and getting 'ValueError: setting an array element with a sequence.' AWS Sagemaker,InvokeEndpoint操作,模型错误:“使用序列设置数组元素。” - AWS Sagemaker, InvokeEndpoint operation, Model error: “setting an array element with a sequence.” ValueError:使用序列设置数组元素。 在DBSCAN上,没有丢失的尺寸 - ValueError: setting an array element with a sequence. on DBSCAN, no missing dimensionality ValueError:使用序列设置数组元素。 在TensorFlow中sess.run() - ValueError: setting an array element with a sequence. in TensorFlow sess.run()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM