plotting using a box plot

1 次查看(过去 30 天)
fafz1203
fafz1203 2016-10-18
The following MATLAB code works correctly. After making this calculations I want to do 100 realizations of the training data (xTrain and yTrain). By that I mean, basically run it 100 times with different xTrain and yTrain. After that I want to plot these values I got on a box plot. Please see the attached image below to illustrate the box plot I want. Can anyone help with this.
Let me know if anything is unclear.
sigma = eye(10);
mu = repelem(zeros,10);
sd1 = 0.01; sd2 = 0.1; sd3 = 0.25;
xTrain = mvnrnd(mu,sigma,1000);
xTest = mvnrnd(mu,sigma,1000);
betaTruth = (mvnrnd (mu,sigma))';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
epTest1 = noise(sd1); epTest2 = noise(sd2); epTest3 = noise(sd3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
yTest1 = yValues(xTest,betaTruth,epTest1);
yTest2 = yValues(xTest,betaTruth,epTest2);
yTest3 = yValues(xTest,betaTruth,epTest3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
betaHat1 = beta(xTrain,yTrain1);
betaHat2 = beta(xTrain,yTrain2);
betaHat3 = beta(xTrain,yTrain3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
testError1 = error(xTest,betaHat1,yTest1);
testError2 = error(xTest,betaHat2,yTest2);
testError3 = error(xTest,betaHat3,yTest3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function n = noise(x)
n = x.*randn(1000,1);
end
function e = error(x,b,y)
diff = ((x*b) - y).^2;
e = sum (diff(:))/1000;
end
function y = yValues(x,b,n)
y = (x*b) + n;
end
function b = beta(x,y)
b = (inv(x'*x)*x')*y;
end
  2 个评论
fafz1203
fafz1203 2016-10-18
the functions are found at the bottom
fafz1203
fafz1203 2016-10-18
Here is a picture of the plot I should obtain

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by