修改 python numpy 数组中的结果

我收到了 kerras 预测的响应,如下所示 (y_pred):

array([[127450.63 ],
       [181983.39 ],
       [150607.72 ],
       ...,
       [460400.   ],
       [ 92920.234],
       [244455.97 ]], dtype=float32)

我需要将结果与另一个如下所示的数组(t_pred)进行比较:

[105000. 172000. 189900. ... 131000. 132000. 188000.]

我该如何将数组 1 转换为类似于数组 2 以便我可以计算其mean_square_log_error,如下所示?:

mean_squared_log_error(t_pred, y_pred)


holdtom
浏览 98回答 1
1回答

跃然一笑

使用ravel()或reshape(-1)或flatten():mean_squared_log_error(t_pred, y_pred.ravel())或者mean_squared_log_error(t_pred, y_pred.reshape(-1))或者mean_squared_log_error(t_pred, y_pred.flatten())例子:>>> from sklearn.metrics import mean_squared_log_error>>> y_pred = np.array([[127450.63, 181983.39,181983.39 ]]) >>> t_pred = [105000., 172000., 189900.]>>> mean_squared_log_error(t_pred, y_pred.ravel())0.01418072635060214>>> mean_squared_log_error(t_pred, y_pred.reshape(-1))0.01418072635060214>>> mean_squared_log_error(t_pred, y_pred.flatten())0.01418072635060214
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python