Add blockwise ensemble meta-estimators#657
Merged
TomAugspurger merged 18 commits intodask:masterfrom May 6, 2020
Merged
Conversation
Member
Author
```python
In [1]: import sklearn.linear_model
...: import dask_ml.datasets
...: import dask_ml.ensemble
...:
...: X, y = dask_ml.datasets.make_classification(n_features=20, chunks=25)
...:
...: clf = dask_ml.ensemble.BlockwiseVotingClassifier(
...: sklearn.linear_model.LogisticRegression(), voting="soft",
...: classes=[0, 1]
...: )
...:
...: clf.fit(X, y)
In [2]: clf.estimators_
Out[2]:
[LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, l1_ratio=None, max_iter=100,
multi_class='auto', n_jobs=None, penalty='l2',
random_state=None, solver='lbfgs', tol=0.0001, verbose=0,
warm_start=False),
LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, l1_ratio=None, max_iter=100,
multi_class='auto', n_jobs=None, penalty='l2',
random_state=None, solver='lbfgs', tol=0.0001, verbose=0,
warm_start=False),
LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, l1_ratio=None, max_iter=100,
multi_class='auto', n_jobs=None, penalty='l2',
random_state=None, solver='lbfgs', tol=0.0001, verbose=0,
warm_start=False),
LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, l1_ratio=None, max_iter=100,
multi_class='auto', n_jobs=None, penalty='l2',
random_state=None, solver='lbfgs', tol=0.0001, verbose=0,
warm_start=False)]
```
6e0021b to
1e2f9d1
Compare
TomAugspurger
commented
May 5, 2020
dask_ml/ensemble/_blockwise.py
Outdated
Comment on lines
+53
to
+57
| results = [ | ||
| X.map_blocks(_predict, dtype=dtype, estimator=estimator, drop_axis=1) | ||
| for estimator in self.estimators_ | ||
| ] | ||
| combined = da.vstack(results).T.rechunk({1: -1}) |
Member
Author
There was a problem hiding this comment.
This is kinda slow for many estimators (many partitions). We end up with X.npartitions * len(self.classifiers_) tasks. Looking into doing a "batch" predict where each task represents the predictions from every estimator on that partition stacked into a single ndarray.
Member
Author
There was a problem hiding this comment.
Fixed for array. For dask.dataframe.map_partitions didn't especially like returning a 3D array. Looking into it a bit, but not a blocker right now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds
BlockwiseVotingClassifierandBlockwiseVotingRegressor, which are meta-estimators forGiven an input array split into
kpartitions,kclones of the subestimator are fit independently, one per partition. This is efficient since we don't need to move any data (assuming the partitions of X and y are co-located).At prediction time we combine the predictions from each of the
kfitted models. For classification we take the class with either the most votes (voting="hard") or the highest total probability (voting="soft"). See https://scikit-learn.org/stable/modules/ensemble.html#voting-classifier. For regression we take the average.