64 lines
3.0 KiB
Python
64 lines
3.0 KiB
Python
import numpy as np
|
|
import pandas as pd
|
|
from decimal import Decimal, ROUND_HALF_UP
|
|
|
|
class Calculate():
|
|
def __init__(self) -> None:
|
|
self.Loss, self.Accuracy, self.Precision, self.Recall, self.F1, self.AUC = 0, 0, 0, 0, 0, 0
|
|
self.Loss_Record, self.Accuracy_Record, self.Precision_Record, self.Recall_Record, self.F1_Record = [], [], [], [], []
|
|
self.History = []
|
|
pass
|
|
|
|
def Append_numbers(self, Loss, Accuracy, Precision, Recall, F1):
|
|
self.Loss_Record.append(Loss)
|
|
self.Accuracy_Record.append(Accuracy)
|
|
self.Precision_Record.append(Precision)
|
|
self.Recall_Record.append(Recall)
|
|
self.F1_Record.append(F1)
|
|
pass
|
|
|
|
def Construction_To_DataFrame(self, Loss, Accuracy, Precision, Recall, F1):
|
|
DataFrame = pd.DataFrame(
|
|
{
|
|
"loss" : "{:.2f}".format(Loss),
|
|
"precision" : "{:.2f}".format(Precision),
|
|
"recall" : "{:.2f}".format(Recall),
|
|
"accuracy" : "{:.2f}".format(Accuracy),
|
|
"f1" : "{:.2f}".format(F1),
|
|
}, index = [0]
|
|
)
|
|
self.History.append(DataFrame)
|
|
return DataFrame
|
|
|
|
def Calculate_Mean(self):
|
|
Loss_Mean = np.mean(self.Loss_Record)
|
|
Accuracy_Mean = np.mean(self.Accuracy_Record)
|
|
Precision_Mean = np.mean(self.Precision_Record)
|
|
Recall_Mean = np.mean(self.Recall_Record)
|
|
F1_Mean = np.mean(self.F1_Record)
|
|
|
|
Mean_DataFram = self.Construction_To_DataFrame(Loss_Mean, Accuracy_Mean * 100, Precision_Mean * 100, Recall_Mean * 100, F1_Mean * 100)
|
|
|
|
return Mean_DataFram
|
|
|
|
def Calculate_Std(self):
|
|
Loss_Std = Decimal(str(np.std(self.Loss_Record))).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
|
Accuracy_Std = Decimal(str(np.std(self.Accuracy_Record))).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
|
Precision_Std = Decimal(str(np.std(self.Precision_Record))).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
|
Recall_Std = Decimal(str(np.std(self.Recall_Record))).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
|
F1_Std = Decimal(str(np.std(self.F1_Record))).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
|
|
|
Std_DataFram = self.Construction_To_DataFrame(Loss_Std, Accuracy_Std, Precision_Std, Recall_Std, F1_Std)
|
|
return Std_DataFram
|
|
|
|
def Output_Style(self):
|
|
Result = pd.DataFrame(
|
|
{
|
|
"loss" : "{}±{}".format(self.History[0]["loss"][0], self.History[1]["loss"][0]),
|
|
"precision" : "{}%±{}".format(self.History[0]["precision"][0], self.History[1]["precision"][0]),
|
|
"recall" : "{}%±{}".format(self.History[0]["recall"][0], self.History[1]["recall"][0]),
|
|
"accuracy" : "{}%±{}".format(self.History[0]["accuracy"][0], self.History[1]["accuracy"][0]),
|
|
"f1" : "{}%±{}".format(self.History[0]["f1"][0], self.History[1]["f1"][0]),
|
|
}, index = [0]
|
|
)
|
|
return Result |