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

input validation in predict of DummyRegressor is too strict #9832

Closed
dcatteeu opened this issue Sep 26, 2017 · 4 comments
Closed

input validation in predict of DummyRegressor is too strict #9832

dcatteeu opened this issue Sep 26, 2017 · 4 comments

Comments

@dcatteeu
Copy link

@dcatteeu dcatteeu commented Sep 26, 2017

Description

sklearn.dummy.DummyRegressor requires X to be numeric and have at least 1 feature in predict. IMO, this is too strict.

Also, it is not done in fit.

Steps/Code to Reproduce

import numpy as np
import pandas as pd
import sklearn.dummy

cls = sklearn.dummy.DummyRegressor(strategy='mean')
df = pd.DataFrame(data={'A': ['foo', 'bar', 'baz']})
X = df.loc[:, ['A']].values  # X's data is of type object
y = [1, 2, 3]
cls.fit(X, y)
cls.predict(X)

Expected Result

returns [2, 2, 2] and no ValueError at all.

Actual Result

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File ".../python3.6/site-packages/sklearn/dummy.py", line 468, in predict
    X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
  File ".../python3.6/site-packages/sklearn/utils/validation.py", line 382, in check_array
    array = np.array(array, dtype=dtype, order=order, copy=copy)
ValueError: could not convert string to float: 'baz'

Versions

Python 3.6.1 | packaged by conda-forge | (default, Mar 23 2017, 21:57:00)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
NumPy 1.12.1
SciPy 0.19.0
Scikit-Learn 0.18.1

Proposal

in sklearn.dummy.DummyRegressor, method predict call check_array with kwargs dtype=None and ensure_min_features=0

@jnothman
Copy link
Member

@jnothman jnothman commented Sep 26, 2017

@dcatteeu
Copy link
Author

@dcatteeu dcatteeu commented Sep 26, 2017

Good point. I forgot to mention there was a similar issue that is fixed in 0.19: #8916

In 0.19, check_array is called with force_all_finite=False. This means you can now pass data with missing values, but X must still be numeric and have at least 1 feature.

@jnothman
Copy link
Member

@jnothman jnothman commented Sep 26, 2017

Okay

@jnothman
Copy link
Member

@jnothman jnothman commented Sep 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants