问题描述
使用 this example,我为 catboost 创建了一个精确召回 AUC 评估指标。但是,我需要一些关于如何使其与 class_weights
参数兼容的指导,我将在其中传递列表(例如:[625.0,0.500400320256205]),因为我有很大的类不平衡。以下是我的自定义评估指标:
from sklearn.metrics import average_precision_score
import numpy as np
from scipy.special import expit
# define pr-AUC custom eval metric
class PrecisionRecallAUC:
# define a static method to use in evaluate method
@staticmethod
def get_pr_auc(y_true,y_pred):
# fit predictions to logistic sigmoid function
y_pred = expit(y_pred).astype(float)
# actual values should be 1 or 0 integers
y_true = y_true.astype(int)
# calculate average precision
flt_pr_auc = average_precision_score(y_true=y_true,y_score=y_pred)
return flt_pr_auc
# define a function to tell catboost that greater is better (or not)
def is_max_optimal(self):
# greater is better
return True
# get the score
def evaluate(self,approxes,target,weight):
# make sure length of approxes == 1
assert len(approxes) == 1
# make sure length of target is the same as predictions
assert len(target) == len(approxes[0])
# set target to integer and save as y_true
y_true = np.array(target).astype(int)
# save predictions
y_pred = approxes[0]
# generate score
score = self.get_pr_auc(y_true=y_true,y_pred=y_pred)
return score,1
# return score
def get_final_error(self,error,weight):
return error
如何在此自定义评估指标中使用我的类权重列表?
提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)