Automatic early stopping using cross validation