# How to compute the generalization error (test error) in a multivariate regression?

How can I, after running multivariate linear regression, compute the Generalization Error (also known as Test Error)? Are there many practises to do that?

EDIT: Can the following be considered as Generalization (or Test) Error?

y = data1; [M,N] = size(y);
X = [ones(M,N) data2];
y_train = y(M-30-483:M-30,:);
X_train = X(M-30-483:M-30,:);
y_test = y(M-29:M,:);
X_test = X(M-29:M,:);

[b,~,r,~,stats] = regress(y_train,X_train);
[M,N] = size(data2);
figure; plot(r);
axis([0,N+1,-Inf,Inf]);

y_estimated = X_test * b; y_expected = y_test;
generalization_error = y_expected - y_estimated;
figure; plot(generalization_error);
• I take it that you're wondering how to do this in Matlab? Jul 22, 2012 at 8:37
• @MånsT: Basically yes, but I would also appreciate if you could provide a few hints regarding the theoretical aspects of this concept... Jul 22, 2012 at 19:51
• possible duplicate you can check this stats.stackexchange.com/questions/32748/… Feb 8, 2013 at 1:43