could you please use this function in classify_for_multiple_k to avoid code duplication