Repository navigation
WIP: PCA class - #1596
WIP: PCA class#1596jseabold wants to merge 18 commits into
Conversation
|
comp-dimensionreduction ? |
|
This needs unit tests to verify results. |
|
I had started a sandbox subdirectory "datarich" borrowing the term from the econometrics literature that I was looking at. |
|
See #1238. |
|
It doesn't look to me like cov is completely finished. Correlation matrix agrees with Stata. |
|
Eyeball tests agree with Stata and R. Tests now pass against your old matlab ones as well. |
|
What bells and whistles should we add to the PCA results? Scree plots, a projection method, what else? |
|
I added some bells and whistles to the todo checklist. Any other suggestions are welcome. |
|
my original usecase PCR |
|
Yeah, I'm headed that way for diffusion index stuff and principal fitted components (Cook). That code should still work with this if the imports get fixed. I might have changed the defaults from covariance to correlation (or vice versa) given the changes I had to make to the tests. I wonder if we shouldn't deprecate the sandbox code. I didn't want to get in that kind of a situation, but we know this code has been used. |
|
I don't remember what the code was supposed to do with respect to demean. demean is an option, but if demean=False, we still use corrcoef or cov in pca, but not in pca_svd. |
There was a problem hiding this comment.
if keepdim is None, then proj is useless, it should be just X
There was a problem hiding this comment.
Yeah I saw that. I'm just going to change it to a method I think.
|
my guess is that xreduced/projections is not in the original space if corr=True, My guess is that we need to revert the standardization. |
|
In terms of methods: what I was playing around for some time (but don't have committed the examples AFAICS) is about the properties of PCA as linear or affine transformation. In terms of regression we have PCA as a stateful transform, x -> f and f -> x (x is data, f is factors) we need x -> f for a new x with old transformation matrix to make predictions. |
|
Added a scree plot method. Question. Should we give an option to plot the explained/cumulative explained variance in the scree plot instead of just the eigenvalues? Added the notebook from @kshedden. Refactored it to take advantage of pandas features and the new PCA class. Raises another question. Should we use the wrapping stuff and preserve the pandas indices, if given. The plotting code could be simplified a bit if they were labelled pandas objects. |
|
I'm not sure PCA makes the most sense in stastmodels/tools. Especially re: the docs. Tools wouldn't be the first place I checked for dimension reduction code. I'm not wild about |
|
@kshedden where did you get this fertility data? From the world bank API? Link? I recall there being some fertility rate data floating around a few years ago that I was looking at that was definitely non-free. |
|
Nevermind, I see the indicator name and can read the WB terms of use. |
|
Yes, I think an option to make the plot in terms of variance explained is On Wed, Apr 23, 2014 at 8:29 AM, Skipper Seabold
|
|
NIce. Add a fit method? It will make it easier to use wrapped results Possible to do without though a la filters, exponential smoothing. This would be our only class that does the 'fitting' in the |
|
I don't know, I haven't gone through many usecases yet for the PCA class. Alternative: the PCA class is storing the full svd, or an svd up to a max number of components. I guess that the PCA class will have different use cases than the pure pca_svd function. For examples like Kerby's and the one in the blog the main target is to make it convenient. For large scale PCR we have to take into account that we only want to (calculate and) store a few components or non at all. |
|
for example in one of the talks at pycon for natural language processing with scikit-learn, the initial number of "features" was huge, and after PCA he kept 50 components. |
|
I left it without a fit for now. We don't really need a wrapper here (yet). |
|
While I'm thinking about it. We should switch to using the symmetric eigendecomposition routines. |
|
I redid my PCA notebook example, the new version is on the wiki page (same place as before, also linked below). I think I was incorrectly centering before, which basically had the effect of removing the first PC factor, which captured the variation in overall fertility level. |
|
I find the terminology for the return values of the two PCA functions a bit confusing. What is currently called "factors" is often called "scores" or "factor scores". What is currently called "evecs" is often called "loadings" or "factor loadings". |
|
That was one of the motivations for the convenience class. Is it clearer? Sent from my mobile |
|
I hadn't noticed the PCA class. It is more clear, especially for loadings. But the word "scores" is very commonly used in PCA and does not seem to appear anywhere. Perhaps a mention in the docstring would be helpful. |
|
IMO, background: I wrote the PCA function just after coming from matlab and doing "Factor Models" and principal component regression, and the PCA terminology didn't make any sense to me. open PR for PCA class that needs more review and merging #1596 |
|
(silly thing to link to the PR from the PR, very early in the morning local time) |
|
Heavy overlap with #2004 now |
|
PR #2004 has been merged. |
|
+1 for this to be closed. |
|
If there is a chance this will be merged, I'm happy to rebase
|
|
@bashtage Your PCA version has been merged a year ago. |
|
Ok. Perils is github email responses. I think I strictly nested, including
|
|
Thanks, closing then |
Fair warning, I haven't looked at this code in 2 years. Rescued and rebased from upstream. Deleted the branch in upstream to keep things tidy.
Would be nice to replicate the notebook of @kshedden with the class to get an idea of what needs to be fixed, added, generalized, etc. Comments (or PRs) very welcome.
http://nbviewer.ipython.org/urls/umich.box.com/shared/static/6m7f4lw9bdog241kqcmb.ipynb
TODO