Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] mean_squared_error fails with mixed dtype combinations unlike scikit-learn #4442

Closed
beckernick opened this issue Dec 10, 2021 · 2 comments · Fixed by #4770
Closed

[BUG] mean_squared_error fails with mixed dtype combinations unlike scikit-learn #4442

beckernick opened this issue Dec 10, 2021 · 2 comments · Fixed by #4770
Assignees
Labels
bug Something isn't working Cython / Python Cython or Python issue good first issue Good for newcomers

Comments

@beckernick
Copy link
Member

cuml.metrics.mean_squared_error is sensitive to dtype combinations (float32, float64, int32, etc.). It will throw if the predictions array is a different dtype than the y_true array for float or integer inputs.

import numpy as np
import cuml
from sklearn.metrics import mean_squared_errory = np.array([1,2,3], dtype="float64")
pred = np.array([1,2.2,3], dtype="float32")
print(mean_squared_error(y, pred))
cuml.metrics.mean_squared_error(y, pred)
0.013333339691162868
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_12350/3868277037.py in <module>
      6 pred = np.array([1,2.2,3], dtype="float32")
      7 print(mean_squared_error(y, pred))
----> 8 cuml.metrics.mean_squared_error(y, pred)

~/conda/envs/rapids-21.12/lib/python3.8/site-packages/cuml/internals/api_decorators.py in inner(*args, **kwargs)
    358         def inner(*args, **kwargs):
    359             with self._recreate_cm(func, args):
--> 360                 return func(*args, **kwargs)
    361 
    362         return inner

cuml/metrics/regression.pyx in cuml.metrics.regression.mean_squared_error()

cuml/metrics/regression.pyx in cuml.metrics.regression._prepare_input_reg()

~/conda/envs/rapids-21.12/lib/python3.8/contextlib.py in inner(*args, **kwds)
     73         def inner(*args, **kwds):
     74             with self._recreate_cm():
---> 75                 return func(*args, **kwds)
     76         return inner
     77 

~/conda/envs/rapids-21.12/lib/python3.8/site-packages/cuml/internals/api_decorators.py in inner(*args, **kwargs)
    358         def inner(*args, **kwargs):
    359             with self._recreate_cm(func, args):
--> 360                 return func(*args, **kwargs)
    361 
    362         return inner

~/conda/envs/rapids-21.12/lib/python3.8/site-packages/cuml/common/input_utils.py in input_to_cuml_array(X, order, deepcopy, check_dtype, convert_to_dtype, safe_dtype_conversion, check_cols, check_rows, fail_on_order, force_contiguous)
    388             type_str = X_m.dtype
    389             del X_m
--> 390             raise TypeError("Expected input to be of type in " +
    391                             str(check_dtype) + " but got " + str(type_str))
    392 

TypeError: Expected input to be of type in [dtype('float64')] but got float32
@beckernick beckernick added bug Something isn't working Cython / Python Cython or Python issue labels Dec 10, 2021
@github-actions
Copy link

github-actions bot commented Jan 9, 2022

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

@github-actions
Copy link

github-actions bot commented Apr 9, 2022

This issue has been labeled inactive-90d due to no recent activity in the past 90 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed.

@beckernick beckernick added the good first issue Good for newcomers label May 5, 2022
rapids-bot bot pushed a commit that referenced this issue Jun 29, 2022
Resolves #4442

This PR fixes the issue with using mixed data types in regression errors like `mean_squared_error`, `mean_absolute_error` and `mean_squared_log_error`.

Authors:
  - Shaswat Anand (https://github.com/shaswat-indian)

Approvers:
  - William Hicks (https://github.com/wphicks)

URL: #4770
jakirkham pushed a commit to jakirkham/cuml that referenced this issue Feb 27, 2023
…#4770)

Resolves rapidsai#4442

This PR fixes the issue with using mixed data types in regression errors like `mean_squared_error`, `mean_absolute_error` and `mean_squared_log_error`.

Authors:
  - Shaswat Anand (https://github.com/shaswat-indian)

Approvers:
  - William Hicks (https://github.com/wphicks)

URL: rapidsai#4770
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Cython / Python Cython or Python issue good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants