-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult_util.py
48 lines (34 loc) · 1.6 KB
/
result_util.py
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
44
45
46
47
48
import pandas as pd
def store_classification_results(algorithm_name: str, f1_train: float, f1_test: float, model_path: str,
results_file_path="data/results.csv"):
"""Store the results of a classification process into a CSV file."""
results_df = None
try:
results_df = pd.read_csv(results_file_path)
except FileNotFoundError:
pass
# if there is no results_df, create one
if results_df is None:
results_df = pd.DataFrame(columns=['algorithm', 'f1_train', 'f1_test', 'model_path'])
# check if there is already a result entry for this algorithm
if algorithm_name in results_df['algorithm'].values:
results_df.loc[results_df['algorithm'] == algorithm_name, ['f1_train', 'f1_test', 'model_path']] = [f1_train, f1_test, model_path]
else:
results_df = results_df.append({
'algorithm': algorithm_name,
'f1_train': f1_train,
'f1_test': f1_test,
'model_path': model_path
}, ignore_index=True)
results_df.to_csv(results_file_path, index=False)
def get_classification_results(results_file_path="data/results.csv"):
"""Retrieve the file with the classification results."""
try:
return pd.read_csv(results_file_path)
except FileNotFoundError:
pass
def print_classification_results(results_file_path="data/results.csv"):
"""Print the classification results from the file containing this information."""
results_df = get_classification_results(results_file_path)
if results_df is not None:
print(results_df.to_string())