Repository navigation
ENH: add an example with dask-ml's Incremental - #15
Conversation
|
I've made some edits, viewable on the same gist: https://gist.github.com/stsievert/fbd2da97924e827bdb2f015aff7fe9b1 This is ready for review now. |
TomAugspurger
left a comment
There was a problem hiding this comment.
Looks great, thanks!
Could you create a distriubted Client, and encourage people to look at the UI while this is running?
Could you add a concluding thoughts section, reiterating
- We used Dask to manage the data. You write normal NumPy-like code, and don't have to mess with writing a for loop to page chunks of data in
- The training is sequential, and done entirely be scikit-learn.
- The sequential training isn't a huge hindrance, as we can do parallelism at a higher level (GridSearchCV).
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Scikit-learn is a popular machine learning library, and implements the minimal API required for training machine learning models. Their library encompasses a wide variety of problem formulations, ranging from simple linear models to more complex clustering or decomposition formulations. Scikit-learn is hindered by computation (what machine library isn't?). This has even gotten a page in their user guide, \"[Strategies to scale computationally: bigger data][strat]\".\n", |
There was a problem hiding this comment.
minimal API required
could be interpreted positively or negatively :)
Perhaps something like "whose API has inspired many other libraries"?
There was a problem hiding this comment.
"Their library" -> "It"
It's OSS, it's everyone's library :)
There was a problem hiding this comment.
Scikit-learn is hindered by computation
I like to phrase this as "Scikit-learn works great for problems that fit on a single machine, but struggles for larger problem"
| "\n", | ||
| "Using scikit-learn estimators with Dask-ML helps scale to large datasets. All the computation remains on scikit-learn's shoulders but the data management is handled by Dask. This allows scaling to large datasets distributed across many machines, or to datasets that do not fit in memory.\n", | ||
| "\n", | ||
| "This example wraps a scikit-learn estimator with a Dask-ML estimator suited for incremental learning. This Dask-ML estimator manages feeding data to Scikit-learn, and leaves the computation to Scikit-learn. This example will not cover the other algorithms inside of Dask-ML that are well-suited for Dask's distributed architecture.\n", |
There was a problem hiding this comment.
Link incremental learning -> http://scikit-learn.org/stable/modules/scaling_strategies.html#incremental-learning
edit: ah, I see you have that later. Still, doesn't hurt.
There was a problem hiding this comment.
Also introduce Incremental, with a linkn to http://dask-ml.readthedocs.io/en/latest/modules/generated/dask_ml.wrappers.Incremental.html#dask_ml.wrappers.Incremental, before saying "This Dask-ML estimator..."
There was a problem hiding this comment.
This Dask-ML estimator manages feeding data to Scikit-learn, and leaves the computation to Scikit-learn.
redudentant with the previous paragraph.
| "\n", | ||
| "This example will show\n", | ||
| "\n", | ||
| "* wrapping a scikit-learn estimator that implement `partial_fit` with `dask_ml`\n", |
There was a problem hiding this comment.
implement -> implements.
You could maybe strike scikit-learn. It's work on any estimator that implements partial_fit (and the rest of the estimator API)
| "metadata": {}, | ||
| "source": [ | ||
| "## Data creation\n", | ||
| "We will create many synthetic data. We are more interested in showing the plumbing this data can flow through than cool insights we can glean from the data.\n", |
There was a problem hiding this comment.
"showing the plumbing this" -> "showing how this data flows through the estimator"?
| "import numpy as np\n", | ||
| "n, d = int(100e3), 100\n", | ||
| "\n", | ||
| "X = da.random.normal(size=(n, d), chunks=n // 10)\n", |
There was a problem hiding this comment.
dask/dask-ml#255 would cover this right?
dsak_ml.datasets.make_classification has some knobs over n_informative, etc. I'm not sure if all of them are implemented.
I agree that for these examples, the actual data are irrelevant, so ideally this would be as simple as possible.
There was a problem hiding this comment.
dask/dask-ml#255 would cover this right?
It would help. I use make_classification now – I think I was creation of my own matrices for ground truth, but I don't actually use it later.
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "y_hat = inc.predict(X_test)\n", |
There was a problem hiding this comment.
I think scikit-learn uses y_pred, so people may be more familiar with that (though I'm partial to y_hat, in this case it's best to go where the people are).
| "outputs": [], | ||
| "source": [ | ||
| "y_hat = inc.predict(X_test)\n", | ||
| "errors = np.abs(y_hat - y_test) / 2 # divide by 2 to get 0-1 labels\n", |
There was a problem hiding this comment.
dask_ml.metrics.accuracy_score
There was a problem hiding this comment.
I was using raw dask arrays to provide some basics on how to use them. I've tried to clarify that, and re-ordered too.
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "This accuracy might be the best possible, but there a lot of parameters to feed `SGDClassifier` that can drastically change the performance. We'll consider two of the most basic parameters, specifying a different loss function and different amount of penalty. This is the problem of hyperparameter optimization, something Dask-ML supports: https://dask-ml.readthedocs.io/en/latest/hyper-parameter-search.html\n", |
There was a problem hiding this comment.
Is the first phrase missing a "not"? Somethying like
"This accuracy might not be the best possible; there are a lot of parameters..."
| "outputs": [], | ||
| "source": [ | ||
| "from dask_ml.model_selection import GridSearchCV\n", | ||
| "params = {'alpha': np.logspace(-6, 0, num=10),\n", |
There was a problem hiding this comment.
I would write this like:
# small parameter grid for the example
params = {
'alpha': [0.1, 10],
'loss': ['hingle', 'log'],
}
# An example of a larger parameter grid.
# params = {
# 'alpha': np.logspace(-6, 0, num=10),
# 'loss': ['hinge', 'log', 'modified_huber', 'squared_hinge', 'perceptron']
# }| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import seaborn as sns\n", |
There was a problem hiding this comment.
I greatly prefer this instead of the heatmap.
|
Hmm I had a review pending, but apparently lost it. Overall, the content here is solid. We may want to wait on the resolution to dask/dask-ml#258, as that'll be an API breaking change. |
|
Could I have another review on this PR? I'm satisfied with the prose and the performance (which has spawned a couple other issues and PRs) |
|
I've pushed the notebook with outputs. I can strip them before removal depending on #16. |
|
Some comments, mostly language related. My apologies for not going in-line:
As an example, here is what I recommend for how to handle persist and da.unique. I recommend the following cells directly after creating the training data. I've found that this level of prose/code is easily digestible by peole with short attention spans (most readers). Separating things out by section headers with brief informative names helps them to understand the scope of the step of the computation that they are about to learn about. |
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Scikit-learn is a popular machine learning library whose API is easy to use because it has been inspired by other machine learning libraries. It encompasses a wide variety of problem formulations, ranging from simple linear models to more complex clustering or decomposition formulations. Scikit-learn works great for problems that fit on a single machine, but struggles for larger problems. This has even gotten a page in their user guide, \"[Strategies to scale computationally: bigger data][strat]\".\n", |
There was a problem hiding this comment.
I'm not sure about the origins of scikit-learn's design, but I often see it cited as the inspiration for other APIs (e.g. https://spark.apache.org/docs/latest/ml-pipeline.html#main-concepts-in-pipelines)
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Creating a distributed scheduler will provide good feedback because we can view the dask.distributed dashboard. This will provide progress and performance metrics, including visualization of jobs that are running." |
There was a problem hiding this comment.
I think this is redundant with the previous.
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Now, let's call `partial_fit` multiple times.\n", |
There was a problem hiding this comment.
I would remove this block, since implementing max_iter for Incremental will I think make it obsolete?
There was a problem hiding this comment.
I want to leave this block we're show casing Incremental, which will very likely be used for other tools to get some idea or progress/etc. I would imagine that the data dictionary I use will be used, and probably with more data.
I have restructered a bit, to move the persisting data section below the "calling partial_fit" header.
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "There a lot of parameters to feed `SGDClassifier`, and this accuracy depends on those parameters, and it may not be as high as it can be. We'll consider two of the most basic parameters, specifying a different loss function and different amount of penalty. This is the problem of hyperparameter optimization, something Dask-ML supports: https://dask-ml.readthedocs.io/en/latest/hyper-parameter-search.html\n", |
|
I have addressed both @mrocklin and @TomAugspurger's comments, and made some more edits. I've pushed the notebook with the outputs again.
Good idea. I've removed the model selection section. I have briefly mentioned this alongside the Dask joblib integration in a "Learn more" section. |
|
FYI I’m traveling today and will likely be busy on pandas things the next few days, so don’t let me hold any of these up.
…________________________________
From: Scott Sievert <[email protected]>
Sent: Wednesday, July 4, 2018 10:12:25 PM
To: dask/dask-examples
Cc: Tom Augspurger; Mention
Subject: Re: [dask/dask-examples] ENH: add an example with dask-ml's Incremental (#15)
I have addressed both @mrocklin<https://github.com/mrocklin> and @TomAugspurger<https://github.com/TomAugspurger>'s comments. I've pushed the notebook with the outputs again.
I also recommend removing the GridSearch section for the same reason. Lets get them in and out quickly.
Good idea. I've removed the model selection section. I have briefly mentioned this alongside the Dask joblib integration in a "Learn more" section.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#15 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABQHItrOMEkjqJIP-9JWVitHCwL9Yasdks5uDYQZgaJpZM4U9vR5>.
|
|
I'm taking a look through this now. I may make a few edits directly if that's ok. |
Thank you, it's appreciated. That's more than okay. |
1. Change title to focus on incremental, rather than all of
scikit-learn
2. Remove a lot of general content in the header
3. Persist data early on, briefly explain why
4. Increase the dataset size by an order of magnitude to make the
examples somewhat heavier. This targets the 1-2GB dataset size for
the Binder environment
5. Replace final learn more section with links from the notebook
This isn't only about joblib, and moving notebook links will cause existing links in the wild to break.
|
@stsievert I've changed things to make them in line with my preferences. Can you look things over and make sure that they're still consistent with your intent? |
stsievert
left a comment
There was a problem hiding this comment.
This looks pretty good, but the introduction could use some work. The biggest edits I made were adding some motivation for calling dask.persist.
| " df = pandas.read_csv(filename)\n", | ||
| " x, y = ... # get data from CSV using the Pandas API\n", | ||
| " est.partial_fit(x, y)\n", | ||
| "```\n", |
There was a problem hiding this comment.
Do you have any examples for "this is a common operation"? The first thing I would do is shuffle the dataset before calling the optimizer on each block.
There was a problem hiding this comment.
Are you referring to this sentence:
A common approach to training large datasets is to incrementally train a model on many batches of data sequentially.
This was my understanding, but I could definitely be incorrect.
The first thing I would do is shuffle the dataset before calling the optimizer on each block.
My intent here in the first section is just to give the reader a quick idea of what's going on, not to go into detail on anything. Hence the liberal use of ...
However, it may be that I'm showing people anti-patterns. If so perhaps we can remove these pseudo-examples entirely and just refer people to scikit-learn docs. This intro seems a bit long regardless, there isn't any activity for the user above the fold.
There was a problem hiding this comment.
The biggest edits I made were adding some motivation for calling dask.persist.
Sounds fine to me. As a general note, there are always going to be lots of things that we'll do in any of these examples that are important that we won't be able to tell them about. We'll necessarily skip a lot of potential wisdom we could deliver in order to focus on the topic at hand.
In this case though I agree that including some information about persist is good, especially because it's nice and concise.
There was a problem hiding this comment.
I've pushed another example that removes the examples and tries to trim down the intro.
|
This is in. Thanks @stsievert ! |

I'd appreciate a review of this. I tried to point out the features and limitations of
Incremental, and walked through a basic training + testing example. I included a note about dask/dask-ml#247, and how Incremental is responsible for data management and sklearn is responsible for the computation on the data.A rendered notebook is available at https://gist.github.com/stsievert/fbd2da97924e827bdb2f015aff7fe9b1
cc @TomAugspurger @mrocklin