ラテックス混同行列



Latex Confusion Matrix



以前、ラテックステーブルを紹介しました。したがって、混同行列は本質的にテーブルです。簡単、高速、正確に描画できます。

最初に描いた場合、紙に挿入したときに必然的に低くなり、拡大縮小すると画像が歪んでしまいます。 Baiduでの検索はありません。だからグーグルを使用してください。



1つ目は、Tikzパッケージを使用した、カラーなし、白黒です。

documentclass{article} usepackage[utf8]{inputenc} usepackage[english]{babel} usepackage{tikz} usetikzlibrary{positioning} egin{document} egin{tikzpicture}[ box/.style={draw,rectangle,minimum size=2cm,text .5cm,align=left}] matrix (conmat) [row sep=.1cm,column sep=.1cm] { ode (tpos) [box, label=left:( mathbf{p'} ), label=above:( mathbf{p} ), ] {True \ positive} & ode (fneg) [box, label=above: extbf{n}, label=above right: extbf{total}, label=right:( mathrm{P}' )] {False \ negative} \ ode (fpos) [box, label=left:( mathbf{n'} ), label=below left: extbf{total}, label=below:P] {False \ positive} & ode (tneg) [box, label=right:( mathrm{N}' ), label=below:N] {True \ negative} \ } ode [left=.05cm of conmat,text .5cm,align=right] { extbf{actual \ value}} ode [above=.05cm of conmat] { extbf{prediction outcome}} end{tikzpicture} end{document}

これは次のようになります。



色付きの場合:

documentclass[english]{article} usepackage[T1]{fontenc} usepackage[latin9]{inputenc} usepackage{babel} usepackage[table]{xcolor} usepackage{collcell} usepackage{hhline} usepackage{pgf} usepackage{multirow} defcolorModel{hsb} %You can use rgb or hsb ewcommandColCell[1]{ pgfmathparse{#1<50?1:0} %Threshold for changing the font color into the cells ifnumpgfmathresult=0 elaxcolor{white}fi pgfmathsetmacrocompA{0} %Component R or H pgfmathsetmacrocompB{#1/100} %Component G or S pgfmathsetmacrocompC{1} %Component B or B edefx{ oexpandcentering oexpandcellcolor[colorModel]{compA,compB,compC}}x #1 } ewcolumntype{E}{>{collectcellColCell}m{0.4cm}<{endcollectcell}} %Cell width ewcommand* ot{ otatebox{90}} egin{document} ewcommanditems{3} %Number of classes arrayrulecolor{white} %Table line colors oindentegin{tabular}{cc*{items}|} multicolumn{1}{c}{} &multicolumn{1}{c}{} &multicolumn{items}{c}{Predicted} \ hhline~*items multicolumn{1}{c}{} & multicolumn{1}{c}{} & multicolumn{1}{c}{ ot{Class A}} & multicolumn{1}{c}{ ot{Class B}} & multicolumn{1}{c}{ ot{Class C}} \ hhline~*items- multirow{items}{*}{ otatebox{90}{Actual}} &Class A & 100 & 0 & 10 \ hhline~*items &Class B & 10 & 80 & 10 \ hhline~*items &Class C & 30 & 0 & 70 \ hhline~*items end{tabular} end{document}

カラーマッチングの変更:

https://tex.stackexchange.com/questions/20267/how-to-construct-a-confusion-matrix-in-latex/20284#20284

そしてまた:

documentclass{article} usepackage[table]{xcolor} usepackage{pgf} usepackage{tikz} usepackage{collcell} usepackage{caption} %The min, mid and max values ewcommand*{MinNumber}{0.0}% ewcommand*{MidNumber}{0.2} % ewcommand*{MaxNumber}{1.0}% defOmitZero#1.#2.#3!{% ifx elax#2 elax % #2 is empty -> no decimal #1% else % #2 not empty -> decimal ifnum#1=0 % we have 0. .#2% else % we have no 0.xx #1.#2% fi fi} %Apply the gradient macro ewcommand{ApplyGradient}[1]{% ifdim #1 pt > MidNumber pt pgfmathsetmacro{PercentColor}{max(min(100.0*(#1 - MidNumber)/(MaxNumber-MidNumber),100.0),0.00)} % hspace{-0.33em}colorbox{green!PercentColor!red}{OmitZero#1..!} else pgfmathsetmacro{PercentColor}{max(min(100.0*(MidNumber - #1)/(MidNumber-MinNumber),100.0),0.00)} % hspace{-0.33em}colorbox{white!PercentColor!red}{OmitZero#1..!} fi } ewcolumntype{G}{>{collectcellApplyGradient}c<{endcollectcell}} enewcommand{arraystretch}{0} setlength{fboxsep}{3mm} % box size setlength{ abcolsep}{0pt} %% for rotation in table usepackage{adjustbox} usepackage{array} ewcolumntype{R}[2]{%>{adjustbox{angle=#1,lap=width-(#2)}group}% l% <{egroup}% } ewcommand* otz{multicolumn{1}{R{0}{-1em}}}% no optional argument here, please! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % END COLORED CM %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% egin{document} egin{table}[t] caption{The confusion matrix} label{tab:CM} centering esizebox{1 extwidth}{!}{ % to nicely resize the table in the text width egin{tabular}{r*{6}{G}} otz{} & otz{A} & otz{B} & otz{C} & otz{D} & otz{E} smallskip \ A & 0.54 & 0 & 0.08 & 0.17 & 0 \ B & 0 & 0.96 & 0 & 0 & 0 \ C & 0.04 & 0.04 & 0.38 & 0.13 & 0 \ D & 0.08 & 0 & 0.04 & 0.75 & 0 \ E & 0 & 0.04 & 0 & 0 & 0.96 \ end{tabular}%parigskip } end{table} end{document}

実際、私たちは以下を使用することを好みます:

次に、これがラテックステーブルではなく図であることに注意してください。したがって、pythonまたはmatlabを使用して描画し、プロットの画像を追加した可能性があります。

まず、以下を使用します。 https://stackoverflow.com/questions/2897826/confusion-matrix-with-number-of-classified-misclassified-instances-on-it-python

ここでのコード生成

による https://ercanozturk.org/2017/12/16/python-matplotlib-plots-in-latex/ 、ここで言った。 PDFとして保存

次に、それをラテックスに追加します。ズームインした後でも非常に鮮明です。それで成功しました。