File size: 1,032 Bytes
22c4a51
 
 
 
 
49a9586
22c4a51
 
 
49a9586
 
22c4a51
 
 
 
49a9586
22c4a51
 
 
 
 
49a9586
 
 
 
 
 
 
22c4a51
49a9586
22c4a51
 
 
49a9586
 
 
 
 
 
 
 
22c4a51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# https://www.cnblogs.com/yexionglin/p/11432180.html

import seaborn as sns
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt
from colorama import Fore,Back,Style


def draw(y_true, y_pred):
	min_len = min( len(y_true), len(y_pred) )
	
	sns.set()
	f, ax=plt.subplots()
	# y_true = [0,0,1,2,1,2,0,2,2,0,1,1]
	# y_pred = [1,0,1,2,1,0,0,2,2,0,1,1]
	cm = confusion_matrix(y_true, y_pred, labels=[-1] * min_len)
	print(cm) #打印出ζ₯ηœ‹ηœ‹
	sns.heatmap(cm, annot=True, ax=ax) #η”»ηƒ­εŠ›ε›Ύ

def draw2(y_true, y_pred):
	min_len = min( len(y_true), len(y_pred) )
	
	print('\t', end='')
	for i in range(min_len):
		y_true_format = str(y_true[i])[:3]
		print('%s\t' % y_true_format, end='')
	print('')

	for i in range(min_len):
		print(Fore.RESET + '%s\t' % str(i + 1), end='')
		for j in range(i):
			print('\t', end='')

		# print with color
		if y_pred[i] > 0.5:
			print(Fore.GREEN + str(y_pred[i]))
		else:
			print(Fore.RED + str(y_pred[i]))

if __name__ == '__main__':
	draw2( [1.0] * 13, [0.5] * 13 )