I like polls. They’re easy to interact with, and if you have a big groupchat, you can get a lot of responses.

For Valentine’s day this year, I decided to make a script I could run to pair together people who answer polls similarly. This way people could become friends with people that they are compatible with.

Gathering Data

When someone answers a poll, let’s assign them a score relative to the other participants.

How we do this is somewhat arbitrary, so let’s give an example poll:

Ideal Hangout?CampingFairgroundFancy DinnerConcert
Camping5224
Fairground2532
Fancy Dinner2353
Concert4235

This is what I call a mapping. It determines the score that two people get when they answer a question. For example, if Person A says Camping and Person B says Fancy Dinner, we’ll give them a score of 2, since those are very different activities.

When asking multiple questions, just add together the scores from each question to get a total score.

Data Cleanup

After asking a few questions, we now have a pretty well-defined series of connections.

One problem is if someone didn’t answer all the questions. Their connection scores might look similar to someone who is less compatible.

To fix this, we can first delete anyone who didn’t answer at least a few polls.

Next, we can convert the scores to percentages of the max score possible. That way people aren’t penalized for having answered one less question than their peers.

Generating Pairings

So it turns out that pairing people together is the same problem as the maximum matching problem1. We want to pair people together, but we want everyone to get a good matching. For example, consider this pairing:

[Jessie] -[12]- [Patrick]
  |                 |
 [8]               [9]
  |                 |
[Robin] --[3]-- [Cameron]

An approach that just chose the highest pairing would pair Jessie & Patrick, at the expense of Robin & Cameron. A better overall pairing would be Jessie & Robin, and Patrick & Cameron.

Thankfully, we don’t need to solve this problem. We can just use the max_weight_matching algorithm in networkx2, which avoids the trap and gives the ideal answer overall.

Conclusion

In the future, I would love to poll people who are friends vs people who have stopped hanging out. After running it through some machine learning, the script could learn to assign better pair scores to each user over time. It could also learn if certain questions give better information than others.

Repo Link

The code is set up to accept the copy-pasted poll results from GroupMe.

When you post your polls, make sure you make the responses visible so you can tie each answer to a person :)