Filter löschen
Filter löschen

plotting using a box plot

1 Ansicht (letzte 30 Tage)
fafz1203
fafz1203 am 18 Okt. 2016
Bearbeitet: Walter Roberson am 18 Okt. 2016
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 Kommentare
fafz1203
fafz1203 am 18 Okt. 2016
the functions are found at the bottom
fafz1203
fafz1203 am 18 Okt. 2016
Here is a picture of the plot I should obtain

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by