Unverified Commit 18352475 authored by Green-16's avatar Green-16 Committed by GitHub
Browse files

Use ROC-AUC metric for classification model in examples (#5440)

* [Python-package] FIX fix the metrics of classify module

* [Python-package] FIX fix the metrics of classify module

* [Python-package] FIX fix the metrics of classify module

* [Python-package] FIX fix the metrics of classify module

* [Python-package] FIX fix the metrics of classify module
parent 5fceb4a1
...@@ -6,7 +6,7 @@ from pathlib import Path ...@@ -6,7 +6,7 @@ from pathlib import Path
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from sklearn.metrics import mean_squared_error from sklearn.metrics import roc_auc_score
import lightgbm as lgb import lightgbm as lgb
...@@ -84,8 +84,8 @@ bst = lgb.Booster(model_file='model.txt') ...@@ -84,8 +84,8 @@ bst = lgb.Booster(model_file='model.txt')
# can only predict with the best iteration (or the saving iteration) # can only predict with the best iteration (or the saving iteration)
y_pred = bst.predict(X_test) y_pred = bst.predict(X_test)
# eval with loaded model # eval with loaded model
rmse_loaded_model = mean_squared_error(y_test, y_pred) ** 0.5 auc_loaded_model = roc_auc_score(y_test, y_pred)
print(f"The RMSE of loaded model's prediction is: {rmse_loaded_model}") print(f"The ROC AUC of loaded model's prediction is: {auc_loaded_model}")
print('Dumping and loading model with pickle...') print('Dumping and loading model with pickle...')
# dump model with pickle # dump model with pickle
...@@ -97,8 +97,8 @@ with open('model.pkl', 'rb') as fin: ...@@ -97,8 +97,8 @@ with open('model.pkl', 'rb') as fin:
# can predict with any iteration when loaded in pickle way # can predict with any iteration when loaded in pickle way
y_pred = pkl_bst.predict(X_test, num_iteration=7) y_pred = pkl_bst.predict(X_test, num_iteration=7)
# eval with loaded model # eval with loaded model
rmse_pickled_model = mean_squared_error(y_test, y_pred) ** 0.5 auc_pickled_model = roc_auc_score(y_test, y_pred)
print(f"The RMSE of pickled model's prediction is: {rmse_pickled_model}") print(f"The ROC AUC of pickled model's prediction is: {auc_pickled_model}")
# continue training # continue training
# init_model accepts: # init_model accepts:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment