基于sklearn的线性回归中,引入多维数组出现TypeError: only size-1 arrays can be converted to Python scalars

def runplt():
plt.figure()
plt.title(u’低氧环境下运动员白细胞含量随运动时间的变化’)
plt.xlabel(u’运动时间’)
plt.ylabel(u’白细胞含量 ')
plt.axis([0,62,2,7])
plt.grid(True)
return plt
plt1 = runplt()
x = [[0],[8],[18],[25],[32],[38],[45],[50],[52],[57]]
y_list = [[‘4.06’,‘3.90’,‘3.5’,‘3.7’,‘4.2’,‘5’],
[‘4.86’,‘4.70’,‘4.50’,‘4.30’,‘5.9’,‘4.9’],
[‘4.9’,‘4.9’,‘4.9’,‘4.7’,‘5.3’,‘4.7’],
[‘5.36’,‘6.5’,‘5’,‘4.3’,‘6.6’,‘4.4’],
[‘5.28’,‘5.20’,‘4.6’,‘6.1’,‘6.5’,‘4’],
[‘4.74’,‘4.1’,‘4.3’,‘5.5’,‘5.8’,‘3.8’],
[‘4.34’,‘4.7’,‘4.2’,‘3.1’,‘5.5’,‘4.2’],
[‘4.98’,‘5.7’,‘4.6’,‘4.5’,‘5.9’,‘4.2’],
[‘4.57’,‘5.9’,‘4.5’,‘4.4’,‘5.5’,‘3.5’],
[‘4.77’,‘6.00’,‘4.1’,‘3.4’,‘5.8’,‘3.6’]]
plt.plot(x, y_list, ‘k.’)
plt.show()
model = LinearRegression()
model.fit(x, y_list)
print(‘预测第30天时候白细胞含量:%.2f’ % model.predict(np.array([30]).reshape(1, -1))[0])

Traceback (most recent call last):
File “/home/rentao/.PyCharmCE2018.3/config/scratches/try.py”, line 30, in
print(‘预测第30天时候白细胞含量:%.2f’ % model.predict(np.array([30]).reshape(1, -1))[0])
TypeError: only size-1 arrays can be converted to Python scalars

我只是把y改成这种形式以后才出现的这个问题,请问如何解决?

你可能感兴趣的:(基于sklearn的线性回归中,引入多维数组出现TypeError: only size-1 arrays can be converted to Python scalars)