1. 程式人生 > >模型評估

模型評估

都是 表示 measure __name__ color 結果 image 單個 指數

 1 # -*- coding: utf-8 -*-
 2 """
 3 Created on Thu Sep 27 16:24:29 2018
 4     模型及預測準確度評估
 5 @author: zhen
 6 """
 7 
 8 from sklearn import metrics
 9 
10 if __name__ == "__main__":
11     
12     # 同一性homogeneity:每個群集只包含單個類的成員。 
13     # 完整性completeness:給定類的所有成員都分配給同一個群集。
14     # 調和平均V-measure
15
y = [0, 0, 0, 1, 1, 1] 16 y_hat = [0, 0, 1, 1, 2, 2] 17 h = metrics.homogeneity_score(y, y_hat) 18 c = metrics.completeness_score(y, y_hat) 19 20 v2 = 2 * c * h / (c + h) 21 v = metrics.v_measure_score(y, y_hat) 22 print(u同一性(Homogeneity):, h) 23 print(u完整性(Completeness):
, c) 24 print(uV_Measure:, v2, v) 25 26 y = [0, 0, 0, 1, 1, 1] 27 y_hat = [0, 0, 1, 3, 3, 3] 28 h = metrics.homogeneity_score(y, y_hat) 29 c = metrics.completeness_score(y, y_hat) 30 v = metrics.v_measure_score(y, y_hat) 31 32 print(u同一性(Homogeneity):, h) 33 print
(u完整性(Completeness):, c) 34 print(uV_Measure:, v) 35 36 # 允許不同值 37 y = [0, 0, 0, 1, 1, 1] 38 y_hat = [1, 1, 1, 0, 0, 0] 39 h = metrics.homogeneity_score(y, y_hat) 40 c = metrics.completeness_score(y, y_hat) 41 v = metrics.v_measure_score(y, y_hat) 42 43 print(u同一性(Homogeneity):, h) 44 print(u完整性(Completeness):, c) 45 print(uV_Measure:, v) 46 47 # 蘭德指數 48 # ARI值的範圍是[-1,1],負的結果都是較差的,越接近-1表示聚類越差, 49 # 正的結果都是較好的,1是最佳結果,越接近1表示聚類結果越好。 50 y = [0, 0, 1, 1] 51 y_hat = [0, 1, 0, 1] 52 ari = metrics.adjusted_rand_score(y, y_hat) 53 print("蘭德指數:", ari) 54 55 y = [0, 0, 0, 1, 1, 1] 56 y_hat = [0, 0, 1, 1, 2, 2] 57 ari = metrics.adjusted_rand_score(y, y_hat) 58 print("蘭德指數:", ari) 59

結果:

技術分享圖片

模型評估