from sklearn.model_selection import GridSearchCV
from sklearn.metrics import precision_score, make scorer
# here the scoring function is created. make_scorer passes the pos_label=0
# argument to sklearn.metrics.precision_score() to create the desired function.
neg_precision = make_scorer(precision_score, pos_label=0)
# some random C parameters for completion
params = {'C': [0.01, 0.03, 0.1, 0.3, 1, 3, 10]}
clf = GridSearchCV(LinearSVC(class_weight='balanced'), cv=10,param_grid=params, scoring=neg_precision)
clf.fit(X, y)
我最终在Scikit评分函数文档中找到了答案。在
可以根据负面标签计算得分,方法是将其重新定义为“正面标签”(仅用于评分)。例如:
我个人决定使用scoring='f1'u macro'。这将计算正标签的f1分数和负标签的f1分数的非加权平均值。这产生了我追求的结果。在
相关问题 更多 >
编程相关推荐