a = [200, 2 , 20 , 1 , 9 , 000, 000, 1 ]
b = [6 , 50 , 10 , 2 , 20 , 000, 4 , 6 ]
c = [12 , 6 , 300, 5 , 5 , 000, 000, 11 ]
d = [1 , 1 , 3 , 50 , 9 , 000, 000, 18 ]
e = [4 , 2 , 6 , 2 , 300, 7 , 1 , 22 ]
f = [000, 1 , 2 , 1 , 30 , 80 , 2 , 9 ]
g = [1 , 5 , 3 , 2 , 10 , 10 , 24 , 4 ]
h = [1 , 3 , 15 , 5 , 30 , 5 , 2 , 300]
Confusion_Matrix = [
a, b, c, d, e, f, g, h
]
import copy
def OA(Confusion_Matrix):
CM = Confusion_Matrix
xia_list = []
for i in range(len(CM)):
xia_list.append(sum(CM[i]))
xia = sum(xia_list)
shang_list = []
for i in range(len(CM)):
shang_list.append(CM[i][i])
shang = sum(shang_list)
OA = shang / xia
return OA
def KP(Overall_Accuracy, Confusion_Matrix):
CM = Confusion_Matrix
p0 = Overall_Accuracy
pe_xia_list = []
for i in range(len(CM)):
pe_xia_list.append(sum(CM[i]))
pe_xia = sum(pe_xia_list) ** 2
CMT = list(map(list, zip(*CM))) # 转置
pe_shang_list = []
for i in range(len(CM)):
pe_shang_list.append(sum(CM[i]) * sum(CMT[i]))
pe_shang = sum(pe_shang_list)
pe = pe_shang / pe_xia
KP = (p0 - pe) / (1 - pe)
return KP
def CE(Class, Confusion_Matrix):
CM = Confusion_Matrix
Class_list = CM[Class]
Commission_list = copy.deepcopy(Class_list)
del Commission_list[Class]
CE = sum(Commission_list) / sum(Class_list)
return CE
def OE(Class, Confusion_Matrix):
CM = Confusion_Matrix
CMT = list(map(list, zip(*CM))) # 转置
Class_list = CMT[Class]
Ommission_list = copy.deepcopy(Class_list)
del Ommission_list[Class]
OE = sum(Ommission_list) / sum(Class_list)
return OE
# 总体精度
Overall_Accuracy = OA(Confusion_Matrix)
print("总体精度:",Overall_Accuracy)
# 卡帕系数
Kappa = KP(Overall_Accuracy, Confusion_Matrix)
print("卡帕系数:",Kappa)
# 针对某一类
# 错分误差
Commission_Error = CE(0, Confusion_Matrix) # 第一个参数位写第几类,0是第一类,1是第二类
print("错分误差:",Commission_Error)
# 漏分误差
Omission_Error = OE(0, Confusion_Matrix) # 第一个参数位写第几类,0是第一类,1是第二类
print("漏分误差:",Omission_Error)
# 用户精度
Users_Accuracy = 1 - Commission_Error
print("用户精度:",Users_Accuracy)
# 生产者精度/制图精度
Producers_Accuracy = 1 - Omission_Error
print("生产者精度/制图精度:",Producers_Accuracy)
用户精度 (User’s Accuracy):
假设分类结果的某类别的用户精度为 80%,则用户拿到分类结果后,10个像元中有8个是对的,2个是错的;
生产者精度 (Producer’s Accuracy):
假设分类结果的某类别的生产者精度为 80%,那么如果该类别有10个像素的话,则有2个没有分到该类别(丢失了)。
文章来源:https://www.toymoban.com/news/detail-846558.html
有一个很好的例子:
图像分类中混淆矩阵精度验证法中的几个指标说明 - GIS知乎-新一代GIS问答社区 (geoscene.cn)文章来源地址https://www.toymoban.com/news/detail-846558.html
到了这里,关于混淆矩阵计算遥感分类精度(总体精度、Kappa系数、用户精度、生产者精度等)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!