Add optional parameter to return raw data for diabetes dataset - #16605
Conversation
|
The dataset description included here says that each column has been scaled
and centred, which accounts for this difference. I agree that there would
be benefit in allowing the user to retrieve the raw values. Apart from
anything else, there is some data leakage in scaling across training and
test data.
But this should be done by providing a parameter to optionally return
standardized values (default True to preserve current behaviour).
|
My bad, I completely missed that part from the description. In addition to the leakage issue, not all the columns (for ex gender) makes sense to be scaled and centered. I can augment this pr to return raw vs scaled / centered based on an optional parameter |
|
Thanks @jnothman for feedback. I followed your suggestion and added an optional parameter |
|
Thanks! Could you please add a new test to check that the new option works as described? For instance a new test that loads that when fetching the un-standardized data and standardizing our-selves we get a resulting data matrix that is close to the one we fetch when we call load_diabetes with |
I created a new test called |
|
I would like to have a test that checks that the standardized values are what they are supposed to be but it does not seem to be the case. For instance the following test: def test_load_diabetes_raw():
diabetes_raw = load_diabetes(standardized=False)
assert diabetes_raw.data.shape == (442, 10)
assert diabetes_raw.target.size, 442
assert len(diabetes_raw.feature_names) == 10
assert diabetes_raw.DESCR
diabetes_default = load_diabetes()
np.testing.assert_allclose(
scale(diabetes_raw.data),
diabetes_default.data
)fails with: I haven't had a deeper look but there is something wrong either in our data files or in the assumptions we make about them. |
|
Ah, from the dataset description: So looks like we would need to divide the raw values by 442 ** 0.5 after scaling it. Adjusting for precision loss, this test no longer fails: |
ogrisel
left a comment
There was a problem hiding this comment.
Thanks for the clarification!
But now I have the following concern:
|
|
||
| standardized : bool, default=True | ||
| If True, the feature variables are mean centered and scaled by the | ||
| standard deviation times `n_samples`. |
There was a problem hiding this comment.
So this should be "standard deviation times the square root of n_samples.", no?
This is weird to call this "standardized" because it does not not match the usual Standardization we implement in StandardScaler.
Maybe we should rename this standardized parameter to a more neutral name such as preprocessed or scaled.
There was a problem hiding this comment.
Good point. I changed the description to reflect standard deviation times the square root of n_samples and renamed the parameter to scaled.
There was a problem hiding this comment.
Just realized that I took the description from descr/diabetes.rst, so I updated that one too
jnothman
left a comment
There was a problem hiding this comment.
I'm happy with this, but do we think it's necessary to distribute both diabetes_data_raw.csv.gz and diabetes_data.csv.gz, rather than just distributing one and scaling the data on the fly?
+1 for doing this. |
|
I removed the (scaled) diabetes_data.csv.gz file and switched to relying on on the unscaled data I'm not sure whether we should go ahead (and consider this to be a fix) or not. In any case, I think shipping two versions of the data that's are not equal within float64 tolerance (which is much less that 1e-4) is not ideal. |
|
If we only have 2 docstring failings, then I think that we can use the proposed option to rescale the dataset. |
glemaitre
left a comment
There was a problem hiding this comment.
LGTM. Waiting to see if there are some remaining failures but otherwise I will merge this one.
|
So all tests are passing now. I am merging. Thanks to all. |
Issue
Diabetes dataset from
sklearn.datasetshad incorrect values (the target is fine).For instance:
returns
What does this implement/fix? Explain your changes.
The compressed csv file was incorrect https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/data/diabetes_data.csv.gz
I uploaded data from the source file indicated in the description (https://www4.stat.ncsu.edu/~boos/var.select/diabetes.tab.txt)
Testing the same code locally yields:
Any other comments?