Python ValueError:绘制预测值时,x和y的大小必须相同
我正试着把我的预测值和我的自变量画出来 如果它们是相同的形状,能够适合模型,为什么它们不能是相同的大小?是的,它们不一样,因为X有多个属性,因为Y是一个自变量,但我仍然不知道如何绘制它们 代码: 错误:Python ValueError:绘制预测值时,x和y的大小必须相同,python,matplotlib,linear-regression,Python,Matplotlib,Linear Regression,我正试着把我的预测值和我的自变量画出来 如果它们是相同的形状,能够适合模型,为什么它们不能是相同的大小?是的,它们不一样,因为X有多个属性,因为Y是一个自变量,但我仍然不知道如何绘制它们 代码: 错误: Slope: [-5.37064533 -0.50880666 -0.09348247 -1.33726289 0.18639004 1.42313131 -0.2752906 0.26580939 -0.17365683 -0.13841734] Intercept: 274.537
Slope: [-5.37064533 -0.50880666 -0.09348247 -1.33726289 0.18639004 1.42313131
-0.2752906 0.26580939 -0.17365683 -0.13841734]
Intercept: 274.5378817549546
Root mean squared error: 498.2107065101733
R2 score: 0.31625521784258237
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-179-a4bdd40003d3> in <module>()
31 # data points
32
---> 33 plt.scatter(x, y, s=10)
34 plt.xlabel('x')
35 plt.ylabel('y')
c:\python36\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs)
3473 vmin=vmin, vmax=vmax, alpha=alpha,
3474 linewidths=linewidths, verts=verts,
-> 3475 edgecolors=edgecolors, data=data, **kwargs)
3476 finally:
3477 ax._hold = washold
c:\python36\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1865 "the Matplotlib list!)" % (label_namer, func.__name__),
1866 RuntimeWarning, stacklevel=2)
-> 1867 return func(ax, *args, **kwargs)
1868
1869 inner.__doc__ = _add_data_doc(inner.__doc__,
c:\python36\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
4255 y = np.ma.ravel(y)
4256 if x.size != y.size:
-> 4257 raise ValueError("x and y must be the same size")
4258
4259 if s is None:
ValueError: x and y must be the same size
y:
您正试图根据序列
y
生成数据帧x
(1942871 x N对象)的散点图。代码失败,因为x
的元素总数大于y
print('x的大小={0}'。格式(x.size))
打印('y的大小={0}'。格式(y.size))
断言x.size==y.size
大小不相等,因此代码失败
如果必须有一个x
与y
的散点图,请逐列进行
对于x列中的列:
plt.散射(x[col],y,s=10)
您正试图针对序列y
生成数据帧x
(1942871 x N对象)的散点图。代码失败,因为x
的元素总数大于y
print('x的大小={0}'。格式(x.size))
打印('y的大小={0}'。格式(y.size))
断言x.size==y.size
大小不相等,因此代码失败
如果必须有一个x
与y
的散点图,请逐列进行
对于x列中的列:
plt.散射(x[col],y,s=10)
我刚刚这么做,它返回KeyError:“IMU\u hand\u temp”这是x中第一列的名称,为什么它要计算列的名称?@Zaid我认为应该是plt.scatter(x[col],y,s=10)
我刚刚这么做了,它返回KeyError:“IMU\u hand\u temp”这是x中第一列的名称为什么它要计算列的名称?@Zaid我认为应该是plt.scatter(x[col],y,s=10)
Slope: [-5.37064533 -0.50880666 -0.09348247 -1.33726289 0.18639004 1.42313131
-0.2752906 0.26580939 -0.17365683 -0.13841734]
Intercept: 274.5378817549546
Root mean squared error: 498.2107065101733
R2 score: 0.31625521784258237
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-179-a4bdd40003d3> in <module>()
31 # data points
32
---> 33 plt.scatter(x, y, s=10)
34 plt.xlabel('x')
35 plt.ylabel('y')
c:\python36\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs)
3473 vmin=vmin, vmax=vmax, alpha=alpha,
3474 linewidths=linewidths, verts=verts,
-> 3475 edgecolors=edgecolors, data=data, **kwargs)
3476 finally:
3477 ax._hold = washold
c:\python36\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1865 "the Matplotlib list!)" % (label_namer, func.__name__),
1866 RuntimeWarning, stacklevel=2)
-> 1867 return func(ax, *args, **kwargs)
1868
1869 inner.__doc__ = _add_data_doc(inner.__doc__,
c:\python36\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
4255 y = np.ma.ravel(y)
4256 if x.size != y.size:
-> 4257 raise ValueError("x and y must be the same size")
4258
4259 if s is None:
ValueError: x and y must be the same size
IMU_hand_temp hand_acceleration_16_1 hand_acceleration_16_2 hand_acceleration_16_3 hand_gyroscope_rad_7 hand_gyroscope_rad_8 hand_gyroscope_rad_9 hand_magnetometer_μT_10 hand_magnetometer_μT_11 hand_magnetometer_μT_12
0 30.375 2.21530 8.27915 5.58753 -0.004750 0.037579 -0.011145 8.93200 -67.9326 -19.9755
1 30.375 2.29196 7.67288 5.74467 -0.171710 0.025479 -0.009538 9.58300 -67.9584 -20.9091
2 30.375 2.29090 7.14240 5.82342 -0.238241 0.011214 0.000831 9.05516 -67.4017 -19.5083
3 30.375 2.21800 7.14365 5.89930 -0.192912 0.019053 0.013374 9.92698 -67.4387 -20.5602
4 30.375 2.30106 7.25857 6.09259 -0.069961 -0.018328 0.004582 9.15626 -67.1825 -20.0857
... ... ... ... ... ... ... ... ... ... ...
1942867 25.125 4.99466 6.01881 5.59830 -0.289166 -0.110170 0.238570 -4.79353 -18.1271 -48.2695
1942868 25.125 5.02764 5.90369 5.48372 -0.275411 -0.128358 0.267409 -4.54101 -18.0169 -48.9268
1942869 25.125 5.06409 5.71370 5.48491 -0.289885 -0.126548 0.281483 -4.17401 -17.9121 -48.4032
1942870 25.125 5.13914 5.63724 5.48629 -0.234417 -0.101485 0.275497 -4.66091 -18.2588 -49.0563
1942871 25.125 5.00812 5.40645 5.02326 -0.260924 -0.093849 0.266205 -5.05008 -17.6169 -48.1408
0 100.0
1 100.0
2 100.0
3 100.0
4 100.0
...
1942867 162.0
1942868 162.0
1942869 162.0
1942870 162.0
1942871 162.0
Name: heart_rate, Length: 1942872, dtype: float64