Я пытаюсь построить мои прогнозируемые значения в сравнении с моей независимой переменной
, если бы они были одинаковой формы, чтобы можно было вписаться в модель, почему бы им не быть одинакового размера? да, они не одинаковы, так как X имеет несколько атрибутов, так как Y - одна независимая переменная, но все же я не понимаю, как их построить
Код:
# generate random data-set
np.random.seed(0)
x = df1
y = subjects["heart_rate"]
#x= x.values.reshape(-1, 1)
#y= y.values.reshape(-1, 1)
#x.shape[0] != y.shape[0]
# sckit-learn implementation
# Model initialization
regression_model = LinearRegression()
# Fit the data(train the model)
regression_model.fit(x, y)
# Predict
y_predicted = regression_model.predict(x)
# model evaluation
rmse = mean_squared_error(y, y_predicted)
r2 = r2_score(y, y_predicted)
# printing values
print('Slope:' ,regression_model.coef_)
print('Intercept:', regression_model.intercept_)
print('Root mean squared error: ', rmse)
print('R2 score: ', r2)
# plotting values
# data points
plt.scatter(x, y, s=10)
plt.xlabel('x')
plt.ylabel('y')
# predicted values
plt.plot(x, y_predicted, color='r')
plt.show()
Ошибка:
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
X:
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
y:
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