Skip to content

[MRG + 1] replace mutable default argument in _RidgeGCV #4376

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

Closed
wants to merge 76 commits into from

Conversation

DonBeo
Copy link

@DonBeo DonBeo commented Mar 10, 2015

This is a very small change to make me familiar with the repository and the git system. The mutable default value is replaced with a numpy array. This code passes al the tests.

@DonBeo
Copy link
Author

DonBeo commented Mar 10, 2015

Sorry I did a mistake. The numpy array are mutable as well. Maybe we should stop this push. Anyway this should not influence the library at all.

@amueller
Copy link
Member

Well, you could use a tuple as you said. It would be good to add a test, though.

@DonBeo DonBeo closed this Mar 10, 2015
@amueller
Copy link
Member

Why did you close this?

@DonBeo
Copy link
Author

DonBeo commented Mar 10, 2015

I was going to open a new one with the tuple instead of array. Is this not the correct procedure?

@DonBeo DonBeo reopened this Mar 10, 2015
@DonBeo
Copy link
Author

DonBeo commented Mar 10, 2015

Sorry I did not know that was possible to update the branch during the pull. I reopen the pull request. I hope that this does not lead to confusion. Regarding the test I need some help. I will ask on the mail list.

@amueller
Copy link
Member

You can ask here ;)
The pull request was already updated when you closed. The pull request will keep tracking your branch.
Actually, I don't think this can easily be tested. I'll try to add a test to the common_tests, but that might be a bit too tricky for this PR.

@amueller amueller changed the title replace mutable default argument in _RidgeGCV [MRG + 1] replace mutable default argument in _RidgeGCV Mar 10, 2015
@amueller
Copy link
Member

I think this looks good to merge.
We'll need another review though. The travis failure is unrelated and I restarted the tests.

fit_intercept=True, normalize=False, scoring=None,
score_func=None, loss_func=None, cv=None, gcv_mode=None,
store_cv_values=False):
self.alphas = alphas
self.alphas = np.asarray(alphas)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line mutates the init and we shouldn't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh indeed. this needs to go into the fit method.

@arjoly
Copy link
Member

arjoly commented Mar 10, 2015

Whenever my remarks is addressed, +1!

@DonBeo
Copy link
Author

DonBeo commented Mar 10, 2015

Sorry I need a clarification.
Should we never modify the init method?
Should I change it?

Let me know!

@amueller
Copy link
Member

Yes, we should never modify anything in the __init__ method, as parameters might get set via set_params and therefore bypass __init__.
Please remove the conversion from __init__ and create a local variable in fit that is set using the conversion.

@DonBeo
Copy link
Author

DonBeo commented Mar 10, 2015

I have replaced the self.alphas value in fit. I think this make the code more clear. Otherwise I can define a local variable alphas_loc = np.asarray(self.alphas) and replace all the occurencies of self.alphas with alphas_loc in the fit method. I do not know which approach is preffered.

@amueller
Copy link
Member

the second approach, though you can just call the variable alphas.
The reason is that otherwise you overwrite the user input.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 95.12% when pulling 70c3f7c on DonBeo:my-feature into 588b3f7 on scikit-learn:master.

@DonBeo
Copy link
Author

DonBeo commented Mar 11, 2015

in the linereader function it was quiet difficult to change the default value. I have been able to replace it but I am not happy of the quality of the solution. Maybe it can be improved

@@ -847,8 +847,10 @@ def fit(self, X, y, sample_weight=None):
-------
self : Returns self.
"""
alphas = np.asarray(self.alphas)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests are passed also without that line. The problem is that the default argiment was a numpy array. If you want I can delete it and just use self.alphas in all the method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the default argiment was a numpy array.

Have I missed something? It seems to be a list.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/ridge.py line 832. The default argument for init was a numpy array. The code works with both self.alphas everywhere or with alphas=np.array(self.alphas). Let me know what version should I keep

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go with the least number of lines to modify and go with the tuple.
Though, the doc says that it accepts (only) numpy array. http://scikit-learn.org/dev/modules/generated/sklearn.linear_model.RidgeClassifierCV.html#sklearn.linear_model.RidgeClassifierCV From a user perpsective, I would expect array-like for alphas.

In that case, I would add a regression support and add support for array-like.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok then I think the last updated version should be ok. I am using tuples as default value and we expect the users to use np.array. I think that this should work well. Unless I am not missing something. In that case explain me :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I would add a regression support and add support for array-like.

I mean. I would add a test for this. By the way, we should update the documentation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid that you have to help me with the test. I am not sure of what to test and how to do it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For instance, you could test that passing a tuple of alpha, a numpy array of alpha or a list of alpha give similar results.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I have added a test. Let me know if you think that this is fine.

@DonBeo
Copy link
Author

DonBeo commented Mar 12, 2015

I think that this conflict can be caused by the test. My understanding is that to solve it I have to write the original sklearn repository. I think that only a moderator can do that.

@DonBeo
Copy link
Author

DonBeo commented Mar 20, 2015

Hi,
I did rebase again. Hopefully now it should be fine.
My understanding is that with the command git rebase -i master I can delete some of the commits but at the moment all the commits are related to changes that I did.

Let me know if this is fine.

Sorry for the confusion I am starting to understand git and the next pull will hopefully be less painful

@amueller
Copy link
Member

when you do rebase -i, you can mark all but the first commit as squash so they will be resolved to a single commit.

DonBeo added 4 commits March 20, 2015 20:50
# The first commit's message is:

# This is a combination of 2 commits.
# The first commit's message is:

# This is a combination of 2 commits.
# The first commit's message is:

# This is a combination of 2 commits.
# The first commit's message is:

# This is a combination of 2 commits.
# The first commit's message is:

# This is a combination of 2 commits.
# The first commit's message is:

# This is a combination of 3 commits.
# The first commit's message is:
# This is a combination of 4 commits.
# The first commit's message is:
# This is a combination of 18 commits.
# The first commit's message is:
replace mutable default argument in _RidgeGCV

# This is the 2nd commit message:

use tuples instead of mutable  default values

# This is the 3rd commit message:

use tuples instead of mutable  default values

# This is the 4th commit message:

redefinition of alphas is removed from init and added to fit method

# This is the 5th commit message:

use tuples instead of mutable  default values

# This is the 6th commit message:

joblib is restored to its original version. In ridge.py alphas is not casted to a numpy array anymore

# This is the 7th commit message:

collections library not required anymore and os it is removed

# This is the 8th commit message:

use tuples instead of mutable  default values

# This is the 9th commit message:

conflict solved

# This is the 10th commit message:

update documentation

# This is the 11th commit message:

documentation updated

# This is the 12th commit message:

use tuples instead of mutable  default values

# This is the 13th commit message:

solve conflict

# This is the 14th commit message:

up

# This is the 15th commit message:

conflict solved

# This is the 16th commit message:

conflict solved

# This is the 17th commit message:

remose white lines
# This is the 18th commit message:

delete white lines

# This is the 2nd commit message:

use tuples instead of mutable  default values

# This is the 3rd commit message:

use tuples instead of mutable  default values

# This is the 4th commit message:

redefinition of alphas is removed from init and added to fit method

# This is the 2nd commit message:

conflict solved

# This is the 3rd commit message:

use tuples instead of mutable  default values

# This is the 2nd commit message:

documentation updated

# This is the 2nd commit message:

use tuples instead of mutable  default values

# This is the 2nd commit message:

redefinition of alphas is removed from init and added to fit method

# This is the 2nd commit message:

conflict solved

# This is the 2nd commit message:

use tuples instead of mutable  default values

# This is the 2nd commit message:

redefinition of alphas is removed from init and added to fit method
# The first commit's message is:
conflict solved

# This is the 2nd commit message:

documentation updated

# This is the 3rd commit message:

remose white lines
# This is the 4th commit message:

delete white lines
@DonBeo
Copy link
Author

DonBeo commented Mar 20, 2015

I did rebase again. The number of commits now is lower. My understanding is that I can not have a single commit for certain addition.

I hope that this if fine now.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling fb11bc4 on DonBeo:my-feature into * on scikit-learn:master*.

@amueller
Copy link
Member

Can you please look at the commit count shown a the top? It shows 97 commits.
Also, you can do anything within a single commit (apart from a merge, which you should not have).

amueller and others added 8 commits March 23, 2015 11:12
[MRG+2] FIX make StandardScaler & scale more numerically stable
# The first commit's message is:
# This is a combination of 2 commits.
# The first commit's message is:

# This is a combination of 2 commits.
# The first commit's message is:

# This is a combination of 2 commits.
# The first commit's message is:

# This is a combination of 2 commits.
# The first commit's message is:

# This is a combination of 3 commits.
# The first commit's message is:
# This is a combination of 2 commits.
# The first commit's message is:

# This is a combination of 3 commits.
# The first commit's message is:
# This is a combination of 2 commits.
# The first commit's message is:

# This is a combination of 3 commits.
# The first commit's message is:
# This is a combination of 2 commits.
# The first commit's message is:

documentation updated

use tuples instead of mutable  default values

solve conflict

up

conflict solved

conflict solved

remose white lines

delete white lines

use tuples instead of mutable  default values

use tuples instead of mutable  default values

redefinition of alphas is removed from init and added to fit method

conflict solved

use tuples instead of mutable  default values

documentation updated

use tuples instead of mutable  default values

redefinition of alphas is removed from init and added to fit method

conflict solved

use tuples instead of mutable  default values

redefinition of alphas is removed from init and added to fit method

conflict solved

documentation updated

remose white lines

delete white lines

update documentation

replace mutable default argument in _RidgeGCV

# This is the 2nd commit message:

redefinition of alphas is removed from init and added to fit method

# This is the 2nd commit message:

use tuples instead of mutable  default values

# This is the 3rd commit message:

conflict solved

# This is the 2nd commit message:

documentation updated

# This is the 2nd commit message:

remose white lines
# This is the 3rd commit message:

delete white lines

# This is the 2nd commit message:

redefinition of alphas is removed from init and added to fit method

# This is the 2nd commit message:

conflict solved

# This is the 3rd commit message:

use tuples instead of mutable  default values

# This is the 2nd commit message:

documentation updated

# This is the 2nd commit message:

redefinition of alphas is removed from init and added to fit method

# This is the 2nd commit message:

conflict solved

# This is the 2nd commit message:

redefinition of alphas is removed from init and added to fit method

# This is the 2nd commit message:

documentation updated

# This is the 3rd commit message:

remose white lines
# This is the 4th commit message:

delete white lines
[MRG+1] FIX LDA(solver="lsqr"): make sure the right error is raised on transform
@amueller
Copy link
Member

sorry, I'd be happy to help you, but I just missed you on IRC. you can ping me as amueller, then something will bounce on my desktop ;)

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 6d2c599 on DonBeo:my-feature into * on scikit-learn:master*.

@TomDLT
Copy link
Member

TomDLT commented May 13, 2015

#4713 merged
This PR can be closed

@arjoly arjoly closed this May 13, 2015
@DonBeo DonBeo deleted the my-feature branch May 25, 2015 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants