Mean-field Analysis of Generalization Errors