【问题标题】:How to display classification report in flask web application如何在烧瓶 Web 应用程序中显示分类报告
【发布时间】:2019-11-14 07:56:47
【问题描述】:

我需要将输出显示在分类矩阵中 但我得到一个字符串作为输出

from pyod.models.xgbod import XGBClassifier
clf = XGBClassifier(max_depth=15, min_child_weight=4, gamma=0.3,
                    colsample_bytree=0.4)  # max_depth = 15, min_child_weight =4
clf.fit(x_train[:, np.newaxis], y_train)

y_pred1 = clf.predict(x_test[:, np.newaxis])
y_prob1 = clf.predict_proba(x_test[:, np.newaxis])

n_errors1 = (y_pred1 != y_test).sum()
print('')
print('XG boost no of Errors :{}'.format(n_errors1))
print('Accuracy Score: ', accuracy_score(y_test, y_pred1))
print('Classification report :')
print(classification_report(y_test, y_pred1))
av = accuracy_score(y_test, y_pred1)
cv = classification_report(y_test, y_pred1)

f1_score_xgb =   f1_score(y_test, y_pred1, average='weighted')
print(f1_score_xgb)

return render_template('classification_report.html',cv = cv,f1_score =f1_score_xgb)

输出:

XGBOOST:: 分类报告和准确度得分:精确召回 f1 得分支持 0 0.92 1.00 0.96 4073 1 0.90 0.23 0.36 466 微观平均 0.92 0.92 0.92 4539 宏观平均 0.91 0.61 0.66 4539 加权平均 0.92 0.92 0.8p

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>XG_BOOST Accuracy & C_report</title></head>
<body><h1> XGBOOST::</h1>
<p> classification report and accuracy score :{{cv}} </p>
<p> f1 score {{f1_score}}</p>
<p>print(cv)</p></body>
</html>

【问题讨论】:

  • 能否也加入classification_report.html
  • 包括html报告谢谢
  • classificationreport.html: ''' XG_BOOST Accuracy & C_report title>

    XGBOOST::

    分类报告和准确度得分:{{cv}}

    f1 score {{f1_score}}

    打印(cv)

    '''
  • 您的 HTML 似乎没有问题。它应该显示一个标题,其下有三个段落。你看到了什么?
  • 我只看到分类报告显示为字符串 XGBOOST:: 分类报告和准确度分数:精确召回 f1 分数支持 0 0.92 1.00 0.96 4073 1 0.90 0.23 0.36 466 微平均 0.92 0.92 0.92 4539 宏平均 0.91 0.61 0.66 4539 加权平均 0.92 0.92 0.89 4539

标签: python machine-learning flask plotly-dash data-science-experience


【解决方案1】:

我相信你必须先在 html 中设置这个分类矩阵模板。我建议你阅读这个博客。 simple-tables-in-webapps-using-flask-and-pandas-with-python

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-08
    • 2018-10-16
    相关资源
    最近更新 更多