필터 지우기
필터 지우기

plotting using a box plot

조회 수: 1 (최근 30일)
fafz1203
fafz1203 2016년 10월 18일
편집: Walter Roberson 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