Misplaced Pages

Generalization error

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Measure of algorithm accuracy

For supervised learning applications in machine learning and statistical learning theory, generalization error (also known as the out-of-sample error or the risk) is a measure of how accurately an algorithm is able to predict outcomes for previously unseen data. As learning algorithms are evaluated on finite samples, the evaluation of a learning algorithm may be sensitive to sampling error. As a result, measurements of prediction error on the current data may not provide much information about the algorithm's predictive ability on new, unseen data. The generalization error can be minimized by avoiding overfitting in the learning algorithm. The performance of machine learning algorithms is commonly visualized by learning curve plots that show estimates of the generalization error throughout the learning process.

Definition

See also: Statistical learning theory

In a learning problem, the goal is to develop a function f n ( x ) {\displaystyle f_{n}({\vec {x}})} that predicts output values y {\displaystyle y} for each input datum x {\displaystyle {\vec {x}}} . The subscript n {\displaystyle n} indicates that the function f n {\displaystyle f_{n}} is developed based on a data set of n {\displaystyle n} data points. The generalization error or expected loss or risk I [ f ] {\displaystyle I} of a particular function f {\displaystyle f} over all possible values of x {\displaystyle {\vec {x}}} and y {\displaystyle y} is the expected value of the loss function V ( f ) {\displaystyle V(f)} :

I [ f ] = X × Y V ( f ( x ) , y ) ρ ( x , y ) d x d y , {\displaystyle I=\int _{X\times Y}V(f({\vec {x}}),y)\rho ({\vec {x}},y)d{\vec {x}}dy,}

where ρ ( x , y ) {\displaystyle \rho ({\vec {x}},y)} is the unknown joint probability distribution for x {\displaystyle {\vec {x}}} and y {\displaystyle y} .

Without knowing the joint probability distribution ρ {\displaystyle \rho } , it is impossible to compute I [ f ] {\displaystyle I} . Instead, we can compute the error on sample data, which is called empirical error (or empirical risk). Given n {\displaystyle n} data points, the empirical error of a candidate function f {\displaystyle f} is:

I n [ f ] = 1 n i = 1 n V ( f ( x i ) , y i ) {\displaystyle I_{n}={\frac {1}{n}}\sum _{i=1}^{n}V(f({\vec {x}}_{i}),y_{i})}

An algorithm is said to generalize if:

lim n I [ f ] I n [ f ] = 0 {\displaystyle \lim _{n\rightarrow \infty }I-I_{n}=0}

Of particular importance is the generalization error I [ f n ] {\displaystyle I} of the data-dependent function f n {\displaystyle f_{n}} that is found by a learning algorithm based on the sample. Again, for an unknown probability distribution, I [ f n ] {\displaystyle I} cannot be computed. Instead, the aim of many problems in statistical learning theory is to bound or characterize the difference of the generalization error and the empirical error in probability:

P G = P ( I [ f n ] I n [ f n ] ϵ ) 1 δ n {\displaystyle P_{G}=P(I-I_{n}\leq \epsilon )\geq 1-\delta _{n}}

That is, the goal is to characterize the probability 1 δ n {\displaystyle 1-\delta _{n}} that the generalization error is less than the empirical error plus some error bound ϵ {\displaystyle \epsilon } (generally dependent on δ {\displaystyle \delta } and n {\displaystyle n} ). For many types of algorithms, it has been shown that an algorithm has generalization bounds if it meets certain stability criteria. Specifically, if an algorithm is symmetric (the order of inputs does not affect the result), has bounded loss and meets two stability conditions, it will generalize. The first stability condition, leave-one-out cross-validation stability, says that to be stable, the prediction error for each data point when leave-one-out cross validation is used must converge to zero as n {\displaystyle n\rightarrow \infty } . The second condition, expected-to-leave-one-out error stability (also known as hypothesis stability if operating in the L 1 {\displaystyle L_{1}} norm) is met if the prediction on a left-out datapoint does not change when a single data point is removed from the training dataset.

These conditions can be formalized as:

Leave-one-out cross-validation Stability

An algorithm L {\displaystyle L} has C V l o o {\displaystyle CVloo} stability if for each n {\displaystyle n} , there exists a β C V ( n ) {\displaystyle \beta _{CV}^{(n)}} and δ C V ( n ) {\displaystyle \delta _{CV}^{(n)}} such that:

i { 1 , . . . , n } , P S { | V ( f S i , z i ) V ( f S , z i ) | β C V ( n ) } 1 δ C V ( n ) {\displaystyle \forall i\in \{1,...,n\},\mathbb {P} _{S}\{|V(f_{S^{i}},z_{i})-V(f_{S},z_{i})|\leq \beta _{CV}^{(n)}\}\geq 1-\delta _{CV}^{(n)}}

and β C V ( n ) {\displaystyle \beta _{CV}^{(n)}} and δ C V ( n ) {\displaystyle \delta _{CV}^{(n)}} go to zero as n {\displaystyle n} goes to infinity.

Expected-leave-one-out error Stability

An algorithm L {\displaystyle L} has E l o o e r r {\displaystyle Eloo_{err}} stability if for each n {\displaystyle n} there exists a β E L m {\displaystyle \beta _{EL}^{m}} and a δ E L m {\displaystyle \delta _{EL}^{m}} such that:

i { 1 , . . . , n } , P S { | I [ f S ] 1 n i = 1 N V ( f S i , z i ) | β E L ( n ) } 1 δ E L ( n ) {\displaystyle \forall i\in \{1,...,n\},\mathbb {P} _{S}\left\{\left|I-{\frac {1}{n}}\sum _{i=1}^{N}V\left(f_{S^{i}},z_{i}\right)\right|\leq \beta _{EL}^{(n)}\right\}\geq 1-\delta _{EL}^{(n)}}

with β E L ( n ) {\displaystyle \beta _{EL}^{(n)}} and δ E L ( n ) {\displaystyle \delta _{EL}^{(n)}} going to zero for n {\displaystyle n\rightarrow \infty } .

For leave-one-out stability in the L 1 {\displaystyle L_{1}} norm, this is the same as hypothesis stability:

E S , z [ | V ( f S , z ) V ( f S i , z ) | ] β H ( n ) {\displaystyle \mathbb {E} _{S,z}\leq \beta _{H}^{(n)}}

with β H ( n ) {\displaystyle \beta _{H}^{(n)}} going to zero as n {\displaystyle n} goes to infinity.

Algorithms with proven stability

A number of algorithms have been proven to be stable and as a result have bounds on their generalization error. A list of these algorithms and the papers that proved stability is available here.

Relation to overfitting

See also: Overfitting
This figure illustrates the relationship between overfitting and the generalization error I - IS. Data points were generated from the relationship y = x with white noise added to the y values. In the left column, a set of training points is shown in blue. A seventh order polynomial function was fit to the training data. In the right column, the function is tested on data sampled from the underlying joint probability distribution of x and y. In the top row, the function is fit on a sample dataset of 10 datapoints. In the bottom row, the function is fit on a sample dataset of 100 datapoints. As we can see, for small sample sizes and complex functions, the error on the training set is small but error on the underlying distribution of data is large and we have overfit the data. As a result, generalization error is large. As the number of sample points increases, the prediction error on training and test data converges and generalization error goes to 0.

The concepts of generalization error and overfitting are closely related. Overfitting occurs when the learned function f S {\displaystyle f_{S}} becomes sensitive to the noise in the sample. As a result, the function will perform well on the training set but not perform well on other data from the joint probability distribution of x {\displaystyle x} and y {\displaystyle y} . Thus, the more overfitting occurs, the larger the generalization error.

The amount of overfitting can be tested using cross-validation methods, that split the sample into simulated training samples and testing samples. The model is then trained on a training sample and evaluated on the testing sample. The testing sample is previously unseen by the algorithm and so represents a random sample from the joint probability distribution of x {\displaystyle x} and y {\displaystyle y} . This test sample allows us to approximate the expected error and as a result approximate a particular form of the generalization error.

Many algorithms exist to prevent overfitting. The minimization algorithm can penalize more complex functions (known as Tikhonov regularization), or the hypothesis space can be constrained, either explicitly in the form of the functions or by adding constraints to the minimization function (Ivanov regularization).

The approach to finding a function that does not overfit is at odds with the goal of finding a function that is sufficiently complex to capture the particular characteristics of the data. This is known as the bias–variance tradeoff. Keeping a function simple to avoid overfitting may introduce a bias in the resulting predictions, while allowing it to be more complex leads to overfitting and a higher variance in the predictions. It is impossible to minimize both simultaneously.

References

  1. ^ Mohri, M., Rostamizadeh A., Talwakar A., (2018) Foundations of Machine learning, 2nd ed., Boston: MIT Press
  2. Y S. Abu-Mostafa, M.Magdon-Ismail, and H.-T. Lin (2012) Learning from Data, AMLBook Press. ISBN 978-1600490064
  3. ^ Mukherjee, S.; Niyogi, P.; Poggio, T.; Rifkin., R. M. (2006). "Learning theory: stability is sufficient for generalization and necessary and sufficient for consistency of empirical risk minimization" (PDF). Adv. Comput. Math. 25 (1–3): 161–193. doi:10.1007/s10444-004-7634-z. S2CID 2240256.

Further reading

Differentiable computing
General
Hardware
Software libraries
Category: