I found this hard to read, could we refactor it slightly? Maybe to something like this:

    sorted_groups = example_groups.sort_by { |_, hash| -hash[:average] }.first(number_of_examples)