mirror of
https://github.com/Doctorado-ML/Stree_datasets.git
synced 2025-08-15 15:36:01 +00:00
Update oc1 accuracy and time (mean & std)
This commit is contained in:
@@ -2,13 +2,30 @@ import os
|
||||
from datetime import datetime
|
||||
from experimentation.Sets import Datasets
|
||||
from experimentation.Database import MySQL
|
||||
from statistics import mean, stdev
|
||||
|
||||
|
||||
def store_result(database, dataset, accuracy, time_spent):
|
||||
attributes = [
|
||||
"date",
|
||||
"time",
|
||||
"type",
|
||||
"accuracy",
|
||||
"accuracy_std",
|
||||
"dataset",
|
||||
"classifier",
|
||||
"norm",
|
||||
"stand",
|
||||
"time_spent",
|
||||
"time_spent_std",
|
||||
"parameters",
|
||||
]
|
||||
command_insert = (
|
||||
"replace into results (date, time, type, accuracy, "
|
||||
"dataset, classifier, norm, stand, time_spent, parameters) values (%s,"
|
||||
" %s, %s, %s, %s, %s, %s, %s, %s, %s)"
|
||||
"insert into results ("
|
||||
+ ",".join(attributes)
|
||||
+ ") values("
|
||||
+ ("%s," * len(attributes))[:-1]
|
||||
+ ")"
|
||||
)
|
||||
now = datetime.now()
|
||||
date = now.strftime("%Y-%m-%d")
|
||||
@@ -17,12 +34,14 @@ def store_result(database, dataset, accuracy, time_spent):
|
||||
date,
|
||||
time,
|
||||
"crossval",
|
||||
accuracy,
|
||||
mean(accuracy),
|
||||
stdev(accuracy),
|
||||
dataset,
|
||||
"oc1",
|
||||
True,
|
||||
False,
|
||||
time_spent,
|
||||
mean(time_spent),
|
||||
stdev(time_spent),
|
||||
str({"random_state": 1}),
|
||||
)
|
||||
cursor = database.cursor()
|
||||
@@ -34,11 +53,15 @@ def get_result(name):
|
||||
filename = os.path.join("data", "oc1output", f"{name}.txt")
|
||||
result_file = open(filename, "r")
|
||||
lines = result_file.readlines()
|
||||
accuracy = float(lines[-2].split("= ")[1].split("#")[0]) / 100
|
||||
time = float(lines[-1])
|
||||
print(f"accuracy=[{accuracy}] time=[{time}]")
|
||||
result_file.close()
|
||||
return accuracy, time
|
||||
data = lines[-6:-1]
|
||||
time_spent = []
|
||||
accuracy = []
|
||||
for line in data:
|
||||
acc, time_s = line.split("***")[2:4]
|
||||
accuracy.append(float(acc))
|
||||
time_spent.append(float(time_s))
|
||||
return accuracy, time_spent
|
||||
|
||||
|
||||
dbh = MySQL()
|
||||
@@ -47,5 +70,11 @@ dt = Datasets(False, False, "tanveer")
|
||||
for dataset in dt:
|
||||
print(f"Processing {dataset[0]:30s}", end=" ")
|
||||
accuracy, time_spent = get_result(dataset[0])
|
||||
accuracy_mean, accuracy_std = mean(accuracy), stdev(accuracy)
|
||||
time_mean, time_std = mean(time_spent), stdev(time_spent)
|
||||
print(
|
||||
f"accuracy=[{accuracy_mean:05.3f}\u00B1{accuracy_std:05.3f}] "
|
||||
f"time=[{time_mean:05.3f}\u00B1{time_std:05.3f}]"
|
||||
)
|
||||
store_result(database, dataset[0], accuracy, time_spent)
|
||||
dbh.close()
|
||||
|
Reference in New Issue
Block a user