可視化多個二維迴歸的策略?

可視化多個二維迴歸的策略?

希望我能在內容中比標題中更清楚地描述我的問題。它可能更多是關於可視化策略而不是特定的 pgfplots 技術。問題是關於二維輸入的回歸,但請讓我從一維輸入開始。

假設在我的實驗中我改變輸入 x,並觀察輸出 y。我重複實驗三次。該圖顯示了結果(程式碼列在最後):

一維輸入的多元迴歸

現在假設我的實驗有兩個輸入 x 和 y,以及一個輸出 z。對於一項實驗的觀察結果,可以如下繪製:

二維輸入的回歸

然而,對於重複實驗(例如 4-5 次),包含所有這些結果的 3-D 圖相當令人困惑。平均值和偏差圖看起來更好,但肯定丟失了資訊。這是一個例子,當實驗重複兩次(兩組觀察)時,繪圖將是:

二維輸入的多元迴歸

有沒有什麼策略可以更好地視覺化這種情況(多個xyz)? 「更好」可能是指每個單獨的實驗都清晰地呈現,並且多個實驗一起呈現以便於比較。

僅供參考,這些是產生繪圖的 pgfplots 程式碼。

多重 xyz 圖:

\begin{tikzpicture}[scale=0.8]
\begin{axis}
  [scale only axis, width=0.35\textwidth,
  xlabel=x, ylabel=y, zlabel=z, title=Two dimensional input,]
  \addplot3[surf,mesh/rows=5] coordinates { 
    (0,0,0) (1,0,0) (2,0,0) (3,0,0) 
    (0,1,0.1) (1,1,0.3) (2,1,0.3) (3,1,0.4) 
    (0,2,0.15) (1,2,0.5) (2,2,0.5) (3,2,0.5) 
    (0,3,0.65) (1,3,0.60) (2,3,0.65) (3,3,0.45) 
    (0,4,0.8) (1,4,0.75) (2,4,0.85) (3,4,0.65) 
  }; 
 \addplot3[surf,mesh/rows=5] coordinates { 
    (0,0,0.1) (1,0,0.1) (2,0,0) (3,0,0) 
    (0,1,0.3) (1,1,0.2) (2,1,0.2) (3,1,0.4) 
    (0,2,0.15) (1,2,0.6) (2,2,0.5) (3,2,0.5) 
    (0,3,0.55) (1,3,0.7) (2,3,0.65) (3,3,0.45) 
    (0,4,0.6) (1,4,0.85) (2,4,0.65) (3,4,0.35) 
  }; 
\end{axis} 
\end{tikzpicture}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[scale only axis, width=0.3\textwidth,
  xlabel=x, ylabel=y, zlabel=z, title=Mean and Deviation,]
  \addplot3[surf,mesh/rows=5,
    error bars/z dir=both, error bars/z fixed=0.1,] coordinates { 
    (0,0,0.05) (1,0,0.05) (2,0,0) (3,0,0) 
    (0,1,0.2) (1,1,0.25) (2,1,0.25) (3,1,0.4) 
    (0,2,0.15) (1,2,0.55) (2,2,0.5) (3,2,0.5) 
    (0,3,0.65) (1,3,0.65) (2,3,0.65) (3,3,0.45) 
    (0,4,0.7) (1,4,0.80) (2,4,0.75) (3,4,0.5) 
  }; 
\end{axis} 
\end{tikzpicture}

單一 xyz 圖:

\begin{tikzpicture}[scale=0.8]
\begin{axis}
  [scale only axis, width=0.35\textwidth,
  xlabel=x, ylabel=y, zlabel=z, title=Two dimensional input,]
  \addplot3[surf,mesh/rows=5] coordinates { 
    (0,0,0) (1,0,0) (2,0,0) (3,0,0) 
    (0,1,0.1) (1,1,0.3) (2,1,0.3) (3,1,0.4) 
    (0,2,0.15) (1,2,0.5) (2,2,0.5) (3,2,0.5) 
    (0,3,0.65) (1,3,0.60) (2,3,0.65) (3,3,0.45) 
    (0,4,0.8) (1,4,0.75) (2,4,0.85) (3,4,0.65) 
  }; 
\end{axis} 
\end{tikzpicture}
\hfill
\begin{tikzpicture}[scale=0.8]
\begin{axis}[view={0}{90}, scale only axis, width=0.3\textwidth,
  xlabel=x, ylabel=y, zlabel=z, title=Top view of two dimensional input, ]
  \addplot3[surf,mesh/rows=5] coordinates { 
    (0,0,0) (1,0,0) (2,0,0) (3,0,0) 
    (0,1,0.1) (1,1,0.3) (2,1,0.3) (3,1,0.4) 
    (0,2,0.15) (1,2,0.5) (2,2,0.5) (3,2,0.5) 
    (0,3,0.65) (1,3,0.60) (2,3,0.65) (3,3,0.45) 
    (0,4,0.8) (1,4,0.75) (2,4,0.85) (3,4,0.65) 
  }; 
\end{axis} 
\end{tikzpicture}

多個 xy 圖:

\begin{tikzpicture}
\begin{axis}
  [scale only axis, width=0.3\textwidth,
  xlabel=x, ylabel=y, title=One dimensional input]
  \addplot coordinates{(0, 0.6) (0.1, 0.25) (0.2, 0.1) (0.3, 0.06) (0.4, 0.02) (0.5, 0.01)};
  \addplot coordinates{(0, 0.7) (0.1, 0.1) (0.2, 0.125) (0.3, 0.08) (0.4, 0.016) (0.5, 0.02)};
  \addplot coordinates{(0, 0.5) (0.1, 0.15) (0.2, 0.15) (0.3, 0.10) (0.4, 0.012) (0.5, 0.03)};
  \legend{exp1, exp2, exp3}
\end{axis}
\end{tikzpicture}
\hfill
\begin{tikzpicture}
\begin{axis}
  [scale only axis, width=0.3\textwidth,
  xlabel=x, ylabel=y, title=Mean and Deviation]
  \addplot[ error bars/.cd, y dir=both, y explicit, ]
    coordinates{(0, 0.6)  +- (0, 0.1) 
                    (0.1, 0.1)  +- (0, 0.1)
                    (0.2, 0.125) +- (0, 0.025)
                    (0.3, 0.08) +- (0, 0.08) 
                    (0.4, 0.016) +- (0, 0.04)
                  (0.5, 0.02) +- (0, 0.02)};
\end{axis}
\end{tikzpicture}

然而,

答案1

為了獲得這張照片...

在此輸入影像描述

....嘗試這些指令,

pdflatex example.tex; asy  -twosided *.asy; pdflatex example.tex

...編譯這個例子。

\documentclass[]{article}
\usepackage[]{asymptote}
\begin{document}
Two Dimensional Input

\vspace{3cm}
\begin{asy}
settings.render=4;
import three;
import graph3;
currentlight=White;
currentprojection=orthographic(3,-5,1,center=true);
size(5cm);
size3(5cm,5cm,5cm, IgnoreAspect);

render render=render(compression=Low,merge=true);
triple[][] t1 = 
{
 {(0,0,0), (1,0,0), (2,0,0), (3,0,0) }, 
 {(0,1,0.1), (1,1,0.3), (2,1,0.3), (3,1,0.4)}, 
 {(0,2,0.15), (1,2,0.5), (2,2,0.5), (3,2,0.5)},
 {(0,3,0.65), (1,3,0.60), (2,3,0.65), (3,3,0.45)},
 {(0,4,0.8), (1,4,0.75), (2,4,0.85), (3,4,0.65)}
};
triple[][] t2 = 
{
   {(0,0,0.1), (1,0,0.1), (2,0,0), (3,0,0)},
   {(0,1,0.3), (1,1,0.2), (2,1,0.2), (3,1,0.4)},
   {(0,2,0.15), (1,2,0.6), (2,2,0.5), (3,2,0.5)},
   {(0,3,0.55), (1,3,0.7), (2,3,0.65), (3,3,0.45)},
   {(0,4,0.6),(1,4,0.85),(2,4,0.65),(3,4,0.35)}
};

draw(surface(t1), blue+opacity(0.9));
draw(surface(t2), red+opacity(0.6));

xaxis3("$x$",Bounds,InTicks);
yaxis3("$y$",Bounds,InTicks);
zaxis3("$z$",Bounds,InTicks);

\end{asy}
\end{document}

顯然你需要在你的系統中安裝 pdflatex、asymptote 套件和 asymptote。幸運的是,如果您使用最新版本的 Acrobat Reader 開啟 PDF,您也會在 PDF 中取得互動式 3D 物件。

不用說,我同意傑克的觀點,即使你可以用 pgfplots 做到這一點(你不能簡單地做到這一點),它也是非常令人困惑的。

答案2

另一個類似的解決方案,但純粹使用pgfplots(不是asymptote),是將opacity=0.5選項添加到曲面。像這樣:

 \addplot3[surf,mesh/rows=5, opacity=0.5] coordinates { ...

不透明技巧

它仍然不完美,但至少圖像是物理的(鬼面相互滲透)並且不會因為創建不可能的 3D 物件而傷害大腦。請注意,該技巧僅適用於值 0.5(即表面不覆蓋其他表面),否則表面開始以大腦認為奇怪的方式重疊。

您甚至可以對誤差線(使用 )使用相同的技巧opacity以獲得以下效果:

帶有誤差線的不透明度

下面是最後一張圖的完整程式碼:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.8]
\begin{axis}
  [scale only axis, width=0.35\textwidth,
  xlabel=x, ylabel=y, zlabel=z, title=Two dimensional input,]
  \addplot3[surf,mesh/rows=5,opacity=0.5] coordinates { 
    (0,0,0) (1,0,0) (2,0,0) (3,0,0) 
    (0,1,0.1) (1,1,0.3) (2,1,0.3) (3,1,0.4) 
    (0,2,0.15) (1,2,0.5) (2,2,0.5) (3,2,0.5) 
    (0,3,0.65) (1,3,0.60) (2,3,0.65) (3,3,0.45) 
    (0,4,0.8) (1,4,0.75) (2,4,0.85) (3,4,0.65) 
  }; 
 \addplot3[surf,mesh/rows=5, opacity=0.5] coordinates { 
    (0,0,0.1) (1,0,0.1) (2,0,0) (3,0,0) 
    (0,1,0.3) (1,1,0.2) (2,1,0.2) (3,1,0.4) 
    (0,2,0.15) (1,2,0.6) (2,2,0.5) (3,2,0.5) 
    (0,3,0.55) (1,3,0.7) (2,3,0.65) (3,3,0.45) 
    (0,4,0.6) (1,4,0.85) (2,4,0.65) (3,4,0.35) 
  }; 
  \addplot3[mesh/rows=5,
    error bars/z dir=both, error bars/z fixed=0.1, opacity=0.3, draw=none] coordinates { 
    (0,0,0.05) (1,0,0.05) (2,0,0) (3,0,0) 
    (0,1,0.2) (1,1,0.25) (2,1,0.25) (3,1,0.4) 
    (0,2,0.15) (1,2,0.55) (2,2,0.5) (3,2,0.5) 
    (0,3,0.65) (1,3,0.65) (2,3,0.65) (3,3,0.45) 
    (0,4,0.7) (1,4,0.80) (2,4,0.75) (3,4,0.5) 
  };
\end{axis} 
\end{tikzpicture}
\end{document}

相關內容