added training function

added train() to iterate until less than the argument threshold