def get_optimal_num_clusters(n_clusters_vector, obj_vals):
    """
    Function to find the optimal number of clusters for the given dataset
    Input:
        - n_clusters_vector: vector of various cluster lenghts to evaluate
        - objVals: The list of final values of the inertia criterion (sum
          of squared distances to the closest centroid for all observations
          in the training set) for all values of number of clusters
    Output:
        - optimal_num_clusters: optimal number of clusters for the given data
    """
    optimal_num_clusters = n_clusters_vector[0]
    epsilon = 0.05
    for i in range(1, len(n_clusters_vector)):
        if obj_vals[i - 1] - obj_vals[i] < epsilon:
            optimal_num_clusters = n_clusters_vector[i - 1]
            break
    return optimal_num_clusters
