如何在Blask Web应用程序中显示分类报告



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

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.90 0.23 0.23 0.36 466 MICRO AVG 0.92 0.92 0.92 0.92 4539宏观AVG 0.91 0.61 0.61 0.66 0.66 4539加权AVG 0.92 0.92 0.92 0.92 0.92 0.89 4539 4539

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>

我相信您必须先在html中设置此分类矩阵模板。我建议您阅读此博客。webapps中的简单表格,使用flask and-pandas-with-with-python

相关内容

  • 没有找到相关文章

最新更新