在使用scikit-learn在管道中拟合ML模型后,如何将准确性与score()函数中的另一个性能指标交换?



这是我代码的一部分:

def ml_pipeline(self):
if self.control_panel['ml_pipeline_switch']:
self.model = make_pipeline(self.preprocessor, self.control_panel['ml_algo'][1])
self.model.fit(self.X_train, self.y_train)
def ml_pipeline_result(self, show_control_panel_switch=True): 
if self.control_panel['ml_pipeline_switch']:
print('Model score (training set): %.3f' % self.model.score(self.X_train, self.y_train))
print('Model score (test set): %.3f' % self.model.score(self.X_test, self.y_test))

score()似乎正在产生准确性。如何将准确性与其他性能指标(如F1-macrorecall-macro(交换?我在文档中找不到任何内容。

对你的问题的简短回答是否定的,除非你破解并重新定义/覆盖scikit-learn函数。

使用pipe.score()时,它会从管道末尾的分类器调用 score 方法。

现在,幕后发生的事情是,scikit-learn中的所有分类器都基于ClassifierMixin类,为此.score()是通过accuracy_score定义的,这是硬编码的(见这里(。

最新更新