The Fowlkes-Mallows Score is an evaluation metric to evaluate the similarity among clusterings obtained after applying different clustering algorithms. Although technically it is used to quantify the similarity between two clusterings, it is typically used to evaluate the clustering performance of a clustering algorithm by assuming the second clustering to be the ground-truth ie the observed data and assuming it to be the perfect clustering.
Let there be N number of data points in the data and k number of clusters in clusterings A1 and A2. Then the matrix M is built such that
where determines the number of data points that lie in the ith cluster in clustering A1 and the jth cluster in clustering A2.
The Fowlkes-Mallows index for the parameter k is given by
The following terms are defined in the context of the above-defined symbolic conventions:-
- True Positive(TP): The number of pair of data points which are in the same cluster in A1 and in A2.
- False Positive(FP): The number of pair of data points which are in the same cluster in A1 but not in A2.
- False Negative(FN): The number of pair of data points which are not in the same cluster in A1 but are in the same cluster in A2.
- True Negative(TN): The number of pair of data points which are not in the same cluster in neither A1 nor A2.
Thus the Fowlkes-Mallows Index can also be expressed as:-
Rewritting the above expression
Thus the Fowlkes-Mallows Index is the geometric mean of the precision and the recall.
- Assumption-Less: This evaluation metric does not assume any property about the cluster structure thus proving to be significantly advantageous than traditional evaluation methods.
- Ground-Truth Rules: One disadvantage to this evaluation metric is that it requires the knowledge of the ground-truth rules(Class Labels) to evaluate a clustering algorithm.
The below steps will demonstrate how to evaluate the Fowlkes-Mallows Index for a clustering algorithm by using Sklearn. The dataset for the below steps is the Credit Card Fraud Detection dataset which can be downloaded from Kaggle.
Step 1: Importing the required libraries
Step 2: Loading and Cleaning the data
Step 3: Building different Clustering and evaluating individual performances
The following step lines of code involve Building different K-Means Clustering models each having different values for the parameter n_clusters and then evaluating each individual performance using the Fowlkes-Mallows Score.
a) n_clusters = 2
b) n_clusters = 3
c) n_clusters = 4
d) n_clusters = 5
e) n_clusters = 6
Step 4: Visualizing and Comparing the results
Thus, quite obviously, the clustering with the number of clusters = 2 is the most similar to the observed data because the data has only two class labels.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- NLP | How to score words with Execnet and Redis
- ML | Models Score and Error
- Python | Extract Score list of String
- Z score for Outlier Detection - Python
- Python - Coefficient of Determination-R2 score
- Python PRAW - Getting the score of a comment in Reddit
- Calculating the completeness score using sklearn in Python
- Grouped Boxplots in Python with Seaborn
- Facebook Transcoder
- Bulk Posting on Facebook Pages using Selenium
- Serializing JSON data in Python
- Python - Difference Between json.load() and json.loads()
- Scrape Google Search Results using Python BeautifulSoup
- How to remove empty tags using BeautifulSoup in Python?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : shubham_singh