Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stacking param tuning #254

Merged
merged 5 commits into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/sources/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The CHANGELOG for the current development version is available at

##### New Features

- Added `evaluate.permutation_test`, a permutation test for hypothesis testing (or A/B testing) to test if two samples come from the same distribution. Or in other words, a procedure to test the null hypothesis that that two groups are not significantly different (e.g., a treatment and a control group).
- Added `evaluate.permutation_test`, a permutation test for hypothesis testing (or A/B testing) to test if two samples come from the same distribution. Or in other words, a procedure to test the null hypothesis that that two groups are not significantly different (e.g., a treatment and a control group).
- Added `'leverage'` and `'conviction` as evaluation metrics to the `frequent_patterns.association_rules` function. [#246](https://github.com/rasbt/mlxtend/pull/246) & [#247](https://github.com/rasbt/mlxtend/pull/247)
- Added a `loadings_` attribute to `PrincipalComponentAnalysis` to compute the factor loadings of the features on the principal components. [#251](https://github.com/rasbt/mlxtend/pull/251)

Expand All @@ -27,6 +27,7 @@ The CHANGELOG for the current development version is available at
##### Bug Fixes

- the "S" vector from SVD in `PrincipalComponentAnalysis` are now scaled so that the eigenvalues via `solver='eigen'` and `solver='svd'` now store eigenvalues that have the same magnitudes. [#251](https://github.com/rasbt/mlxtend/pull/251)
- The parameters for `StackingClassifier`, `StackingCVClassifier`, `StackingRegressor`, `StackingCVRegressor`, and `EnsembleVoteClassifier` can now be tuned using scikit-learn's `GridSearchCV` ([#254](https://github.com/rasbt/mlxtend/pull/254) via [James Bourbeau](https://github.com/jrbourbeau))

### Version 0.8.0 (2017-09-09)

Expand Down
7 changes: 7 additions & 0 deletions mlxtend/classifier/ensemble_vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ def get_params(self, deep=True):
for name, step in six.iteritems(self.named_clfs):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value

for key, value in six.iteritems(super(EnsembleVoteClassifier,
self).get_params(deep=False)):
if key == 'clfs':
continue
else:
out['%s' % key] = value
return out

def _predict(self, X):
Expand Down
9 changes: 9 additions & 0 deletions mlxtend/classifier/stacking_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def fit(self, X, y):

def get_params(self, deep=True):
"""Return estimator parameter names for GridSearch support."""

if not deep:
return super(StackingClassifier, self).get_params(deep=False)
else:
Expand All @@ -137,6 +138,14 @@ def get_params(self, deep=True):
for name, step in six.iteritems(self.named_meta_classifier):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value

for key, value in six.iteritems(super(StackingClassifier,
self).get_params(deep=False)):
if key in ('classifiers', 'meta-classifier'):
continue
else:
out['%s' % key] = value

return out

def _predict_meta_features(self, X):
Expand Down
8 changes: 8 additions & 0 deletions mlxtend/classifier/stacking_cv_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ def get_params(self, deep=True):
for name, step in six.iteritems(self.named_meta_classifier):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value

for key, value in six.iteritems(super(StackingCVClassifier,
self).get_params(deep=False)):
if key in ('classifiers', 'meta-classifier'):
continue
else:
out['%s' % key] = value

return out

def predict(self, X):
Expand Down
5 changes: 3 additions & 2 deletions mlxtend/classifier/tests/test_ensemble_vote_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ def test_EnsembleVoteClassifier_gridsearch_enumerate_names():

clf1 = LogisticRegression(random_state=1)
clf2 = RandomForestClassifier(random_state=1)
eclf = EnsembleVoteClassifier(clfs=[clf1, clf1, clf2], voting='soft')
eclf = EnsembleVoteClassifier(clfs=[clf1, clf1, clf2])

params = {'logisticregression-1__C': [1.0, 100.0],
'logisticregression-2__C': [1.0, 100.0],
'randomforestclassifier__n_estimators': [5, 20]}
'randomforestclassifier__n_estimators': [5, 20],
'voting': ['hard', 'soft']}

grid = GridSearchCV(estimator=eclf, param_grid=params, cv=5)
grid = grid.fit(iris.data, iris.target)
3 changes: 2 additions & 1 deletion mlxtend/classifier/tests/test_stacking_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def test_gridsearch_enumerate_names():

params = {'meta-logisticregression__C': [1.0, 100.0],
'randomforestclassifier-1__n_estimators': [5, 10],
'randomforestclassifier-2__n_estimators': [5, 20]}
'randomforestclassifier-2__n_estimators': [5, 20],
'use_probas': [True, False]}

grid = GridSearchCV(estimator=sclf, param_grid=params, cv=5)
grid = grid.fit(iris.data, iris.target)
Expand Down
3 changes: 2 additions & 1 deletion mlxtend/classifier/tests/test_stacking_cv_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def test_gridsearch_enumerate_names():

params = {'meta-logisticregression__C': [1.0, 100.0],
'randomforestclassifier-1__n_estimators': [5, 10],
'randomforestclassifier-2__n_estimators': [5, 20]}
'randomforestclassifier-2__n_estimators': [5, 20],
'use_probas': [True, False]}

grid = GridSearchCV(estimator=sclf, param_grid=params, cv=5)
grid = grid.fit(iris.data, iris.target)
Expand Down
8 changes: 8 additions & 0 deletions mlxtend/regressor/stacking_cv_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,12 @@ def get_params(self, deep=True):
for name, step in six.iteritems(self.named_meta_regressor):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value

for key, value in six.iteritems(super(StackingCVRegressor,
self).get_params(deep=False)):
if key in ('regressors', 'meta-regressor'):
continue
else:
out['%s' % key] = value

return out
8 changes: 8 additions & 0 deletions mlxtend/regressor/stacking_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ def get_params(self, deep=True):
for name, step in six.iteritems(self.named_meta_regressor):
for key, value in six.iteritems(step.get_params(deep=True)):
out['%s__%s' % (name, key)] = value

for key, value in six.iteritems(super(StackingRegressor,
self).get_params(deep=False)):
if key in ('regressors', 'meta-regressor'):
continue
else:
out['%s' % key] = value

return out

def _predict_meta_features(self, X):
Expand Down
3 changes: 2 additions & 1 deletion mlxtend/regressor/tests/test_cv_stacking_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def test_gridsearch_numerate_regr():
params = {'ridge-1__alpha': [0.01, 1.0],
'ridge-2__alpha': [0.01, 1.0],
'svr__C': [0.01, 1.0],
'meta-svr__C': [0.01, 1.0]}
'meta-svr__C': [0.01, 1.0],
'use_features_in_secondary': [True, False]}

grid = GridSearchCV(estimator=stack,
param_grid=params,
Expand Down