Package: bcubed
python-bcubedSimple extended BCubed implementation in Python for (non-)overlapping clustering evaluation.More information on BCubed and details of the algorithm can be found in the following publication:Amigó, Enrique, et al.: A comparison of Extrinsic Clustering Evaluation Metrics based on Formal Constraints. In: Information Retrieval 12.4 (2009): 461-486.InstallationYou can simply usepip(or any similar package manager) for installation:pip install bcubedor, if you prefer a local user installation:pip install --user bcubedUsageTo evaluate any clustering output you will needground-truth data(also called gold-standard data). We call this theldict. The ground-truth is represented in a dictionary where the keys are items in the gold-standard and the values are sets of annotated categories for those items. For example:ldict={"item1":set(["gray","black"]),"item2":set(["gray","black"]),"item3":set(["gray"]),"item4":set(["black"]),"item5":set(["black"]),"item6":set(["dashed"]),"item7":set(["dashed"]),}In the above example,item1is assigned two categories in the ground-truth:grayandblack. For the case ofitem6anditem7, both are assigned the single annotationdashed. This representation supports modelling overlapping and non-overlapping ground-truth data.Theclustering outputto be evaluated is called thecdictand is also represented as a dictionary in the same way as theldict. In this case, the keys are items in the clustering output and the values are the sets of assigned clusters for those items. For example:cdict={"item1":set(["A","B"]),"item2":set(["A","B"]),"item3":set(["A"]),"item4":set(["B"]),"item5":set(["B"]),"item6":set(["C"]),"item7":set(["C"]),}Please note that the clusters names (or IDs)do not needto be the same as in the ground-truth data because the algorithm only considers the groupings, it does not try to match the names of clusters to the ground-truth categories.Once you have defined theldict(ground-truth data) and thecdict(clustering output to evaluate), you can simply do the following to obtain the extended BCubed precision and recall metric values:importbcubedprecision=bcubed.precision(cdict,ldict)recall=bcubed.recall(cdict,ldict)fscore=bcubed.fscore(precision,recall)There is also included anF-score(also called F-measure) function for your convenience. This function accepts non-standard values for the beta parameter if you need, as follows:fscore=bcubed.fscore(precision,recall,beta=2.0)# weights recall higherfscore=bcubed.fscore(precision,recall,beta=0.5)# weights precision higherA complete example can be found in the includedexample.pyfile, where the examples of the source publication are used.LicenseThis software is under theApache License 2.0.Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.