编辑:感谢Chinny,我将稍微改变一下我的问题:
上下文:我正在处理一组带有二进制目标变量的数据。1只占数据的10%,所以虽然我在使用GridSearchCV时使用了一些技术(例如下采样),但我想只对类1周围的指标进行评分。
例如,我最好的模型可能是0级召回率为0.98,1级召回率为0.28,总召回率为0.91,因为0级的数量比1级的数量多很多。
我更喜欢选择0级召回率为0.93,1级召回率为0.58,总体召回率为0.85的模型。
下面是我的设置的一个简单示例:
param_grid = {'n_estimators':[100,200,300,400],
'random_state':[1]}
extra_tree_Grid = GridSearchCV(et, param_grid, cv = 5, scoring = "f1",
refit = True, n_jobs=2, verbose = 5)
extra_tree_Grid.fit(X_train_new, y_train_new.ravel())Chinny84建议我研究一下"make_scorer“函数,我尝试了一下这个函数,但仍然得到了与我只使用GridSearchCV的评分参数中已经存在的"f1”或"recall“相同的输出。
或者,我得到一个错误。下面是我想要的示例(不是实际编码的)
from sklearn.metrics import f1_score, recall_score, make_scorer
def custom_recall(y_true, y_pred):
'filter for class 1 for both y_true and y_pred'
'target_accuracy = (y_pred Class 1 & are Class 1) / y_true Class 1'
return target_accuracy
my_scorer = make_scorer(custom_recall)我想我可以从存在的度量"recall“中提取一个特定的类,在这种情况下,我想提取那些属于类1的类,但我在如何设置它方面迷失了方向。
发布于 2016-12-03 05:40:29
虽然sklearn库中可能存在评分函数,但您绝对可以创建自己的记分器(假设您的基础模型允许使用此类函数)。
看看sklearn - make_scorer中的这个方法。
https://stackoverflow.com/questions/40941045
复制相似问题