Effacer les filtres
Effacer les filtres

plotting using a box plot

1 vue (au cours des 30 derniers jours)
fafz1203
fafz1203 le 18 Oct 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 commentaires
fafz1203
fafz1203 le 18 Oct 2016
the functions are found at the bottom
fafz1203
fafz1203 le 18 Oct 2016
Here is a picture of the plot I should obtain

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by