我对numpy数组有问题,我有一个很大的条目数据集,并且所有条目都有浮点值,并且每个条目的大小都相同(300),将其作为输入传递给逻辑回归模型时,它会抛出出现错误,提示我已用序列替换了数组元素。
我检查了每个数据类型是否为数组,它们是数据类型为float的数组
print(type(train_on[0][0]))
print(type(train_on[0]))
print(type(train_on))
给出
的输出<class 'numpy.float32'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
我在其他相关文章中读到,发生此错误的主要原因是条目大小不规则,但是我的数据集每个实例的长度为300。为了确保它们的长度相同,我在以下代码的帮助下进行了交叉检查,并且每个条目的大小都相同
count=0
for i in range(train_on.shape[0]):
if train_on[i].size==300:
count+=1
print(count)
count/train.shape[0]
它返回
66376
1.0
当我尝试将其传递给逻辑回归模型时,错误会弹出
logr = LogisticRegression(solver='sag')
logr.fit(train_on,train['A'])
这是错误
--> 522 array = np.asarray(array, dtype=dtype, order=order)
523 except ComplexWarning:
524 raise ValueError("Complex data not supported\n"
/anaconda/envs/py35/lib/python3.5/site-packages/numpy/core/numeric.py in asarray(a, dtype, order)
536
537 """
--> 538 return array(a, dtype, copy=False, order=order)
539
540
ValueError: setting an array element with a sequence.
有人可以帮我吗