Repository navigation
ENH: add xgboost example - #14
Conversation
mrocklin
left a comment
There was a problem hiding this comment.
This is great! Thank you so much for doing this. I'm excited to see this be produced so quickly.
I gave a ton of nit-picky feedback. Please take this as a sign on how invested I am in pushing forward on this :)
I also recommend generally going through the other notebooks in this repository to get a sense for the common patterns that may exist, particularly around setting up the client and section headers.
Meta note: I was also happy to see that a small issue came out of doing this work (I suggest that we try to remove the client keyword from dask_xgboost.train/predict) My hope is that working on examples like this helps to highlight usability corners that need to be smoothed over, which leads to more development work.
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "This example is similar to the example at https://dask-ml.readthedocs.io/en/latest/examples/xgboost.html, but this example takes a while to run because it uses a real dataset. There is a recorded screencast that walks through this example at https://www.youtube.com/watch?v=Cc4E-PdDSro, with comments from the lead Dask developer, Matthew Rocklin.\n", |
There was a problem hiding this comment.
I recommend that we start strong with the topic at hand, rather than discuss the other examples that are out there. Maybe something like "Dask and XGBoost can work together to train data with gradient boosted trees. This notebook shows how"
The context of other examples that may exist may not interest new users. It's usually an accurate guess that for anyone looking at an example it is their first time seeing the topic. If we do want to provide a link to the other example, lets do it at the bottom in a "Learn more" section
There was a problem hiding this comment.
I've expanded, and have included a paragraph about what XGBoost is and why it's useful, and it provides good motivation for the rest of the notebook. I left same thing for Dask out because if they're looking at this example they already want to learn about Dask. Let me know if you'd like me to change that.
| "source": [ | ||
| "This example is similar to the example at https://dask-ml.readthedocs.io/en/latest/examples/xgboost.html, but this example takes a while to run because it uses a real dataset. There is a recorded screencast that walks through this example at https://www.youtube.com/watch?v=Cc4E-PdDSro, with comments from the lead Dask developer, Matthew Rocklin.\n", | ||
| "\n", | ||
| "This example is similar but uses synthetic data instead, to allow it to be easily runnable. This example uses a Dask wrapper around XGBoost.\n", |
There was a problem hiding this comment.
Lets also not mention me, or any other developer by name. If we want to include a screencast of this notebook we should just say "Here is a screencast of this notebook".
| "\n", | ||
| "This example is similar but uses synthetic data instead, to allow it to be easily runnable. This example uses a Dask wrapper around XGBoost.\n", | ||
| "\n", | ||
| "<img src=\"http://dask.readthedocs.io/en/latest/_images/dask_horizontal.svg\" width=\"30%\" alt=\"Dask logo\"> <img src=\"https://raw.githubusercontent.com/dmlc/dmlc.github.io/master/img/logo-m/xgboost.png\" width=\"25%\" alt=\"Dask logo\">" |
There was a problem hiding this comment.
Thanks for the images. Can I also ask for a header title? Perhaps something like
Dask and XGBoost
===============| "from dask import compute, persist\n", | ||
| "from dask.distributed import Client, progress\n", | ||
| "\n", | ||
| "client = Client(os.environ.get(\"DISTRIBUTED_ADDRESS\")) # connect to cluster \n", |
There was a problem hiding this comment.
You'll want to create a client here normally. I recommend looking at the other example notebooks in this repository to see how.
I'm curious, where did you find this line of code? Were you working from an existing example somewhere? (if so, I need to scrub that example)
There was a problem hiding this comment.
I was wondering about it but it worked so I kept going. I copied and pasted from https://dask-ml.readthedocs.io/en/latest/examples/xgboost.html.
| "from dask_ml.model_selection import train_test_split\n", | ||
| "import numpy as np\n", | ||
| "\n", | ||
| "n, d = int(100e3), 20\n", |
There was a problem hiding this comment.
Rather than int(100e3) can I ask for 1e5 or 100000 (preferred)
| "import pandas as pd\n", | ||
| "\n", | ||
| "if isinstance(w_star, da.Array):\n", | ||
| " w_star = w_star.compute()\n", |
There was a problem hiding this comment.
We know that it is a dask array here, right? My guess is that you want to make this cell so that you can run it many times. If so I might suggest one of two approaches:
- Use a different variable name for the dask array and numpy version
- Use
w_star = dask.compute(w_star)[0], which will work in both cases
There was a problem hiding this comment.
My guess is that you want to make this cell so that you can run it many times.
Exactly. I was iterating on this cell.
There was a problem hiding this comment.
There's another notebook in this repo called for dask arrays. I'll let this slide (it's only to show an example) and leave the other explanation for the other notebook.
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "The `bst` object is a regular `xboost.Booster` object, and has all the familar methods available. For example," |
There was a problem hiding this comment.
Trails off with "For example,". Not sure if this was intentional or not.
| "outputs": [], | ||
| "source": [ | ||
| "y_hat = dxgb.predict(client, bst, X_test)\n", | ||
| "y_hat = client.persist(y_hat)\n", |
There was a problem hiding this comment.
I recommend that we avoid the client.persist method in all cases, instead preferring the .persist method of the series object, or the dask.persist function. In this case I would do the following:
y_hat = dxgb.predict(client, bst, X_test).persist()There was a problem hiding this comment.
We might also want to call out that we can use dask_xgboost to predict in parallel in prose.
There was a problem hiding this comment.
Eek, I didn't read closely enough – it's in the other example too. That should be modified too.
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Or we can plot the ROC curve after we do some predictions:" |
There was a problem hiding this comment.
As someone who is a novice in machine learning I have to admit that I don't have a strong understanding of ROC curves. It might be good to spell out the acronym once in the style of Three Letter Acronym (TLA) and then state that "we see that results are good because the curve tends towards the upper left", just to give the novice reader the ability to appreciate how well things worked out.
There was a problem hiding this comment.
I've added an explanation for what ROC curves are.
There was a problem hiding this comment.
And a link too in "Learn more"
| "outputs": [], | ||
| "source": [ | ||
| "import dask_xgboost as dxgb\n", | ||
| "import xgboost as xgb" |
There was a problem hiding this comment.
Thoughts on leaving these as full names like xgboost and dask_xgboost? I'm not sure how common these pronouns are.
There was a problem hiding this comment.
They're easier to type and easier to understand. I don't see a downside. I've changed them.
|
I see most of the other notebooks in this repo are without their outputs in the notebook. Letting the outbooks be coded in the notebook would lower the barrier to viewing to viewing these notebooks by allowing users to try binder if they want. Why don't we include the outputs in the notebooks? I've updated the notebook, and it's rendered at https://gist.github.com/stsievert/b797b4e4d510a4e417a8db33eb6601c6 (though it's pushed without the output). |
|
I've pushed a few minor edits. This is good to go from my perspective. @TomAugspurger any final thoughts? |
| - pip: | ||
| - graphviz | ||
| - dask_xgboost | ||
| - xgboost |
There was a problem hiding this comment.
This may fail / not be pleasant for users.. https://pypi.org/project/xgboost/#files only provides an sdist, so we would have to compile the extension modules every time our image isn't in binder's cache.
I think you can install it with py-xgboost from the defaults channel.
|
Contents look good. Just a comment on the environment setup. |
Moved to #16 |
|
@stsievert I made a few edits to this notebook similar to what we just went over. Would you might looking things over and seeing if you're ok with them? |
|
I've simplified this a lot, by both by reducing unnecessary prose and simplifying the code. I've pushed with the noteboko with outputs, but can remove them before merge. |
|
Seems good to me!
…On Thu, Jul 5, 2018 at 6:43 PM, Scott Sievert ***@***.***> wrote:
I've simplified this a lot, by both by reducing unnecessary prose and
simplifying the code.
I've pushed with the noteboko with outputs, but can remove them before
merge.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AASszNsI4hbiWD7QfSonWjLcr6w1Mxrqks5uDpaSgaJpZM4U9n-6>
.
|
|
This is in. Thanks @stsievert ! |
Implement an xgboost example.
Mirror the example at https://dask-ml.readthedocs.io/en/latest/examples/xgboost.html. That example downloads data and does some preprocessing, which takes a non-trivial amount of time (at least a minute or two). Plus, the ROC curve doesn't look to good.
This example creates synthetic data, which is created fast (though, it does point to other example and the video @mrocklin recorded). This example is visible at https://gist.github.com/stsievert/b797b4e4d510a4e417a8db33eb6601c6
Creation of synthetic data allows to show the comparison with the ground truth: turns out XGBoost does a good job at identifying which features are important:
Plus the ROC curve looks better: