Repository navigation
Conversation
|
The builds where already not passing on master. But here |
|
This pull request introduces 1 alert - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
There are some problems in master, but this PR uses features that are not available in py 2.7 |
|
Just saw that, I am fixing looking to fix it now. What is your opinion otherwise? |
|
I am more concern about the difference between fboxplot and this one. On the figures, we can see that both methods find the same outliers (same legend) but actually the displayed curves are not the same. There might be an index error. |
|
I think there are no more issues. So before I get the tests here, we should decide
Tell me if I can do something else, this is my first PR to an open source project. |
josef-pkt
left a comment
There was a problem hiding this comment.
I added some comments based on a first read-through, where I don't understand the details yet.
numpy just had the discussion about adding quantiles as alternative to percentiles. In the code and docstring it will be less confusing to avoid the work "percentile" if we mean fractions and quantiles. using interval (0, 1) instead of (0, 100)
| __all__ = ['hdrboxplot', 'fboxplot', 'rainbowplot', 'banddepth'] | ||
|
|
||
|
|
||
| def kernel_smoothing_(data, optimize=False): |
There was a problem hiding this comment.
those helper function need leading underscore in name to make them private, no trailing underscore
There was a problem hiding this comment.
Oh misread your previous comment, my bad!
| 3. Plot the bivariate plot, | ||
| 4. Compute mediane curve along with percentiles and outliers curves. | ||
|
|
||
| Behind the scene, the dataset is represented as a matrix. Each line |
There was a problem hiding this comment.
long explanation should go in the notes section. This should have just be a short explanation , so we get faster to Parameter section which we/users need to look at more often
| components, this is called a bivariate plot. | ||
|
|
||
| This visualization exhibit a cluster of points. It indicate that a lot of | ||
| curve lead to common components. The center of the cluster is the mediane |
There was a problem hiding this comment.
It indicate that a lot of curve lead to common components.
It's not clear what this sentence means.
| ---------- | ||
| data : sequence of ndarrays or 2-D ndarray | ||
| The vectors of functions to create a functional boxplot from. If a | ||
| sequence of 1-D arrays, these should all be the same size. |
There was a problem hiding this comment.
It's not (yet) clear to me whether a sequence of 1-D arrays works.
asarray(data) would concatenate rows, and not column_stack
There was a problem hiding this comment.
Indeed, this is not clear to me as well. I took this from fboxplot.
| return projection | ||
|
|
||
|
|
||
| def hdrboxplot(data, ncomp=2, alpha=[], threshold=0.95, optimize=False, |
There was a problem hiding this comment.
don't use mutable like [] as default, just to avoid any kind of related problems.
None as default?
| Number of components to use. If None, returns the as many as the | ||
| smaller of the number of rows or columns in data. | ||
| alpha : list, optional | ||
| Extra percentile values to compute. |
There was a problem hiding this comment.
use quantile instead of percentile, to emphasize that we want a fractional number between 0 and 1.
same for threshold
"fraction" also works
There was a problem hiding this comment.
Got it, I have been mislead with quartile and forgot the word quantile.
|
|
||
| - 'median', array. Median curve. | ||
| - 'mean_percentile', array. 50% percentile band. [sup, inf] curves | ||
| - 'extreme_percentile', list of array. 90% percentile band. [sup, inf] |
There was a problem hiding this comment.
I'm not sure about those names
There was a problem hiding this comment.
Is it extreme that is bothering you?
There was a problem hiding this comment.
not necessarily.
mean: We use it usually as average or expected value, so mean percentile sounds strange, is it and average or a percentile
and then related to the other comments quantile versus percentile
Can those be interpreted as confidence intervals/bands?
maybe directly referring to the coverage or alpha level would be better
0.5-band or 50% percentiles
I don't have a clear suggestion
There was a problem hiding this comment.
I changed all percentile to quantile.
Regarding the bands yes it can be seen as a level of confidence. It is like a box plot with its 1.5 Inter Quartiles Ranges. I checked the original paper, they use: 50% HDR. So I suggest:
hdr_50 or hdr_05 and for the label 50% HDR.
| label = str(labels[ii]) if labels is not None else None | ||
| ax.plot(xdata, outlier, | ||
| ls='--', alpha=0.7, label=label) | ||
| except ValueError: |
There was a problem hiding this comment.
what raises the ValueError?
An explicit check would make the code more informative and more robust.
e.g. if len(outliers) != 0
There was a problem hiding this comment.
It is caused by the ax.plot that is not able to process an empty array. I agree with you, I can use a condition here.
|
I think the function is fine for the I don't understand enough yet for the other issues. (And I'm not sure I will be able to get to it today.) What are the tradeoffs and what are your recommendations or preferences given that it's your code and you have some experience in using it? |
|
In my opinion, the only benefit for using a class for this would be to get the extra plots. So the plot of the reduced space and the contour plot if As for the optimization part. I did not included at first because I know that some are not fine with adding some optimization stuff as no one agree on which method to use (gradient free or not, etc.). But without this you will not be able to do Finally, for the plot options, I think that if the user wants more control, it might be better using the |
|
I am modifying the code to add optimization. Is it okay if I use some |
|
Got it working. It adds two functions outside |
1 similar comment
|
@josef-pkt seems okay to me, let me know If I need to do something else :) |
|
another iteration reading through it without understanding all the details:
Overall, it looks good in my opinion, but I don't have any experience with differential evolution. (Maybe: attribute versus dictionary access to results. Maybe instead of returning a dict for hdr_res we should return an instance of a simple class that just holds attributes. We do this in some of the hypothesis tests but I don't think we have a clean consistent pattern across types of functions yet. I got reminded of this because differential evolution results have a |
|
Thanks for the feedbacks.
Will do all that for the next run. |
No, what I meant was replacing the dict of hdr_res with a instance of a class that just defines attributes |
|
There seems to be an issue with python <3.5 regarding pop on OrderedDict. I am looking at it. |
|
From my tests, it seems that there was an issue in Matplotlib 1.4 with Actually, you are already using a hack in |
|
@josef-pkt Sounds good to me. Anything to add? |
|
@josef-pkt Did you get some time to check this? :) |
|
No, I had forgotten, or didn't realize that you were finished. (I would have remembered or gotten reminded when I work again on my todo list for 0.9.) |
|
@josef-pkt OK no problem. Let me know if I can be of any help anywhere else :) |
|
Sorry for the delay, but with long weekend with 3 kids at home and issue triaging, I didn't get around it yet. |
|
@josef-pkt No problem I fully understand :) |
|
|
||
| # Plots | ||
| ax.plot(np.array([xdata] * n_samples).T, data.T, | ||
| c='c', alpha=.1, label='dataset') |
There was a problem hiding this comment.
Do we ever want to have these labels?
When I reformat the legend to 2-columns ax.legend(ncol=2) (as I had done in my previous review), then I get a very large number of "dataset" in the legend, maybe one for each year.
There was a problem hiding this comment.
Indeed, these can be described in the figure's caption. Will remove it.
| data = np.asarray(data) | ||
| if xdata is None: | ||
| xdata = np.arange(data.shape[1]) | ||
|
|
There was a problem hiding this comment.
suggestion for use with pandas, before converting to array on line 309, store the index as labels, e.g.
if isinstance(xdata, pd.DataFrame) and labels is None:
labels = xdata.index
(maybe needs labels = np.asarray(xdata.index) )
alternative would be
if hasattr(xdata, 'index') and labels is None:
There was a problem hiding this comment.
Done using your snippet bellow
|
If labels is None, then I get a legend with a very large number of Except for labels everything looks good, |
|
one possibility: for example simple int labels seem to work |
|
I'm finished with this review, and will be away from a computer for the next few hours. The main suggestions are remove "dataset" labels Then the rest should behave by default as expected |
|
|
||
| by_label = OrderedDict(zip(labels, handles)) | ||
| if len(outliers) != 0: | ||
| by_label.pop('dataset') |
There was a problem hiding this comment.
This is now either redundant or will raise
I guess
There was a problem hiding this comment.
oh I missed this one!
|
looks good now I tried out the latest checkout. A simple call with a dataframe df produces a nice default I guess there are cosmetic/option improvements that can be made to the functional plots, but it is now similar in style to fboxplot. However, hdr identifies and shows fewer outlier years. |
|
I cancelled and restarted one of the travis jobs that never even started to build. Everything else is green. I think it's ready to merge. This follows now a similar or the same pattern as other plot functions. But some of this or related to this would fit also in |
|
@josef-pkt I am not sure about rebasing + squashing have never done that so maybe you should do it so I can see what you have done for next time :) |
|
rebased version merged in #4049 |
This is related to issue #3864.
It implements the Highest Density Region (HDR) technique from Hyndman[2010].