Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from orchardbirds/add_binary_f1_eval
Add binary f1 eval
- Loading branch information
Showing
13 changed files
with
221 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
"""Import required metrics.""" | ||
|
||
|
||
from .classification_eval_metrics import( | ||
from .classification_eval_metrics import ( | ||
WeightedCrossEntropyMetric, | ||
FocalMetric, | ||
F1_Score_Binary, | ||
) | ||
|
||
__all__ = [ | ||
"WeightedCrossEntropyMetric", | ||
"FocalMetric" | ||
"FocalMetric", | ||
"F1_Score_Binary" | ||
] |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Import required metrics.""" | ||
|
||
|
||
from .regression_eval_metrics import ( | ||
SquaredLogErrorMetric, | ||
RootMeanSquaredLogErrorMetric, | ||
LogCoshMetric, | ||
) | ||
|
||
__all__ = [ | ||
"SquaredLogErrorMetric", | ||
"RootMeanSquaredLogErrorMetric", | ||
"LogCoshMetric" | ||
] |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Import required losses.""" | ||
|
||
|
||
from .regression_loss_functions import ( | ||
SquaredLogErrorLoss, | ||
LogCoshLoss, | ||
) | ||
|
||
__all__ = [ | ||
"SquaredLogErrorLoss", | ||
"LogCoshLoss" | ||
] |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from sklearn.datasets import make_classification\n", | ||
"from sklearn.model_selection import train_test_split\n", | ||
"from sklearn.metrics import roc_auc_score\n", | ||
"from bokbokbok.eval_metrics.classification import F1_Score_Binary\n", | ||
"from bokbokbok.utils import clip_sigmoid\n", | ||
"\n", | ||
"X, y = make_classification(n_samples=1000, \n", | ||
" n_features=10, \n", | ||
" random_state=41114)\n", | ||
"\n", | ||
"X_train, X_valid, y_train, y_valid = train_test_split(X, \n", | ||
" y, \n", | ||
" test_size=0.25, \n", | ||
" random_state=41114)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Usage in LightGBM" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import lightgbm as lgb\n", | ||
"\n", | ||
"train = lgb.Dataset(X_train, y_train)\n", | ||
"valid = lgb.Dataset(X_valid, y_valid, reference=train)\n", | ||
"params = {\n", | ||
" 'n_estimators': 300,\n", | ||
" 'objective': 'binary',\n", | ||
" 'seed': 41114,\n", | ||
" 'n_jobs': 8,\n", | ||
" 'learning_rate': 0.1,\n", | ||
" }\n", | ||
"\n", | ||
"clf = lgb.train(params=params,\n", | ||
" train_set=train,\n", | ||
" valid_sets=[train, valid],\n", | ||
" valid_names=['train','valid'],\n", | ||
" feval=F1_Score_Binary(average='micro'),\n", | ||
" early_stopping_rounds=100)\n", | ||
"\n", | ||
"roc_auc_score(y_valid, clf.predict(X_valid))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Usage in XGBoost" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import xgboost as xgb\n", | ||
"\n", | ||
"dtrain = xgb.DMatrix(X_train, y_train)\n", | ||
"dvalid = xgb.DMatrix(X_valid, y_valid)\n", | ||
"\n", | ||
"params = {\n", | ||
" 'seed': 41114,\n", | ||
" 'objective':'binary:logistic',\n", | ||
" 'learning_rate': 0.1,\n", | ||
" 'disable_default_eval_metric': 1\n", | ||
" }\n", | ||
"\n", | ||
"bst = xgb.train(params,\n", | ||
" dtrain=dtrain,\n", | ||
" num_boost_round=300,\n", | ||
" early_stopping_rounds=10,\n", | ||
" verbose_eval=10,\n", | ||
" maximize=True,\n", | ||
" feval=F1_Score_Binary(average='micro', XGBoost=True),\n", | ||
" evals=[(dtrain, 'dtrain'), (dvalid, 'dvalid')])\n", | ||
"\n", | ||
"roc_auc_score(y_valid, clip_sigmoid(bst.predict(dvalid)))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python [conda env:skorecard_py37]", | ||
"language": "python", | ||
"name": "conda-env-skorecard_py37-py" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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