I have a response from a kerras prediction that looks like this (y_pred):
array([[127450.63 ],
[181983.39 ],
[150607.72 ],
...,
[460400. ],
[ 92920.234],
[244455.97 ]], dtype=float32)
I need to compare the results to another array that looks like this (t_pred):
[105000. 172000. 189900. ... 131000. 132000. 188000.]
How would I go about converting array 1 to look like array 2 so I can calculate its mean_square_log_error, like this?:
mean_squared_log_error(t_pred, y_pred)
asked Sep 26, 2020 at 14:48
Johnny
8691 gold badge14 silver badges35 bronze badges
1 Answer 1
Use ravel() or reshape(-1) or flatten():
mean_squared_log_error(t_pred, y_pred.ravel())
Or
mean_squared_log_error(t_pred, y_pred.reshape(-1))
Or
mean_squared_log_error(t_pred, y_pred.flatten())
Example:
>>> 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
answered Sep 26, 2020 at 14:51
Grayrigel
3,6045 gold badges19 silver badges36 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py