简体   繁体   English

在使用 scikit-learn 在管道中安装 ML model 后,如何将精度与 score() function 中的另一个性能指标交换?

[英]How do I swap accuracy with another performance metric from the score() function after fitting the ML model in Pipeline with scikit-learn?

Here is a part of my code:这是我的代码的一部分:

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))

The score() seems to be producing accuracy. score()似乎产生了准确性。 How can I swap accuracy with another performance metrics such as F1-macro or recall-macro ?如何将准确率与F1-macrorecall-macro等其他性能指标交换? I couldn't find anything in the document .我在文档中找不到任何东西。

The short answer to your question is no, unless you hack your way through and redefine/overwrite the scikit-learn functions.对您的问题的简短回答是否定的,除非您破解并重新定义/覆盖scikit-learn函数。

When you are using pipe.score() , it calls the score method from the classifier that is in the end of the pipeline.当您使用pipe.score()时,它会从位于管道末尾的分类器中调用 score 方法。

Now, what is happening under the hood is that all classifiers in scikit-learn are based on the ClassifierMixin class, for which .score() is defined through accuracy_score , and this is hard-coded (see here ).现在,幕后发生的事情是scikit-learn中的所有分类器都基于ClassifierMixin class,其中.score()是通过accuracy_score定义的,这是硬编码的(参见此处)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM