use cross validation to find optimal K