[MRG+1] Correcting length of explained_variance_ratio_, eigen solver, final PR#7632
[MRG+1] Correcting length of explained_variance_ratio_, eigen solver, final PR#7632jnothman merged 10 commits intoscikit-learn:masterfrom
Conversation
LinearDiscriminantAnalysis class will be of length n_components, if provided. If not provided, will have a maximum length of n_classes. The attribute will have the same length, whatever the solver (SVD, Eigen).
doc/whats_new.rst
Outdated
| - Access to public attributes ``.X_`` and ``.y_`` has been deprecated in | ||
| :class:`isotonic.IsotonicRegression`. By `Jonathan Arfa`_. | ||
|
|
||
| - Length of `explained_variance_ratio` of :clas:`discriminant_analysis.LinearDiscriminantAnalysis` |
doc/whats_new.rst
Outdated
| :class:`discriminant_analysis.LinearDiscriminantAnalysis` now returns | ||
| correct results. By `JPFrancoia`_ | ||
| :clas:`discriminant_analysis.LinearDiscriminantAnalysis` now returns correct results. | ||
| Attribute `explained_variance_ratio` calculated with SVD and Eigen solver are now of |
|
Ok. Under what should it be then ? We are almost there (and no more test failures). |
@amueller, should we create a 0.18.1 heading in what's new in master? |
|
There's now a 0.18.1 section |
0.18.1. I created the sub-section "API changes summary" under 0.18.1.
|
Ok, I put my changes under 0.18.1. I created the sub-section API changes summary under 0.18.1 too. |
There was a problem hiding this comment.
You've repeatedly use :clas:. Should be :class:
There was a problem hiding this comment.
Arf. Sorry to waste your time with a typo.
doc/whats_new.rst
Outdated
| `#6497 <https://github.com/scikit-learn/scikit-learn/pull/6497>`_ | ||
| by `Sebastian Säger`_ | ||
|
|
||
| - Attribute ``explained_variance_ratio`` of :class:`discriminant_analysis.LinearDiscriminantAnalysis` |
There was a problem hiding this comment.
I can waste both of our time a little further by asking that you make the lines somewhat shorter (around 80 chars max) and insert a link to the issue/PR which seems to have been adopted here... Sorry.
There was a problem hiding this comment.
No problem. Done.
|
Otherwise LGTM |
sklearn/discriminant_analysis.py
Outdated
|
|
||
| # Get maximum length for explained_variance_ratio_ | ||
| if self.n_components is None: | ||
| max_length_exp = len(self.classes_) |
There was a problem hiding this comment.
shouldn't it be len(self.classes_) - 1?
There was a problem hiding this comment.
I don't think so. If n_components is not provided, then explained_variance_ratio_ will have a length of maximum len(self.classes). So [:max_length_exp]
There was a problem hiding this comment.
Well, that's a bug, the last one will always be zero.
|
Please explain why you think it should be If I introduce this change, the tests fail: |
|
The test fails because it's also wrong for the other solver imho. My understanding is that the |
Fix for Eigen and SVD solvers.
|
You are right (I double-checked, just to be sure). I fixed it for the 2 solvers, and I updated the tests so in the future the length of this attribute will be checked. |
doc/whats_new.rst
Outdated
|
|
||
| - Length of `explained_variance_ratio` of | ||
| :class:`discriminant_analysis.LinearDiscriminantAnalysis` | ||
| is now the same for Eigen and SVD solvers. (`#7632 |
There was a problem hiding this comment.
I think you should be more explicit by saying that it changed for both and is now min(n_components, n_classes - 1).
|
can you maybe add an attribute |
|
There is already an attribute |
|
Not really. We sometimes have attributes with names that are the same as parameters (but with a trailing underscore) if the "real" value is computed from the training data. We could do |
LinearDiscriminantAnalysis class. Used to determinate the maximum number of components returned by the class. Also used for the lenght of explained_variance_ratio_. See PR 7632. Fixed some stuff to be more PEP8.
|
Hum ok, I decided to call it _max_components, because it is really more explicit. This attribute is only used to store the maximum number of components of the classifier, so let's call a cat a cat. I made it private for now. Let me know if you agree with these changes. |
|
hm I'm not sure why you feel |
|
LGTM :) |
|
(There's one +1 on the current version which is from me. I think @jnothman's doesn't apply any more because there were substantial changes. maybe he has time to review again) |
|
LGTM |
Reference Issue
Fix #6032
What does this implement/fix? Explain your changes.
Attribute explained_variance_ratio_ from LinearDiscriminantAnalysis class will be of length n_components (eigen solver).
Any other comments?
This PR follows PR 7616. I mixed up my git history, so it was easier to open a new PR.