简体   繁体   中英

How to display classification report in flask web application

i need output to be displayed in classification matrix from but i am getting a string as output

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)

output :

XGBOOST:: classification report and accuracy score : precision recall f1-score support 0 0.92 1.00 0.96 4073 1 0.90 0.23 0.36 466 micro avg 0.92 0.92 0.92 4539 macro avg 0.91 0.61 0.66 4539 weighted avg 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>

I believe you would have to set this classification matrix template in html first. I would suggest you to read this blog. simple-tables-in-webapps-using-flask-and-pandas-with-python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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