<filename>display.py
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

def Disp(y1, y2, id):
	plt.subplot(7, 10, id)
	x = np.arange(len(y1))
	plt.plot(x, y1, 'r', label = 'Train')
	plt.plot(x, y2, 'b', label = 'Test')
	plt.xlabel('Epoch')
	plt.ylabel('Loss')
	plt.title('Sample%d' % id)
	plt.legend(ncol = 2)
	plt.savefig('learning_curve.jpg')

def Disp(y1, y2):
	x = np.arange(len(y1))
	plt.plot(x, y1, 'r', label = 'Train')
	plt.plot(x, y2, 'b', label = 'Test')
	plt.xlabel('Epoch')
	plt.ylabel('Acc')
	plt.legend(ncol = 2)
	plt.savefig('learning_curve2.jpg')

def Eval(y, y_output):
	Acc = ((y[y_output > 0.5] == 1).sum() + (y[y_output < 0.5] == 0).sum()) / len(y)
	num_P = max(1, (y_output > 0.5).sum())
	num_N = max(1, (y_output < 0.5).sum())
	TP = (y[y_output > 0.5] == 1).sum() / num_P
	TN = (y[y_output < 0.5] == 0).sum() / num_N
	FP = (y[y_output > 0.5] == 0).sum() / num_P
	FN = (y[y_output < 0.5] == 1).sum() / num_N
	P = TP / (TP + FP)
	R = TP / (TP + FN)
	mF1 = 2 * P * R / (P + R)
	G_mean = np.sqrt(TP / (TP + FN) * TN / (TN + FP))
	return round(TP.item(), 4), round(TN.item(), 4), \
		round(FP.item(), 4), round(FN.item(), 4), \
		round(P.item(), 4), round(R.item(), 4), \
		round(mF1.item(), 4), round(Acc.item(), 4), round(G_mean.item(), 4)
<filename>display.py
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

def Disp(y1, y2, id):
	plt.subplot(7, 10, id)
	x = np.arange(len(y1))
	plt.plot(x, y1, 'r', label = 'Train')
	plt.plot(x, y2, 'b', label = 'Test')
	plt.xlabel('Epoch')
	plt.ylabel('Loss')
	plt.title('Sample%d' % id)
	plt.legend(ncol = 2)
	plt.savefig('learning_curve.jpg')

def Disp(y1, y2):
	x = np.arange(len(y1))
	plt.plot(x, y1, 'r', label = 'Train')
	plt.plot(x, y2, 'b', label = 'Test')
	plt.xlabel('Epoch')
	plt.ylabel('Acc')
	plt.legend(ncol = 2)
	plt.savefig('learning_curve2.jpg')

def Eval(y, y_output):
	Acc = ((y[y_output > 0.5] == 1).sum() + (y[y_output < 0.5] == 0).sum()) / len(y)
	num_P = max(1, (y_output > 0.5).sum())
	num_N = max(1, (y_output < 0.5).sum())
	TP = (y[y_output > 0.5] == 1).sum() / num_P
	TN = (y[y_output < 0.5] == 0).sum() / num_N
	FP = (y[y_output > 0.5] == 0).sum() / num_P
	FN = (y[y_output < 0.5] == 1).sum() / num_N
	P = TP / (TP + FP)
	R = TP / (TP + FN)
	mF1 = 2 * P * R / (P + R)
	G_mean = np.sqrt(TP / (TP + FN) * TN / (TN + FP))
	return round(TP.item(), 4), round(TN.item(), 4), \
		round(FP.item(), 4), round(FN.item(), 4), \
		round(P.item(), 4), round(R.item(), 4), \
		round(mF1.item(), 4), round(Acc.item(), 4), round(G_mean.item(), 4)