【问题标题】:Evaluating Multiple Classifier using f2 score使用 f2 分数评估多个分类器
【发布时间】:2021-04-16 15:32:40
【问题描述】:

我正在尝试对一些模型进行二元分类。我想根据分数和 f2 分数对模型进行分类。

对于“分数”,我使用了代码

for name, clf in zip(models, classifiers):
    clf.fit(X_train, y_train)
    score = clf.score(X_test, y_test)
    scores.append(score)

它给出了所有模型的分数,但我无法找到所有模型的 f2 分数。谁能建议代码应该是什么?

【问题讨论】:

    标签: python machine-learning


    【解决方案1】:

    您可以使用fbeta_score,只需将 β 设置为 2。

    from sklearn.metrics import fbeta_score
    
    scores = []
    f2_score = []
    
    for name, clf in zip(models, classifiers):
        clf.fit(X_train, y_train)
        y_pred = clf.predict(X_test)
        f2 = beta_score(y_test, y_pred, beta=2, average='binary')
        score = clf.score(X_test, y_test)
        scores.append(score)
        f2_score.append(f2)
    

    【讨论】:

    • 在这种情况下如何定义'y_true'。
    • @cris2019 道歉它应该是 y_test 这是真正的标签。
    • @yudhiesh 还有一个问题,如果我使用 GridSearchCV 并想找到每个模型的 find f2 分数,我该怎么办。我想在数据框中显示分数和 f2 分数。
    • scores = [] for model_name, mp in model_params.items(): clf = GridSearchCV(mp['model'], mp['params'], cv=5, return_train_score=False) clf.fit(X_test, y_test) scores.append({ 'model': model_name, 'best_score': clf.best_score_, 'best_params': clf.best_params_, 'f2_score': fbeta_score(y_test, y_pred, beta=2, average='binary') }) df = pd.DataFrame(scores,columns=['model','best_score','best_params','f2_score']) df
    • @cris2019 嗨,请为此创建一个新问题。
    猜你喜欢
    • 2021-07-12
    • 2017-06-10
    • 2016-08-22
    • 1970-01-01
    • 2020-07-01
    • 2018-07-06
    • 1970-01-01
    • 2013-05-08
    • 2021-04-10
    相关资源
    最近更新 更多