8000 Qda lda consistent by chinmay0301 · Pull Request #8000 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Qda lda consistent #8000

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

Conversation

chinmay0301
Copy link

Reference Issue

#7998

What does this implement/fix? Explain your changes.

Renamed the variable store_variances to store_variance and tried to add a deprecation cycle in the init function. Please suggest corrections, as this is my first attempt to add a deprecation cycle

Any other comments?

Copy link
Member
@amueller amueller left a comment

Choose a reason for hiding this comment

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

Also check the test failures.

self.priors = np.asarray(priors) if priors is not None else None
self.reg_param = reg_param
self.store_covariances = store_covariances
#self.store_covariances = store_covariances
Copy link
Member

Choose a reason for hiding this comment

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

remove this line

@@ -623,11 +623,15 @@ class QuadraticDiscriminantAnalysis(BaseEstimator, ClassifierMixin):
Discriminant Analysis
"""

def __init__(self, priors=None, reg_param=0., store_covariances=False,
tol=1.0e-4):
def __init__(self, priors=None, reg_param=0.,store_covariance=False, tol=1.0e-4,store_covariances=None):
Copy link
Member

Choose a reason for hiding this comment

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

this is not pep8

if store_covariances is not None:
warnings.warn("'store_covariances' was renamed to 'store_covariance' in version 0.17 and "
"will be removed in later versions.", DeprecationWarning)
self.store_covariance = store_covariances
Copy link
Member

Choose a reason for hiding this comment

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

You are not storing store_covariance...

Copy link
Author

Choose a reason for hiding this comment

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

But in the docs it was mentioned that if we want to deprecate a parametre, if that is not none, then we need to assign the value of the old parametre to the new parametre.

Copy link
Author

Choose a reason for hiding this comment

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

image

Copy link
Member

Choose a reason for hiding this comment

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

I think you should handle the deprecation in fit, not here. In scikit-learn, __init__ is just used to store parameters, otherwise, in the general case, we will break parameter searches.

In fit set a local copy of store_covariance on the basis of both old and new params.

Copy link
Member

Choose a reason for hiding this comment

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

@chinmay0301 I'm not sure how your comment relates to mine. You are not storing store_covariance. So is someone uses the new parameter, nothing happens.

@chinmay0301
Copy link
Author
chinmay0301 commented Dec 8, 2016 via email

@jnothman
Copy link
Member
jnothman commented Dec 8, 2016 via email

@chinmay0301
Copy link
Author

def fit(self, X, y, store_covariance=None, store_covariances=None, tol=None):
if store_covariances:
warnings.warn("The parameter 'store_covariances' is deprecated as "
"store_covariance of version 0.17 and will be removed "
"in 0.19 parameter is no longer necessary because the "
"value is set via the estimator initialisation or "
"set_params method.", DeprecationWarning)
store_covariance = store_covariances

Is this correct? Or should I store the value of the old parameter (if specified) in a different variable?

@jnothman
Copy link
Member
jnothman commented Dec 8, 2016 via email

@chinmay0301
Copy link
Author

Sorry I am not quite understanding what is to be done exactly :/

@jnothman
Copy link
Member
jnothman commented Dec 8, 2016 via email

Copy link
Contributor
@dalmia dalmia left a comment

Choose a reason for hiding this comment

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

Implement the changes I've mentioned in a serial order and you'll be done with your first PR. :)

@@ -623,11 +623,15 @@ class QuadraticDiscriminantAnalysis(BaseEstimator, ClassifierMixin):
Discriminant Analysis
"""

def __init__(self, priors=None, reg_param=0., store_covariances=False,
tol=1.0e-4):
def __init__(self, priors=None, reg_param=0.,store_covariance=False, tol=1.0e-4,store_covariances=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

@chinmay0301 Just be calm, I'll guide you through the process.
Firstly, change this to:

def __init__(self, priors=None, reg_param=0., store_covariance=False,
             tol=1.0e-4, store_covariances=False):

This differs from the one you wrote because this follows the PEP8 guidelines. Please go throught the Contributor's guide for more information.

if store_covariances is not None:
warnings.warn("'store_covariances' was renamed to 'store_covariance' in version 0.17 and "
"will be removed in later versions.", DeprecationWarning)
self.store_covariance = store_covariances
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to make the value of the parameter store_covariance equal to that of the store_covariances if it is passed. This means, you need to replace:

self.store_covariance = store_covariances

With:

store_covariance = store_covariances

self.priors = np.asarray(priors) if priors is not None else None
self.reg_param = reg_param
self.store_covariances = store_covariances
#self.store_covariances = store_covariances
Copy link
Contributor
@dalmia dalmia Dec 9, 2016

Choose a reason for hiding this comment

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

This is where you store the value of store_covariance. You need to change this commented line to:

self.store_covariance = store_covariance

tol=1.0e-4):
def __init__(self, priors=None, reg_param=0.,store_covariance=False, tol=1.0e-4,store_covariances=None):
if store_covariances is not None:
warnings.warn("'store_covariances' was renamed to 'store_covariance' in version 0.17 and "
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this to: in version 0.19 and

def __init__(self, priors=None, reg_param=0.,store_covariance=False, tol=1.0e-4,store_covariances=None):
if store_covariances is not None:
warnings.warn("'store_covariances' was renamed to 'store_covariance' in version 0.17 and "
"will be removed in later versions.", DeprecationWarning)
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this to: will be removed in version 0.21.

if self.store_covariances:
self.covariances_ = cov
if self.store_covariance:
self.covariance_ = cov
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to change this line. Revert this back to covariances_.

@chinmay0301
Copy link
Author
chinmay0301 commented Dec 9, 2016 via email

@chinmay0301
Copy link
Author

Hi, made the suggested changes. Please have look once @dalmia if its correct.

@@ -623,11 +623,28 @@ class QuadraticDiscriminantAnalysis(BaseEstimator, ClassifierMixin):
Discriminant Analysis
"""

def __init__(self, priors=None, reg_param=0., store_covariances=False,
tol=1.0e-4):
<<<<<<< HEAD

Choose a reason for hiding this comment

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

oops :)

@@ -623,11 +623,28 @@ class QuadraticDiscriminantAnalysis(BaseEstimator, ClassifierMixin):
Discriminant Analysis
"""

def __init__(self, priors=None, reg_param=0., store_covariances=False,
tol=1.0e-4):
<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

Everything looks fine apart from the fact that your merge wasn't very clean. Remove lines:

  • 626
  • 637-647
  • 721
  • 723-725

Copy link
Author

Choose a reason for hiding this comment

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

yeah, corrected that.

warnings.warn("'store_covariances' was renamed to 'store_covariance'"
"in version 0.19 and will be removed in the "
"version 0.21.", DeprecationWarning)
store_covariance = store_covariances
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation error!

tol=1.0e-4):
def __init__(self, priors=None, reg_param=0., store_covariance=False,
tol=1.0e-4, store_covariances=False):
if store_covariances is not None:
Copy link
Member

Choose a reason for hiding this comment

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

this should be done in fit.

Copy link
Author

Choose a reason for hiding this comment

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

So should leave the init function as it was in the master branch?

Copy link
Member

Choose a reason for hiding this comment

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

No you need to add store_covariance and store it.

Copy link
Contributor
@dalmia dalmia Dec 9, 2016

Choose a reason for hiding this comment

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

Since store_covariances is deprecated in fit and will be removed as a parameter in 0.19 do we need to do this in fit? @amueller

Copy link
Member

Choose a reason for hiding this comment

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

I'm not talking about the parameter passed into fit. I'm talking about the parameter passed in __init__. That should be validated in fit not in __init__.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I get you now. Since 0.19 deprecates store_covariances I don't think we need to add this particular deprecation warning, the following change in fit should suffice:

self.store_covariance = store_covariances

tol=1.0e-4):
def __init__(self, priors=None, reg_param=0., store_covariance=False,
tol=1.0e-4, store_covariances=False):
if store_covariances is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

@chinmay0301 remove this check entirely here and change this in fit:

self.store_covariances = store_covariances

to:

self.store_covariance = store_covariances

@jnothman
Copy link
Member

@dalmia, I don't really think it's appropriate to make statements like

Implement the changes I've mentioned in a serial order and you'll be done with your first PR. :)

Perhaps we don't give contributors enough assurances about how much work they'll need to complete a PR, but that's because sometimes we find that it is more work than initially anticipated. It's better to instruct, or point to precedent of similar changes, with the hope that all will proceed smoothly, than to make promises!)

@dalmia
Copy link
Contributor
dalmia commented Dec 11, 2016

@jnothman I am sorry. I was just trying to reassure but yes, I shouldn't be making promises. Thank you for letting me know. I'll keep that in mind from the next time onwards.

@dalmia
Copy link
Contributor
dalmia commented Dec 17, 2016

@chinmay0301 do you want to work on the issue further?

@chinmay0301
Copy link
Author
chinmay0301 commented Dec 18, 2016 via email

"is set via the estimator initialisation or "
"set_params method.", DeprecationWarning)
self.store_covariances = store_covariances
warnings.warn("'store_covariances' was renamed to 'store_covariance'"
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't change the warning message here. Carefully reading the earlier message shows that this statement won't be there from 0.19 onwards and hence, this is just added to ensure compatibility until 0.19. So, your warning message is not valid. The best you could do is add a note alongside the one already present as:
Also, 'store_covariances' is renamed to 'store_covariance' in 0.19.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, change the docstring and the example written along with it to use store_covariance now.

Copy link
Member

Choose a reason for hiding this comment

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

You need to update your copy of master and merge with it. You'll find this code path has disappeared.

@dalmia
Copy link
Contributor
dalmia commented Dec 20, 2016

The errors are:

Exception occurred:
  File "/home/ubuntu/scikit-learn/doc/sphinxext/sphinx_gallery/docs_resolv.py", line 48, in _get_data
    with open(url, 'r') as fid:
IOError: [Errno 2] No such file or directory: '/home/ubuntu/scikit-learn/doc/_build/html/stable/modules/generated/sklearn.feature_selection.SelectKBest.rst.html'
The full traceback has been saved in /tmp/sphinx-err-9IJ5UT.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
Embedding documentation hyperlinks in examples..
	processing: feature_stacker.html
make: *** [html-noplot] Error 1

./build_tools/circle/build_doc.sh returned exit code 2

Action failed: ./build_tools/circle/build_doc.sh

@jnothman Should rebuilding remove the error?

@jnothman
Copy link
Member
jnothman commented Dec 20, 2016 via email

@jnothman
Copy link
Member

@chinmay0301, this remains quite broken. Are you still working on it?

@chinmay0301
Copy link
Author
chinmay0301 commented Dec 26, 2016 via email

@jnothman
Copy link
Member

Okay. I'll close then.

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.

5 participants
0