(x,y1)と(x,​y2)の2つの散布図​のy軸方向の差を描写​する方法

19 views (last 30 days)
SH
SH on 10 Mar 2018
Answered: SH on 10 Mar 2018
scatter(x,y1)
hold on
scatter(x,y2)
の時、y方向差分をグラフ中に図示する方法を教えてください。
例えば、機械学習の回帰学習時には誤差を描画できます。 回帰学習で作ったモデルで予測した予測値(y1)と真値(y2)の差を一目でわかるように図示したいです。

Accepted Answer

michio
michio on 10 Mar 2018
一例まで、plot 関数で誤差を表すy1とy2を結ぶ線分を1本ずつ描く方法を紹介します。
x = 1:5;
y1 = rand(5,1); % ランダムなデータで代用
y2 = movmean(y1,3); % y1 を移動平均取った値で代用
idx = [x;x]; %
scatter(x,y1,'k');
hold on
scatter(x,y2,'r');
plot(idx,[y1,y2]','-r')
hold off
ここで、idx, [y1,y2]' (転置に注意)を以下のような形 (idx は 2x5, [y1,y2]' も同じく 2x5 の行列) で入力し 5 本の線を描いています。
>> idx
ans =
1 2 3 4 5
1 2 3 4 5
>> [y1,y2]'
ans =
0.8085 0.7551 0.3774 0.2160 0.7904
0.7818 0.6470 0.4495 0.4613 0.5032

More Answers (1)

SH
SH on 10 Mar 2018
ありがとうございます。問題は解決しました。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!