Single-linkage clustering for optimal classification in piecewise affine regression