% generate some random data n=200; m=20; beta_true=randn(m,1); epsilon=1E-1; X=rand(n,m)-.5; y=X*beta_true+randn(n,1)*epsilon; % normalize everything [n,m]=size(X); y=y-mean(y); y=y/std(y); X=X-repmat(mean(X,1),n,1); stdX=std(X,0,1); %sqrt(sum(X.^2,1)); X=X./repmat(stdX,n,1); beta_true=beta_true.*stdX'; % feed it to LARS [betas]=lars(X,y); % look at the betas as they change figure(1); s=sum(abs(betas),1); plot(s, betas'); xlabel('|\beta|'); ylabel('\beta_i'); title('coefficients(\beta''s) as they change'); % look at performance of regression, i.e. estimating the true beta figure(2); plot(sqrt(sum((repmat(beta_true,1,m)-betas).^2,1))); xlabel('number of features'); ylabel('L_2 norm with true \beta'); title('regression performance vs number of features');