[英]How to display classification report in flask web application
我需要將輸出顯示在分類矩陣中,但是我得到一個字符串作為輸出
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.89 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中使用python和燒瓶的簡單表
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.