|
本帖最后由 chenwq 于 2013-4-15 13:13 编辑
1、Platform required
This is tested under the scipy 0.9 and numpy 2.0, but they should also work with a reasonably new version.
2、Parameters
Each metric requires only the following two parameters:
predicted_label, labels predicted by the some clustering algorithm:
predicted_label = array([1,1,6,1,1,1,2,2,2,2,2,2,3,3,3,3,3])
group_truth, labels given by the train data:
group_truth = array([2,5,1,1,3,1,2,2,2,2,2,2,3,3,3,3,3])
3、Test cases:- if __name__=="__main__":
- #Example from http://nlp.stanford.edu/IR-book
-
- predicted_label = array([1,1,6,1,1,1,2,2,2,2,2,2,3,3,3,3,3])
- group_truth = array([2,5,1,1,3,1,2,2,2,2,2,2,3,3,3,3,3])
- print "test case 1:"
- print "group_truth:"
- print group_truth
- print "predicted_label:"
- print predicted_label
-
- print "F-score: "
- print F(predicted_label, group_truth)[0]
- print "\nAdjusted purity:"
- print APP(predicted_label, group_truth)
- print "\nMutual Information:"
- print mi(predicted_label, group_truth)
- print "\nNormalized Mutual Information:"
- print nmi(predicted_label, group_truth)
- print "\nv measure score:"
- print V(predicted_label, group_truth)
- print "\nAdjusted Rand Index:"
- print rand(predicted_label, group_truth)
-
- predicted_label = array([1, 2, 2, 3, 3, 2, 1])
- group_truth = array([1, 2, 2, 3, 3, 2, 1])
- print "-" * 50
- print "test case 2:"
- print "group truth:"
- print group_truth
- print "predicted_label:"
- print predicted_label
- print "F-score: "
- print F(predicted_label, group_truth)[0]
- print "\nAdjusted purity:"
- print APP(predicted_label, group_truth)
- print "\nMutual Information:"
- print mi(predicted_label, group_truth)
- print "\nNormalized Mutual Information:"
- print nmi(predicted_label, group_truth)
- print "\nv measure score:"
- print V(predicted_label, group_truth)
- print "\nAdjusted Rand Index:"
- print rand(predicted_label, group_truth)
复制代码
4、References
Clustering evaluation for Numpy and Scipy
5、Source code: |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|