Skip to content

ENH: add xgboost example - #14

Merged
mrocklin merged 12 commits into
dask:masterfrom
stsievert:xgboost
Jul 6, 2018
Merged

mrocklin merged 12 commits into
dask:masterfrom
stsievert:xgboost

Conversation

@stsievert

@stsievert stsievert commented Jun 29, 2018 •

Copy link
Copy Markdown
Member

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:

@mrocklin mrocklin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread xgboost.ipynb Outdated
"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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread xgboost.ipynb Outdated
"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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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".

Comment thread xgboost.ipynb Outdated
"\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\">"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the images. Can I also ask for a header title? Perhaps something like

Dask and XGBoost
===============

Comment thread xgboost.ipynb Outdated
"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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread xgboost.ipynb Outdated
"from dask_ml.model_selection import train_test_split\n",
"import numpy as np\n",
"\n",
"n, d = int(100e3), 20\n",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather than int(100e3) can I ask for 1e5 or 100000 (preferred)

Comment thread xgboost.ipynb Outdated
"import pandas as pd\n",
"\n",
"if isinstance(w_star, da.Array):\n",
" w_star = w_star.compute()\n",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

  1. Use a different variable name for the dask array and numpy version
  2. Use w_star = dask.compute(w_star)[0], which will work in both cases

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread xgboost.ipynb Outdated
"cell_type": "markdown",
"metadata": {},
"source": [
"The `bst` object is a regular `xboost.Booster` object, and has all the familar methods available. For example,"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Trails off with "For example,". Not sure if this was intentional or not.

Comment thread xgboost.ipynb Outdated
"outputs": [],
"source": [
"y_hat = dxgb.predict(client, bst, X_test)\n",
"y_hat = client.persist(y_hat)\n",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We might also want to call out that we can use dask_xgboost to predict in parallel in prose.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Eek, I didn't read closely enough – it's in the other example too. That should be modified too.

Comment thread xgboost.ipynb Outdated
"cell_type": "markdown",
"metadata": {},
"source": [
"Or we can plot the ROC curve after we do some predictions:"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've added an explanation for what ROC curves are.

@stsievert stsievert Jun 30, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

And a link too in "Learn more"

Comment thread xgboost.ipynb Outdated
"outputs": [],
"source": [
"import dask_xgboost as dxgb\n",
"import xgboost as xgb"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thoughts on leaving these as full names like xgboost and dask_xgboost? I'm not sure how common these pronouns are.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They're easier to type and easier to understand. I don't see a downside. I've changed them.

@stsievert

stsievert commented Jun 30, 2018 •

Copy link
Copy Markdown
Member Author

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).

@mrocklin

mrocklin commented Jul 2, 2018

Copy link
Copy Markdown
Member

I've pushed a few minor edits. This is good to go from my perspective. @TomAugspurger any final thoughts?

Comment thread binder/environment.yml Outdated
- pip:
- graphviz
- dask_xgboost
- xgboost

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ping @stsievert

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the ping @mrocklin.

@TomAugspurger

Copy link
Copy Markdown
Member

Contents look good. Just a comment on the environment setup.

@mrocklin

mrocklin commented Jul 2, 2018

Copy link
Copy Markdown
Member

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?

Moved to #16

@mrocklin

mrocklin commented Jul 5, 2018

Copy link
Copy Markdown
Member

@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?

@stsievert

Copy link
Copy Markdown
Member Author

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.

@mrocklin

mrocklin commented Jul 5, 2018 via email

Copy link
Copy Markdown
Member

@mrocklin
mrocklin merged commit 61dfb30 into dask:master Jul 6, 2018
@mrocklin

mrocklin commented Jul 6, 2018

Copy link
Copy Markdown
Member

This is in. Thanks @stsievert !

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.

3 participants