I used Machine Learning to Organize Dating Profiles | Marco Santos | Towards Data Science

After swiping endlessly through hundreds of dating profiles and not matching with a single one, one might start to wonder how these profiles are even showing up on their phone. All of these profiles are not the type they are looking for. They have been swiping for hours or even days and have not found any success. They might start asking:
“Why are these dating apps showing me people that I know I won’t match with?”
The dating algorithms used to show dating profiles might seem broken to plenty of people who are tired of swiping left when they should be matching. Every dating site and app probably utilize their own secret dating algorithm meant to optimize matches among their users. But sometimes it feels like it is just showing random users to one another with no explanation. How can we learn more about and also combat this issue? By using a little something called Machine Learning.
We could use machine learning to expedite the matchmaking process among users within dating apps. With machine learning, profiles can potentially be clustered together with other similar profiles. This will reduce the number of profiles that are not compatible with one another. From these clusters, users can find other users more like them. The machine learning clustering process has been covered in the article below:
towardsdatascience.com
Take a moment to read it if you want to know how we were able to achieve clustered groups of dating profiles.
Sign up for a Medium Membership here to gain unlimited access and support content like mine! With your support I earn a small portion of the membership fee. Thanks!
Using the data from the article above, we were able to successfully obtain the clustered dating profiles in a convenient Pandas DataFrame.
In this DataFrame we have one profile for each row and at the end, we can see the clustered group they belong to after applying Hierarchical Agglomerative Clustering to the dataset. Each profile belongs to a specific cluster number or group. However, these groups could use some refinement.
With the clustered profile data, we can further refine the results by sorting each profile based on how similar they are to one another. This process might be quicker and easier than you may think.
Let’s break the code down to simple steps starting with random, which is used throughout the code simply to choose which cluster and user to select. This is done so that our code can be applicable to any user from the dataset. Once we have our randomly selected cluster, we can narrow down the entire dataset to just include those rows with the selected cluster.
With our selected clustered group narrowed down, the next step involves vectorizing the bios in that group. The vectorizer we are using for this is the same one we used to create our initial clustered DataFrame — CountVectorizer(). (The vectorizer variable was instantiated previously when we vectorized the first dataset, which can be observed in the article above).
# Fitting the vectorizer to the Bioscluster_x = vectorizer.fit_transform(group['Bios'])# Creating a new DF that contains the vectorized wordscluster_v = pd.DataFrame(cluster_x.toarray(),                          index=group.index,                            columns=vectorizer.get_feature_names())
By vectorizing the Bios, we are creating a binary matrix that includes the words in each bio.
Afterwards, we will join this vectorized DataFrame to the selected group/cluster DataFrame.
# Joining the vector DF and the original DFgroup = group.join(cluster_v)# Dropping the Bios because it is no longer neededgroup.drop('Bios', axis=1, inplace=True)
After joining the two DataFrame together, we are left with vectorized bios and the categorical columns:
From here we can begin to find users that are most similar with one another.
Once we have created a DataFrame filled binary values and numbers, we can begin to find the correlations among the dating profiles. Every dating profile has a unique index number from which we can use for reference.
In the beginning, we had a total of 6600 dating profiles. After clustering and narrowing down the DataFrame to the selected cluster, the number of dating profiles can range from 100 to 1000. Throughout the entire process, the index number for the dating profiles remained the same. Now, we can use each index number for reference to every dating profile.
With each index number representing a unique dating profile, we can find similar or correlated users to each profile. This is achieved by running one line of code to create a correlation matrix.
corr_group = group.T.corr()
The first thing we needed to do was to transpose the DataFrame in order to have the columns and indices switch. This is done so that the correlation method we use applied to the indices and not the columns. Once we have transposed the DF we can apply the .corr() method which will create a correlation matrix among the indices.
This correlation matrix contains numerical values which were calculated using the Pearson Correlation method. Values closer to 1 are positively correlated with each other which is why you will see 1.0000 for indices correlated with their own index.
From here you can see where we are going when it comes to finding similar users when using this correlation matrix.
Now that we have a correlation matrix containing correlation scores for every index/dating profile, we can begin sorting the profiles based on their similarity.
random_user = random.choice(corr_group.index)print("Top 10 most similar users to User #", random_user, '\n')top_10_sim = corr_group[[random_user]].sort_values(by=             [random_user],axis=0, ascending=False)[1:11]print(top_10_sim)print("\nThe most similar user to User #", random_user, "is User #", top_10_sim.index[0])
The first line in the code block above selects a random dating profile or user from the correlation matrix. From there, we can select the column with the selected user and sort the users within the column so that it will only return the top 10 most correlated users (excluding the selected index itself).
Success! — When we run the code above, we are given a list of users sorted by their respective correlation scores. We can see the top 10 most similar users to our randomly selected user. This can be run again with another cluster group and another profile or user.
If this were a dating app, the user would be able to see the top 10 most similar users to themselves. This would hopefully reduce swiping time, frustration, and increase matches among the users of our hypothetical dating app. The hypothetical dating app’s algorithm would implement unsupervised machine learning clustering to create groups of dating profiles. Within those groups, the algorithm would sort the profiles based on their correlation score. Finally, it would be able to present users with dating profiles most similar to themselves.
A potential next step would be trying to incorporate new data to our machine learning matchmaker. Maybe have a new user input their own custom data and see how they would match with these fake dating profiles.