Skip to content

Commit

Permalink
kevin-ensemble_compare_f1.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kegao1995 committed Jan 10, 2025
1 parent 5a4618c commit 98d4123
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ as follows:
```python
from ensemble_best_method.confusion_matrices import confusion_matrices
from ensemble_best_method.compare_f1 import compare_f1
from ensemble_best_method.ensumble_compare_f1 import ensemble_compare_f1
from ensemble_best_method.ensemble_compare_f1 import ensemble_compare_f1

from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import LinearSVC
Expand Down Expand Up @@ -58,4 +58,4 @@ Interested in contributing? Check out the contributing guidelines. Please note t

## Credits

`ensemble_best_method` was created with [`cookiecutter`](https://cookiecutter.readthedocs.io/en/latest/) and the `py-pkgs-cookiecutter` [template](https://github.com/py-pkgs/py-pkgs-cookiecutter).
`ensemble_best_method` was created with [`cookiecutter`](https://cookiecutter.readthedocs.io/en/latest/) and the `py-pkgs-cookiecutter` [template](https://github.com/py-pkgs/py-pkgs-cookiecutter).
21 changes: 21 additions & 0 deletions src/ensemble_best_method/ensemble_compare_f1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def ensemble_compare_f1(estimators, X_train, y_train, method='stacking'):
"""
Show cross validation fit time and f1 scores of a classifier by stacking or voting the estimators.
Parameters:
estimators (list): List of (str, estimator) tuples.
X_train (array-like): Feature matrix for training.
y_train (array-like): Target vector for training.
method (str): Ensemble method, 'stacking' or 'voting'. Default is 'stacking'.
Returns:
dict: Dictionary containing fit times and f1 scores.
"""
# ...existing code...

# Example usage:
# estimators = [('lr', LogisticRegression()), ('rf', RandomForestClassifier())]
# X_train = ... # feature matrix for training
# y_train = ... # target vector for training
# result = ensemble_compare_f1(estimators, X_train, y_train, method='stacking')
# print(result)

0 comments on commit 98d4123

Please sign in to comment.