0
乳膠表格式:字符串轉換爲在Python
>>> from sklearn.metrics import classification_report
>>> y_true = [0, 1, 2, 2, 2]
>>> y_pred = [0, 0, 2, 2, 1]
>>> target_names = ['class 0', 'class 1', 'class 2']
>>> print(classification_report(y_true, y_pred, target_names=target_names))
precision recall f1-score support
class 0 0.50 1.00 0.67 1
class 1 0.00 0.00 0.00 1
class 2 1.00 0.67 0.80 3
avg/total 0.70 0.60 0.61 5
我使用file.write(report)
保存classification_report
爲文本文件,但我想將它保存如TEX表格格式如下:
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{rrrrr}
\toprule
& precision & recall & f1-score & support \\
\midrule
& & & & \\
class 0 & 0.5 & 1 & 0.67 & 1 \\
class 1 & 0 & 0 & 0 & 1 \\
class 2 & 1 & 0.67 & 0.8 & 3 \\
& & & & \\
avg/total & 0.7 & 0.6 & 0.61 & 5 \\
\bottomrule
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
有關如何實現此目的的任何建議?謝謝!
非常感謝,明天我會實施這個! – user3025898