Tin Theethawat Savastham commited on
Commit ·
0887820
1
Parent(s): 4ec8622
♻️ Strcuture code
Browse files- .env.example +2 -0
- .gitignore +3 -0
- .vscode/settings.json +11 -0
- Readme.md +4 -0
- functions/{extractor → data_extractor}/.gitignore +0 -0
- functions/{extractor → data_extractor}/adjust_data.py +0 -0
- functions/{extractor → data_extractor}/emanufac_tdabc_extractor_class.py +0 -0
- functions/{extractor → data_extractor}/shaker_augmentation.py +0 -0
- functions/experiment_script/batch_experiment_script.py +133 -0
- functions/experiment_script/get_data_script.py +98 -0
- functions/experiment_script/plotting_summarize.py +1284 -0
- functions/experiment_script/random_number_list.csv +125 -0
- functions/experiment_script/rsg_breakpoint_experiment.py +457 -0
- functions/experiment_script/run_all_experiment.py +21 -0
- functions/experiment_script/summarize_error.py +165 -0
.env.example
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
EMANUFAC_API_URL =
|
| 2 |
+
EMANUFAC_API_KEY =
|
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv/
|
| 2 |
+
.env
|
| 3 |
+
*.zip
|
.vscode/settings.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"python.analysis.extraPaths": [
|
| 3 |
+
],
|
| 4 |
+
"git.autofetch": "all",
|
| 5 |
+
"git.blame.editorDecoration.enabled": true,
|
| 6 |
+
"git.enabled": true,
|
| 7 |
+
"dataWrangler.columnInsights.displayOnOpen": false,
|
| 8 |
+
"flake8.args": [
|
| 9 |
+
"--ignore=E501"
|
| 10 |
+
]
|
| 11 |
+
}
|
Readme.md
CHANGED
|
@@ -16,4 +16,8 @@ Install all requirements
|
|
| 16 |
pip install -r requirement.txt
|
| 17 |
```
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
© 2024, Prince of Songkla University under Inteligent Automation Engineering Center
|
|
|
|
| 16 |
pip install -r requirement.txt
|
| 17 |
```
|
| 18 |
|
| 19 |
+
## Repository Structure
|
| 20 |
+
|
| 21 |
+
The Model is structure into folder model, functions. The model and functions that related to **model** is located in folder model and the **function** contain the function to do the experiment.
|
| 22 |
+
|
| 23 |
© 2024, Prince of Songkla University under Inteligent Automation Engineering Center
|
functions/{extractor → data_extractor}/.gitignore
RENAMED
|
File without changes
|
functions/{extractor → data_extractor}/adjust_data.py
RENAMED
|
File without changes
|
functions/{extractor → data_extractor}/emanufac_tdabc_extractor_class.py
RENAMED
|
File without changes
|
functions/{extractor → data_extractor}/shaker_augmentation.py
RENAMED
|
File without changes
|
functions/experiment_script/batch_experiment_script.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib
|
| 2 |
+
import sys
|
| 3 |
+
import getopt
|
| 4 |
+
import os
|
| 5 |
+
import rsg_breakpoint_experiment as rbe
|
| 6 |
+
importlib.reload(rbe)
|
| 7 |
+
|
| 8 |
+
learning_rate = [0.005, 0.01, 0.05, 0.1, 0.5]
|
| 9 |
+
patience_round = 50
|
| 10 |
+
outlier_index = 1.5
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def run_batch_experiment(model_learning_rate,
|
| 14 |
+
augmentation=False,
|
| 15 |
+
remove_outlier_qtr=False,
|
| 16 |
+
round_number=1,
|
| 17 |
+
iteration=200,
|
| 18 |
+
use_model_weight=True,
|
| 19 |
+
dataset_name="simple",
|
| 20 |
+
experiment_version=2,
|
| 21 |
+
use_early_stopping=False
|
| 22 |
+
):
|
| 23 |
+
|
| 24 |
+
dataset_directory = f'data/{dataset_name}'
|
| 25 |
+
output_group_directory = f'result/{dataset_name}'
|
| 26 |
+
os.makedirs(output_group_directory, exist_ok=True)
|
| 27 |
+
output_directory = f'{output_group_directory}/{dataset_name}_{experiment_version}'
|
| 28 |
+
output_directory += f"_{model_learning_rate}"
|
| 29 |
+
if remove_outlier_qtr:
|
| 30 |
+
output_directory += "_remove_outlier"
|
| 31 |
+
if augmentation:
|
| 32 |
+
output_directory += "_augmented"
|
| 33 |
+
if use_early_stopping:
|
| 34 |
+
output_directory += "_early_stopping"
|
| 35 |
+
|
| 36 |
+
try:
|
| 37 |
+
rbe.run_experiment(data_directory=dataset_directory, epoch=iteration,
|
| 38 |
+
learning_rate_list=learning_rate, round_number=round_number,
|
| 39 |
+
folder_name=output_directory, breakpoint=iteration / 2,
|
| 40 |
+
early_stopping=use_early_stopping, patience_round=patience_round,
|
| 41 |
+
augmentation=augmentation,
|
| 42 |
+
outlier_index=outlier_index,
|
| 43 |
+
remove_outlier_qtr=remove_outlier_qtr,
|
| 44 |
+
use_model_weight=use_model_weight,
|
| 45 |
+
model_learning_rate=model_learning_rate)
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print("Error in Experiment", e)
|
| 48 |
+
pass
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def run_in_many_learning_rate(dataset_name="simple", experiment_version=2, round_number=1, iteration=200):
|
| 52 |
+
model_learning_rate_list = [0.0000001, 0.00000001]
|
| 53 |
+
early_stopping_list = [False, True]
|
| 54 |
+
for model_learning_rate in model_learning_rate_list:
|
| 55 |
+
for early_stopping in early_stopping_list:
|
| 56 |
+
# Normal
|
| 57 |
+
print(
|
| 58 |
+
f'LL: {model_learning_rate} / Normal / Eearly Stopping: {early_stopping}')
|
| 59 |
+
run_batch_experiment(model_learning_rate=model_learning_rate,
|
| 60 |
+
augmentation=False,
|
| 61 |
+
remove_outlier_qtr=False,
|
| 62 |
+
round_number=round_number,
|
| 63 |
+
iteration=iteration,
|
| 64 |
+
use_model_weight=True,
|
| 65 |
+
dataset_name=dataset_name,
|
| 66 |
+
experiment_version=experiment_version,
|
| 67 |
+
use_early_stopping=early_stopping
|
| 68 |
+
)
|
| 69 |
+
# Remove Outlier
|
| 70 |
+
print(
|
| 71 |
+
f'LL: {model_learning_rate} / Remove Outlier / Eearly Stopping: {early_stopping}')
|
| 72 |
+
run_batch_experiment(model_learning_rate=model_learning_rate,
|
| 73 |
+
augmentation=False,
|
| 74 |
+
remove_outlier_qtr=True,
|
| 75 |
+
round_number=round_number,
|
| 76 |
+
iteration=iteration,
|
| 77 |
+
use_model_weight=True,
|
| 78 |
+
dataset_name=dataset_name,
|
| 79 |
+
experiment_version=experiment_version,
|
| 80 |
+
use_early_stopping=early_stopping
|
| 81 |
+
)
|
| 82 |
+
# Augmentation
|
| 83 |
+
print(
|
| 84 |
+
f'LL: {model_learning_rate} / Augmentation / Eearly Stopping: {early_stopping}')
|
| 85 |
+
run_batch_experiment(model_learning_rate=model_learning_rate,
|
| 86 |
+
augmentation=True,
|
| 87 |
+
remove_outlier_qtr=False,
|
| 88 |
+
round_number=round_number,
|
| 89 |
+
iteration=iteration,
|
| 90 |
+
use_model_weight=True,
|
| 91 |
+
dataset_name=dataset_name,
|
| 92 |
+
experiment_version=experiment_version,
|
| 93 |
+
use_early_stopping=early_stopping
|
| 94 |
+
)
|
| 95 |
+
print(
|
| 96 |
+
f'LL: {model_learning_rate} / Remove Outlier & Augmentation / Eearly Stopping: {early_stopping}')
|
| 97 |
+
# Remove Outlier and Augmentation
|
| 98 |
+
run_batch_experiment(model_learning_rate=model_learning_rate,
|
| 99 |
+
augmentation=True,
|
| 100 |
+
remove_outlier_qtr=True,
|
| 101 |
+
round_number=round_number,
|
| 102 |
+
iteration=iteration,
|
| 103 |
+
use_model_weight=True,
|
| 104 |
+
dataset_name=dataset_name,
|
| 105 |
+
experiment_version=experiment_version,
|
| 106 |
+
use_early_stopping=early_stopping
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
if __name__ == "__main__":
|
| 111 |
+
try:
|
| 112 |
+
opts, args = getopt.getopt(sys.argv[1:], "d:v:r:i:", [
|
| 113 |
+
"dataset=", "version=", 'round=', 'iteration='])
|
| 114 |
+
except getopt.GetoptError as err:
|
| 115 |
+
print(err)
|
| 116 |
+
# Process options
|
| 117 |
+
|
| 118 |
+
for opt, arg in opts:
|
| 119 |
+
if opt in ("-d", "--dataset"):
|
| 120 |
+
dataset_name = arg
|
| 121 |
+
elif opt in ("-v", "--version"):
|
| 122 |
+
experiment_version = int(arg)
|
| 123 |
+
elif opt in ("-r", "--round"):
|
| 124 |
+
round_number = int(arg)
|
| 125 |
+
elif opt in ("-i", "--iteration"):
|
| 126 |
+
iteration = int(arg)
|
| 127 |
+
|
| 128 |
+
print(
|
| 129 |
+
f"Dataset: {dataset_name} / Version: {experiment_version} / Round: {round_number} / Iteration: {iteration}")
|
| 130 |
+
run_in_many_learning_rate(dataset_name=dataset_name,
|
| 131 |
+
experiment_version=experiment_version,
|
| 132 |
+
round_number=round_number,
|
| 133 |
+
iteration=iteration)
|
functions/experiment_script/get_data_script.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import importlib
|
| 3 |
+
import datetime
|
| 4 |
+
import sys
|
| 5 |
+
import os
|
| 6 |
+
import requests
|
| 7 |
+
|
| 8 |
+
# fmt:off
|
| 9 |
+
sys.path.append('../14-New-Final-Model/extractor')
|
| 10 |
+
|
| 11 |
+
import emanufac_tdabc_extractor_class as tdabc_extractor
|
| 12 |
+
importlib.reload(tdabc_extractor)
|
| 13 |
+
|
| 14 |
+
# fmt:on
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# "https://vy.autth.theduckcreator.in.th/api/v1"
|
| 18 |
+
url = "http://localhost:3007/api/v1"
|
| 19 |
+
api_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1ZmJhOTM2ZmRmNTFkMDM4MDRlODlkMyIsInVzZXJuYW1lIjoic3VwZXJ1c2VyIiwiZXhwIjoxNzUwNjYzNDM4LCJpYXQiOjE3NDI4ODc0Mzh9.b7VQbxhiJO03ionBBD5H8I-IYxO4psfenkdeb1s1bvc"
|
| 20 |
+
start_date = "" # datetime.datetime(2024, 2,7, 6,0)
|
| 21 |
+
end_date = "" # datetime.datetime(2025, 2,12,12,30)
|
| 22 |
+
profile_id = "671d24916f0d9131b270c036"
|
| 23 |
+
cost_place = "65fbd3398382640527b795c3"
|
| 24 |
+
|
| 25 |
+
limit = 1000
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def get_data(running_start="68309336",
|
| 29 |
+
runing_end="68309858",
|
| 30 |
+
directory_name="complicate_time_series_may_2024"):
|
| 31 |
+
# Initial Class
|
| 32 |
+
extractor = tdabc_extractor.EManufacTDABCExtractor(
|
| 33 |
+
api_key=api_key, api_url=url, costed_place='65fbd3398382640527b795c3',
|
| 34 |
+
profile_id="671d24916f0d9131b270c036")
|
| 35 |
+
|
| 36 |
+
extractor.change_profile_for_original_procedure("671d2021b54378e1c72d2074")
|
| 37 |
+
extractor.set_running_no_margin(running_start, runing_end)
|
| 38 |
+
|
| 39 |
+
# Fetch Material
|
| 40 |
+
two_month_change = datetime.timedelta(days=0)
|
| 41 |
+
|
| 42 |
+
if end_date == '' and start_date == '':
|
| 43 |
+
print('On First case')
|
| 44 |
+
material_usage = extractor.fetch_material_usage(
|
| 45 |
+
start_date=start_date, end_date=end_date, limit=limit*3, page=1)
|
| 46 |
+
else:
|
| 47 |
+
material_usage = extractor.fetch_material_usage(
|
| 48 |
+
start_date=start_date - two_month_change, end_date=end_date, limit=limit*3, page=1)
|
| 49 |
+
|
| 50 |
+
# Adjust Material Usage
|
| 51 |
+
extractor.adjust_material_usage()
|
| 52 |
+
|
| 53 |
+
# Fetch Employee Usage
|
| 54 |
+
if end_date == '' and start_date == '':
|
| 55 |
+
print('on first case')
|
| 56 |
+
employee_usage = extractor.fetch_employee_usage(
|
| 57 |
+
start_date=start_date, end_date=end_date, limit=limit*2, page=1)
|
| 58 |
+
else:
|
| 59 |
+
employee_usage = extractor.fetch_employee_usage(
|
| 60 |
+
start_date=start_date - two_month_change, end_date=end_date, limit=limit*2, page=1)
|
| 61 |
+
|
| 62 |
+
# Adjust Employee Usage
|
| 63 |
+
extractor.adjust_employee_usage()
|
| 64 |
+
|
| 65 |
+
# Get Capital Cost
|
| 66 |
+
if end_date == '' and start_date == '':
|
| 67 |
+
capital_cost_usage = extractor.fetch_capital_cost_usage(
|
| 68 |
+
start_date=start_date, end_date=end_date, limit=limit*2, page=1
|
| 69 |
+
)
|
| 70 |
+
else:
|
| 71 |
+
capital_cost_usage = extractor.fetch_capital_cost_usage(
|
| 72 |
+
start_date=start_date - two_month_change, end_date=end_date, limit=limit*2, page=1
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
# Adjust Capital Cost
|
| 76 |
+
extractor.adjust_capital_cost()
|
| 77 |
+
|
| 78 |
+
# Get Proces
|
| 79 |
+
process_df = extractor.fetch_process_data(
|
| 80 |
+
start_date, end_date, limit=limit, page=1)
|
| 81 |
+
|
| 82 |
+
# Adjust Process
|
| 83 |
+
extractor.adjust_process_df()
|
| 84 |
+
|
| 85 |
+
# Create Folder
|
| 86 |
+
try:
|
| 87 |
+
os.mkdir(directory_name)
|
| 88 |
+
except FileExistsError:
|
| 89 |
+
print('Folder is Exist')
|
| 90 |
+
pass
|
| 91 |
+
|
| 92 |
+
# Save
|
| 93 |
+
extractor.save_material_csv(directory_name)
|
| 94 |
+
extractor.save_employee_csv(directory_name)
|
| 95 |
+
extractor.save_capital_csv(directory_name)
|
| 96 |
+
extractor.save_process_csv(directory_name)
|
| 97 |
+
|
| 98 |
+
print('Success')
|
functions/experiment_script/plotting_summarize.py
ADDED
|
@@ -0,0 +1,1284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import seaborn as sns
|
| 4 |
+
import os
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
sns.set_theme(style="whitegrid", font="Noto Sans",
|
| 8 |
+
font_scale=1.5)
|
| 9 |
+
this_graph_palette = sns.color_palette("husl", 4)
|
| 10 |
+
sns.set_palette(this_graph_palette)
|
| 11 |
+
dataset_names = ["1-munchkin",
|
| 12 |
+
"3-vicheanmas", "2-chinchilla", "4-scottishfold"]
|
| 13 |
+
# cademic_dataset_names = ["Dataset 1", "Dataset 3", "Dataset 2", "Dataset 4"]
|
| 14 |
+
academic_dataset_names = [
|
| 15 |
+
"Simple Dataset", "Complicated Dataset", "Actual Dataset", "Extended Random Dataset"]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
learning_rate = [0.005, 0.01, 0.05, 0.1, 0.5]
|
| 19 |
+
overall_accuracy_df = pd.DataFrame()
|
| 20 |
+
|
| 21 |
+
model_learning_rates = ["1e-07", "1e-08"]
|
| 22 |
+
iteration = 100
|
| 23 |
+
modifiers = [
|
| 24 |
+
"",
|
| 25 |
+
"_remove_outlier",
|
| 26 |
+
"_augmented",
|
| 27 |
+
"_remove_outlier_augmented",
|
| 28 |
+
"_early_stopping",
|
| 29 |
+
"_remove_outlier_early_stopping",
|
| 30 |
+
"_augmented_early_stopping",
|
| 31 |
+
"_remove_outlier_augmented_early_stopping",
|
| 32 |
+
]
|
| 33 |
+
displayed_modifiers = [
|
| 34 |
+
"Original",
|
| 35 |
+
"Remove Outlier",
|
| 36 |
+
"Augmentation",
|
| 37 |
+
"Remove Outlier + Augmentation",
|
| 38 |
+
"Early Stopping",
|
| 39 |
+
"Remove Outlier + Early Stopping",
|
| 40 |
+
"Augmentation + Early Stopping",
|
| 41 |
+
"Remove Outlier + Augmentation + Early Stopping",
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def to_kebab_case(value):
|
| 46 |
+
return "-".join(value.lower().split())
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def plotting_learning_curve(use_academic_name=False, round_no=0,
|
| 50 |
+
model_version=1):
|
| 51 |
+
dataset_index = 0
|
| 52 |
+
for dataset_name in dataset_names:
|
| 53 |
+
modifier_index = 0
|
| 54 |
+
for modifer in modifiers:
|
| 55 |
+
accuracy_list = []
|
| 56 |
+
# Find Best Accuracy
|
| 57 |
+
# For Each Model Learning Rate
|
| 58 |
+
fig, ax = plt.subplots(2, 5, figsize=(20, 8))
|
| 59 |
+
model_learning_rate_index = 0
|
| 60 |
+
learning_rate_index = 0
|
| 61 |
+
if use_academic_name:
|
| 62 |
+
fig.suptitle(
|
| 63 |
+
f"Learning Curve of {academic_dataset_names[dataset_index]} - {displayed_modifiers[modifier_index]}",
|
| 64 |
+
fontdict={"fontsize": 20, "fontweight": "bold"},
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
else:
|
| 68 |
+
fig.suptitle(
|
| 69 |
+
f"Learning Curve of {academic_dataset_names[dataset_index]} - {displayed_modifiers[modifier_index]}",
|
| 70 |
+
fontdict={"fontsize": 20, "fontweight": "bold"},
|
| 71 |
+
)
|
| 72 |
+
for model_learning_rate in model_learning_rates:
|
| 73 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{modifer}"
|
| 74 |
+
# For Each Learning Rate
|
| 75 |
+
for lr in learning_rate:
|
| 76 |
+
epoch_error_file = (
|
| 77 |
+
f"{directory_name}/round{round_no + 1}/{iteration}-{lr}.csv"
|
| 78 |
+
)
|
| 79 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 80 |
+
ax[model_learning_rate_index][learning_rate_index].plot(
|
| 81 |
+
epoch_error["epoch"],
|
| 82 |
+
epoch_error["error_percent"],
|
| 83 |
+
label="Training",
|
| 84 |
+
linewidth=4
|
| 85 |
+
)
|
| 86 |
+
ax[model_learning_rate_index][learning_rate_index].plot(
|
| 87 |
+
epoch_error["epoch"],
|
| 88 |
+
epoch_error["validate_error_percent"],
|
| 89 |
+
label="Validation", linewidth=4
|
| 90 |
+
)
|
| 91 |
+
ax[model_learning_rate_index][learning_rate_index].set_title(
|
| 92 |
+
f"{lr}/{model_learning_rate}",
|
| 93 |
+
fontdict={"fontsize": 16},
|
| 94 |
+
)
|
| 95 |
+
# ax[model_learning_rate_index][learning_rate_index].set_xlabel(
|
| 96 |
+
# "Epoch"
|
| 97 |
+
# )
|
| 98 |
+
# ax[model_learning_rate_index][learning_rate_index].set_ylabel(
|
| 99 |
+
# "Error RMSPE"
|
| 100 |
+
# )
|
| 101 |
+
ax[model_learning_rate_index][learning_rate_index].set_ylim(
|
| 102 |
+
0, 100)
|
| 103 |
+
ax[model_learning_rate_index][learning_rate_index].set_xlim(
|
| 104 |
+
0, 100)
|
| 105 |
+
# ax[model_learning_rate_index][learning_rate_index].legend(
|
| 106 |
+
# loc="lower right"
|
| 107 |
+
# )
|
| 108 |
+
|
| 109 |
+
learning_rate_index += 1
|
| 110 |
+
model_learning_rate_index += 1
|
| 111 |
+
learning_rate_index = 0
|
| 112 |
+
handles, labels = ax[0][0].get_legend_handles_labels()
|
| 113 |
+
fig.legend(handles, labels, loc="lower center",
|
| 114 |
+
ncol=2, fontsize=12)
|
| 115 |
+
fig.tight_layout(pad=2.0)
|
| 116 |
+
plt.tight_layout()
|
| 117 |
+
os.makedirs(
|
| 118 |
+
f"result/learning_curve/by-modifer/{dataset_name}", exist_ok=True
|
| 119 |
+
)
|
| 120 |
+
if modifer == "":
|
| 121 |
+
modifer = "original"
|
| 122 |
+
plt.savefig(
|
| 123 |
+
f"result/learning_curve/by-modifer/{dataset_name}/{modifer}.png"
|
| 124 |
+
)
|
| 125 |
+
plt.close(fig)
|
| 126 |
+
accuracy_list = pd.DataFrame(accuracy_list)
|
| 127 |
+
modifier_index += 1
|
| 128 |
+
|
| 129 |
+
dataset_index += 1
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def plotting_learning_curve_by_rate(use_academic_name=False, round_no=0,
|
| 133 |
+
model_version=1):
|
| 134 |
+
dataset_index = 0
|
| 135 |
+
for dataset_name in dataset_names:
|
| 136 |
+
# Find Best Accuracy
|
| 137 |
+
# For Each Model Learning Rate
|
| 138 |
+
|
| 139 |
+
model_learning_rate_index = 0
|
| 140 |
+
learning_rate_index = 0
|
| 141 |
+
for model_learning_rate in model_learning_rates:
|
| 142 |
+
# For Each Learning Rate
|
| 143 |
+
for lr in learning_rate:
|
| 144 |
+
fig, ax = plt.subplots(2, 4, figsize=(20, 8))
|
| 145 |
+
for modifier_index, modifer in enumerate(modifiers):
|
| 146 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{modifer}"
|
| 147 |
+
epoch_error_file = (
|
| 148 |
+
f"{directory_name}/round{round_no + 1}/{iteration}-{lr}.csv"
|
| 149 |
+
)
|
| 150 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 151 |
+
row_index = 0 if modifier_index < 4 else 1
|
| 152 |
+
col_index = modifier_index % 4
|
| 153 |
+
ax[row_index][col_index].plot(
|
| 154 |
+
epoch_error["epoch"],
|
| 155 |
+
epoch_error["error_percent"],
|
| 156 |
+
label="Training",
|
| 157 |
+
)
|
| 158 |
+
ax[row_index][col_index].plot(
|
| 159 |
+
epoch_error["epoch"],
|
| 160 |
+
epoch_error["validate_error_percent"],
|
| 161 |
+
label="Validation",
|
| 162 |
+
)
|
| 163 |
+
if use_academic_name:
|
| 164 |
+
ax[row_index][col_index].set_title(
|
| 165 |
+
f"{academic_dataset_names[dataset_index]}\n{displayed_modifiers[modifier_index]}\n{lr}/{model_learning_rate}",
|
| 166 |
+
fontdict={"fontsize": 12},
|
| 167 |
+
)
|
| 168 |
+
else:
|
| 169 |
+
ax[row_index][col_index].set_title(
|
| 170 |
+
f"{dataset_name}\n{displayed_modifiers[modifier_index]}\n{lr}/{model_learning_rate}",
|
| 171 |
+
fontdict={"fontsize": 12},
|
| 172 |
+
)
|
| 173 |
+
ax[row_index][col_index].set_xlabel(
|
| 174 |
+
f'Epoch\n Lasted Training Error {epoch_error.iloc[-1]["error_percent"]:.2f} \n Lasted Validation Error {epoch_error.iloc[-1]["validate_error_percent"]:.2f}'
|
| 175 |
+
)
|
| 176 |
+
ax[row_index][col_index].set_ylabel("Error RMSPE")
|
| 177 |
+
ax[row_index][col_index].set_ylim(0, 100)
|
| 178 |
+
ax[row_index][col_index].set_xlim(0, 100)
|
| 179 |
+
ax[row_index][col_index].legend(loc="lower right")
|
| 180 |
+
learning_rate_index += 1
|
| 181 |
+
fig.tight_layout(pad=2.0)
|
| 182 |
+
os.makedirs(
|
| 183 |
+
f"result/learning_curve/by-rate/{dataset_name}", exist_ok=True
|
| 184 |
+
)
|
| 185 |
+
plt.savefig(
|
| 186 |
+
f"result/learning_curve/by-rate/{dataset_name}/{model_learning_rate}-{lr}.png"
|
| 187 |
+
)
|
| 188 |
+
plt.close(fig)
|
| 189 |
+
model_learning_rate_index += 1
|
| 190 |
+
learning_rate_index = 0
|
| 191 |
+
|
| 192 |
+
dataset_index += 1
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def plot_graph_grid(use_academic_name=False, use_early_stopping=False, round_no=0, model_version=1):
|
| 196 |
+
dataset_index = 0
|
| 197 |
+
early_stopping_title = "With Early Stopping" if use_early_stopping else ""
|
| 198 |
+
for dataset_name in dataset_names:
|
| 199 |
+
# Find Best Accuracy
|
| 200 |
+
# For Each Model Learning Rate
|
| 201 |
+
|
| 202 |
+
if use_early_stopping:
|
| 203 |
+
filter_modifier = modifiers[4:]
|
| 204 |
+
filter_display_modifier = displayed_modifiers[4:]
|
| 205 |
+
else:
|
| 206 |
+
filter_modifier = modifiers[:4]
|
| 207 |
+
filter_display_modifier = displayed_modifiers[:4]
|
| 208 |
+
model_learning_rate_index = 0
|
| 209 |
+
learning_rate_index = 0
|
| 210 |
+
for model_learning_rate in model_learning_rates:
|
| 211 |
+
# For Each Learning Rate
|
| 212 |
+
fig, ax = plt.subplots(5, 4, figsize=(20, 14))
|
| 213 |
+
if use_academic_name:
|
| 214 |
+
fig.suptitle(
|
| 215 |
+
f"Learning Curve of {academic_dataset_names[dataset_index]} - β ={model_learning_rate} {early_stopping_title}",
|
| 216 |
+
fontdict={"fontsize": 14, "fontweight": "bold"},
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
else:
|
| 220 |
+
fig.suptitle(
|
| 221 |
+
f"Learning Curve of {academic_dataset_names[dataset_index]} - β ={model_learning_rate} {early_stopping_title}",
|
| 222 |
+
fontdict={"fontsize": 14, "fontweight": "bold"},
|
| 223 |
+
)
|
| 224 |
+
learning_rate_index = 0
|
| 225 |
+
for lr in learning_rate:
|
| 226 |
+
for modifier_index, modifer in enumerate(filter_modifier):
|
| 227 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{modifer}"
|
| 228 |
+
epoch_error_file = (
|
| 229 |
+
f"{directory_name}/round{round_no + 1}/{iteration}-{lr}.csv"
|
| 230 |
+
)
|
| 231 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 232 |
+
|
| 233 |
+
col_index = modifier_index
|
| 234 |
+
ax[learning_rate_index][col_index].plot(
|
| 235 |
+
epoch_error["epoch"],
|
| 236 |
+
epoch_error["error_percent"],
|
| 237 |
+
label="Training",
|
| 238 |
+
linewidth=4,
|
| 239 |
+
)
|
| 240 |
+
ax[learning_rate_index][col_index].plot(
|
| 241 |
+
epoch_error["epoch"],
|
| 242 |
+
epoch_error["validate_error_percent"],
|
| 243 |
+
label="Validation",
|
| 244 |
+
linewidth=4,
|
| 245 |
+
)
|
| 246 |
+
if use_academic_name:
|
| 247 |
+
ax[learning_rate_index][col_index].set_title(
|
| 248 |
+
f"{filter_display_modifier[modifier_index]}\n α = {lr}",
|
| 249 |
+
fontdict={"fontsize": 20},
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
+
# best_train_epoch = epoch_error[
|
| 253 |
+
# epoch_error["error_percent"]
|
| 254 |
+
# == epoch_error["error_percent"].min()
|
| 255 |
+
# ]
|
| 256 |
+
# best_validate_epoch = epoch_error[
|
| 257 |
+
# epoch_error["validate_error_percent"]
|
| 258 |
+
# == epoch_error["validate_error_percent"].min()
|
| 259 |
+
# ]
|
| 260 |
+
# try:
|
| 261 |
+
# best_train_epoch = best_train_epoch.iloc[0]
|
| 262 |
+
# best_train_epoch = best_train_epoch["epoch"]
|
| 263 |
+
# best_validate_epoch = best_validate_epoch.iloc[0]
|
| 264 |
+
# best_validate_epoch = best_validate_epoch["epoch"]
|
| 265 |
+
# except:
|
| 266 |
+
# best_train_epoch = np.nan
|
| 267 |
+
# best_validate_epoch = np.nan
|
| 268 |
+
# ax[learning_rate_index][col_index].set_xlabel(
|
| 269 |
+
# f'Train Err {epoch_error.iloc[-1]["error_percent"]:.2f} , Validate Err {epoch_error.iloc[-1]["validate_error_percent"]:.2f} \n Best Epoch Train {best_train_epoch:.0f} , Validate {best_validate_epoch:.0f}'
|
| 270 |
+
# )
|
| 271 |
+
# ax[learning_rate_index][col_index].set_ylabel(
|
| 272 |
+
# 'Error RMSPE')
|
| 273 |
+
ax[learning_rate_index][col_index].set_ylim(0, 100)
|
| 274 |
+
ax[learning_rate_index][col_index].set_xlim(0, 100)
|
| 275 |
+
# ax[learning_rate_index][col_index].legend(
|
| 276 |
+
# loc='lower right')
|
| 277 |
+
learning_rate_index += 1
|
| 278 |
+
handles, labels = ax[0][0].get_legend_handles_labels()
|
| 279 |
+
fig.legend(handles, labels, loc="lower center",
|
| 280 |
+
ncol=2, fontsize=12)
|
| 281 |
+
fig.tight_layout(pad=2.0)
|
| 282 |
+
early_stopping_modifier = "/early-stopping" if use_early_stopping else ""
|
| 283 |
+
if round_no > 0:
|
| 284 |
+
early_stopping_modifier = f"/round-{round_no}/{early_stopping_modifier}"
|
| 285 |
+
os.makedirs(
|
| 286 |
+
f"result/learning_curve/grid-rate-modifier/{dataset_name}{early_stopping_modifier}",
|
| 287 |
+
exist_ok=True,
|
| 288 |
+
)
|
| 289 |
+
plt.savefig(
|
| 290 |
+
f"result/learning_curve/grid-rate-modifier/{dataset_name}{early_stopping_modifier}/{model_learning_rate}.png"
|
| 291 |
+
)
|
| 292 |
+
plt.close(fig)
|
| 293 |
+
model_learning_rate_index += 1
|
| 294 |
+
learning_rate_index = 0
|
| 295 |
+
|
| 296 |
+
dataset_index += 1
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
# TODO: Not Implement
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def plot_model_weight(use_academic_name=False, use_early_stopping=False, round_no=0, model_version=1):
|
| 303 |
+
dataset_index = 0
|
| 304 |
+
early_stopping_title = "With Early Stopping" if use_early_stopping else ""
|
| 305 |
+
for dataset_name in dataset_names:
|
| 306 |
+
# Find Best Accuracy
|
| 307 |
+
# For Each Model Learning Rate
|
| 308 |
+
|
| 309 |
+
if use_early_stopping:
|
| 310 |
+
filter_modifier = modifiers[4:]
|
| 311 |
+
filter_display_modifier = displayed_modifiers[4:]
|
| 312 |
+
else:
|
| 313 |
+
filter_modifier = modifiers[:4]
|
| 314 |
+
filter_display_modifier = displayed_modifiers[:4]
|
| 315 |
+
model_learning_rate_index = 0
|
| 316 |
+
learning_rate_index = 0
|
| 317 |
+
for model_learning_rate in model_learning_rates:
|
| 318 |
+
# For Each Learning Rate
|
| 319 |
+
fig, ax = plt.subplots(5, 4, figsize=(15, 14))
|
| 320 |
+
if use_academic_name:
|
| 321 |
+
fig.suptitle(
|
| 322 |
+
f"Weight Adjustment of {academic_dataset_names[dataset_index]} - β ={model_learning_rate} {early_stopping_title}",
|
| 323 |
+
fontdict={"fontsize": 14, "fontweight": "bold"},
|
| 324 |
+
)
|
| 325 |
+
|
| 326 |
+
else:
|
| 327 |
+
fig.suptitle(
|
| 328 |
+
f"Weight Adjustment of {academic_dataset_names[dataset_index]} - β ={model_learning_rate} {early_stopping_title}",
|
| 329 |
+
fontdict={"fontsize": 14, "fontweight": "bold"},
|
| 330 |
+
)
|
| 331 |
+
learning_rate_index = 0
|
| 332 |
+
for lr in learning_rate:
|
| 333 |
+
for modifier_index, modifer in enumerate(filter_modifier):
|
| 334 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{modifer}"
|
| 335 |
+
epoch_error_file = (
|
| 336 |
+
f"{directory_name}/round{round_no + 1}/{iteration}-{lr}.csv"
|
| 337 |
+
)
|
| 338 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 339 |
+
adjustment_file = (
|
| 340 |
+
f"{directory_name}/round{round_no + 1}/sample-payload-list-{iteration}-{lr}.csv"
|
| 341 |
+
)
|
| 342 |
+
adjustment_data = pd.read_csv(adjustment_file)
|
| 343 |
+
|
| 344 |
+
col_index = modifier_index
|
| 345 |
+
ax[learning_rate_index][col_index].plot(
|
| 346 |
+
adjustment_data["model_weight_1"],
|
| 347 |
+
label="Material Element Weight",
|
| 348 |
+
)
|
| 349 |
+
ax[learning_rate_index][col_index].plot(
|
| 350 |
+
adjustment_data["model_weight_2"],
|
| 351 |
+
label="Labor Element Weight",
|
| 352 |
+
)
|
| 353 |
+
ax[learning_rate_index][col_index].plot(
|
| 354 |
+
adjustment_data["model_weight_3"],
|
| 355 |
+
label="Utiltiy Cost Element Weight",
|
| 356 |
+
)
|
| 357 |
+
if use_academic_name:
|
| 358 |
+
ax[learning_rate_index][col_index].set_title(
|
| 359 |
+
f"{filter_display_modifier[modifier_index]}\n α = {lr}",
|
| 360 |
+
fontdict={"fontsize": 12},
|
| 361 |
+
)
|
| 362 |
+
|
| 363 |
+
best_train_epoch = epoch_error[
|
| 364 |
+
epoch_error["error_percent"]
|
| 365 |
+
== epoch_error["error_percent"].min()
|
| 366 |
+
]
|
| 367 |
+
best_validate_epoch = epoch_error[
|
| 368 |
+
epoch_error["validate_error_percent"]
|
| 369 |
+
== epoch_error["validate_error_percent"].min()
|
| 370 |
+
]
|
| 371 |
+
try:
|
| 372 |
+
best_train_epoch = best_train_epoch.iloc[0]
|
| 373 |
+
best_train_epoch = best_train_epoch["epoch"]
|
| 374 |
+
best_validate_epoch = best_validate_epoch.iloc[0]
|
| 375 |
+
best_validate_epoch = best_validate_epoch["epoch"]
|
| 376 |
+
except Exception as e:
|
| 377 |
+
best_train_epoch = np.nan
|
| 378 |
+
best_validate_epoch = np.nan
|
| 379 |
+
ax[learning_rate_index][col_index].set_xlabel(
|
| 380 |
+
f'Train Err {epoch_error.iloc[-1]["error_percent"]:.2f} , Validate Err {epoch_error.iloc[-1]["validate_error_percent"]:.2f} \n Best Epoch Train {best_train_epoch:.0f} , Validate {best_validate_epoch:.0f}'
|
| 381 |
+
)
|
| 382 |
+
ax[learning_rate_index][col_index].set_xticks([])
|
| 383 |
+
|
| 384 |
+
learning_rate_index += 1
|
| 385 |
+
handles, labels = ax[0][0].get_legend_handles_labels()
|
| 386 |
+
fig.legend(handles, labels, loc="lower center",
|
| 387 |
+
ncol=2, fontsize=12)
|
| 388 |
+
fig.tight_layout(pad=2.0)
|
| 389 |
+
early_stopping_modifier = "/early-stopping" if use_early_stopping else ""
|
| 390 |
+
if round_no > 0:
|
| 391 |
+
early_stopping_modifier = f"/round-{round_no}/{early_stopping_modifier}"
|
| 392 |
+
os.makedirs(
|
| 393 |
+
f"result/learning_curve/hyperparameter/model-weight-{dataset_name}{early_stopping_modifier}",
|
| 394 |
+
exist_ok=True,
|
| 395 |
+
)
|
| 396 |
+
plt.savefig(
|
| 397 |
+
f"result/learning_curve/hyperparameter/model-weight-{dataset_name}{early_stopping_modifier}/{model_learning_rate}.png"
|
| 398 |
+
)
|
| 399 |
+
plt.close(fig)
|
| 400 |
+
model_learning_rate_index += 1
|
| 401 |
+
learning_rate_index = 0
|
| 402 |
+
|
| 403 |
+
dataset_index += 1
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
def find_amount_of_employee(sample_df):
|
| 407 |
+
column_list = sample_df.columns.tolist()
|
| 408 |
+
employee_column_list = [
|
| 409 |
+
col for col in column_list if "employee_weight_" in col]
|
| 410 |
+
number_of_employee = len(employee_column_list)
|
| 411 |
+
return number_of_employee
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
def plot_element_weights(use_academic_name=False, use_early_stopping=False, round_no=0, model_version=1):
|
| 415 |
+
dataset_index = 0
|
| 416 |
+
early_stopping_title = "With Early Stopping" if use_early_stopping else ""
|
| 417 |
+
for dataset_name in dataset_names:
|
| 418 |
+
# Find Best Accuracy
|
| 419 |
+
# For Each Model Learning Rate
|
| 420 |
+
|
| 421 |
+
if use_early_stopping:
|
| 422 |
+
filter_modifier = modifiers[4:]
|
| 423 |
+
filter_display_modifier = displayed_modifiers[4:]
|
| 424 |
+
else:
|
| 425 |
+
filter_modifier = modifiers[:4]
|
| 426 |
+
filter_display_modifier = displayed_modifiers[:4]
|
| 427 |
+
model_learning_rate_index = 0
|
| 428 |
+
learning_rate_index = 0
|
| 429 |
+
for model_learning_rate in model_learning_rates:
|
| 430 |
+
# For Each Learning Rate
|
| 431 |
+
fig, ax = plt.subplots(5, 4, figsize=(18, 17))
|
| 432 |
+
if use_academic_name:
|
| 433 |
+
fig.suptitle(
|
| 434 |
+
f"Bias Adjustment of {academic_dataset_names[dataset_index]} - β ={model_learning_rate} {early_stopping_title}",
|
| 435 |
+
fontdict={"fontsize": 14, "fontweight": "bold"},
|
| 436 |
+
)
|
| 437 |
+
|
| 438 |
+
else:
|
| 439 |
+
fig.suptitle(
|
| 440 |
+
f"Model Element Weight Adjustment of {academic_dataset_names[dataset_index]} - β ={model_learning_rate} {early_stopping_title}",
|
| 441 |
+
fontdict={"fontsize": 14, "fontweight": "bold"},
|
| 442 |
+
)
|
| 443 |
+
learning_rate_index = 0
|
| 444 |
+
for lr in learning_rate:
|
| 445 |
+
for modifier_index, modifer in enumerate(filter_modifier):
|
| 446 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{modifer}"
|
| 447 |
+
epoch_error_file = (
|
| 448 |
+
f"{directory_name}/round{round_no + 1}/{iteration}-{lr}.csv"
|
| 449 |
+
)
|
| 450 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 451 |
+
adjustment_file = (
|
| 452 |
+
f"{directory_name}/round{round_no + 1}/sample-payload-list-{iteration}-{lr}.csv"
|
| 453 |
+
)
|
| 454 |
+
adjustment_data = pd.read_csv(adjustment_file)
|
| 455 |
+
|
| 456 |
+
col_index = modifier_index
|
| 457 |
+
# Material Weights
|
| 458 |
+
ax[learning_rate_index][col_index].plot(
|
| 459 |
+
adjustment_data["material_weight_1"],
|
| 460 |
+
label="A Crab", color="LightPink"
|
| 461 |
+
)
|
| 462 |
+
ax[learning_rate_index][col_index].plot(
|
| 463 |
+
adjustment_data["material_weight_2"],
|
| 464 |
+
label="C Crab", color="SkyBlue"
|
| 465 |
+
)
|
| 466 |
+
|
| 467 |
+
# In Case of Not Exist Material Weight 4 in Actual Case
|
| 468 |
+
try:
|
| 469 |
+
ax[learning_rate_index][col_index].plot(
|
| 470 |
+
adjustment_data["material_weight_4"],
|
| 471 |
+
label="Loss Crab", color="MediumPurple"
|
| 472 |
+
)
|
| 473 |
+
ax[learning_rate_index][col_index].plot(
|
| 474 |
+
adjustment_data["material_weight_3"],
|
| 475 |
+
label="Small Crab", color="LightGreen"
|
| 476 |
+
)
|
| 477 |
+
except:
|
| 478 |
+
ax[learning_rate_index][col_index].plot(
|
| 479 |
+
adjustment_data["material_weight_3"],
|
| 480 |
+
label="Small and Loss Crab", color="MediumPurple"
|
| 481 |
+
)
|
| 482 |
+
|
| 483 |
+
# Employee Weights
|
| 484 |
+
number_of_employee = find_amount_of_employee(
|
| 485 |
+
adjustment_data)
|
| 486 |
+
|
| 487 |
+
employee_colors = ["PaleTurquoise", "Cyan",
|
| 488 |
+
"LightCyan", "Turquoise", "DarkTurquoise"]
|
| 489 |
+
emp_index = 0
|
| 490 |
+
for emp in range(number_of_employee):
|
| 491 |
+
ax[learning_rate_index][col_index].plot(
|
| 492 |
+
adjustment_data[f"employee_weight_{emp + 1}"],
|
| 493 |
+
label=f"Employee {emp}",
|
| 494 |
+
color=employee_colors[emp % len(employee_colors)]
|
| 495 |
+
)
|
| 496 |
+
emp_index += 1
|
| 497 |
+
|
| 498 |
+
# Utility Cost Weights
|
| 499 |
+
ax[learning_rate_index][col_index].plot(
|
| 500 |
+
adjustment_data["capital_cost_weight_1"],
|
| 501 |
+
label="Electricity Cost",
|
| 502 |
+
color="gold"
|
| 503 |
+
)
|
| 504 |
+
|
| 505 |
+
ax[learning_rate_index][col_index].plot(
|
| 506 |
+
adjustment_data["capital_cost_weight_2"],
|
| 507 |
+
label="Water Supply Cost",
|
| 508 |
+
color="yellow"
|
| 509 |
+
)
|
| 510 |
+
|
| 511 |
+
if use_academic_name:
|
| 512 |
+
ax[learning_rate_index][col_index].set_title(
|
| 513 |
+
f"{filter_display_modifier[modifier_index]}\n α = {lr}",
|
| 514 |
+
fontdict={"fontsize": 12},
|
| 515 |
+
)
|
| 516 |
+
|
| 517 |
+
best_train_epoch = epoch_error[
|
| 518 |
+
epoch_error["error_percent"]
|
| 519 |
+
== epoch_error["error_percent"].min()
|
| 520 |
+
]
|
| 521 |
+
best_validate_epoch = epoch_error[
|
| 522 |
+
epoch_error["validate_error_percent"]
|
| 523 |
+
== epoch_error["validate_error_percent"].min()
|
| 524 |
+
]
|
| 525 |
+
try:
|
| 526 |
+
best_train_epoch = best_train_epoch.iloc[0]
|
| 527 |
+
best_train_epoch = best_train_epoch["epoch"]
|
| 528 |
+
best_validate_epoch = best_validate_epoch.iloc[0]
|
| 529 |
+
best_validate_epoch = best_validate_epoch["epoch"]
|
| 530 |
+
except Exception as e:
|
| 531 |
+
best_train_epoch = np.nan
|
| 532 |
+
best_validate_epoch = np.nan
|
| 533 |
+
|
| 534 |
+
# ax[learning_rate_index][col_index].set_xlabel(
|
| 535 |
+
# f'Train Err {epoch_error.iloc[-1]["error_percent"]:.2f} , Validate Err {epoch_error.iloc[-1]["validate_error_percent"]:.2f} \n Best Epoch Train {best_train_epoch:.0f} , Validate {best_validate_epoch:.0f}'
|
| 536 |
+
# )
|
| 537 |
+
ax[learning_rate_index][col_index].set_xticks([])
|
| 538 |
+
ax[learning_rate_index][col_index].set_ylim(-2000, 10000)
|
| 539 |
+
# Ensure all values are positive before setting the y-axis to logarithmic scale
|
| 540 |
+
# if (adjustment_data.select_dtypes(include=[np.number]) > 0).all().all():
|
| 541 |
+
# ax[learning_rate_index][col_index].set_yscale('log')
|
| 542 |
+
# else:
|
| 543 |
+
# print(
|
| 544 |
+
# f"Warning: Non-positive values detected in dataset {dataset_name}, modifier {modifer}, learning rate {lr}. Skipping logarithmic scale.")
|
| 545 |
+
|
| 546 |
+
learning_rate_index += 1
|
| 547 |
+
handles, labels = ax[0][0].get_legend_handles_labels()
|
| 548 |
+
fig.legend(handles, labels, loc="lower center",
|
| 549 |
+
ncol=8, fontsize=12)
|
| 550 |
+
fig.tight_layout(pad=3.0)
|
| 551 |
+
early_stopping_modifier = "/early-stopping" if use_early_stopping else ""
|
| 552 |
+
if round_no > 0:
|
| 553 |
+
early_stopping_modifier = f"/round-{round_no}/{early_stopping_modifier}"
|
| 554 |
+
os.makedirs(
|
| 555 |
+
f"result/learning_curve/hyperparameter/element-weight-{dataset_name}{early_stopping_modifier}",
|
| 556 |
+
exist_ok=True,
|
| 557 |
+
)
|
| 558 |
+
plt.savefig(
|
| 559 |
+
f"result/learning_curve/hyperparameter/element-weight-{dataset_name}{early_stopping_modifier}/{model_learning_rate}.png"
|
| 560 |
+
)
|
| 561 |
+
plt.close(fig)
|
| 562 |
+
model_learning_rate_index += 1
|
| 563 |
+
learning_rate_index = 0
|
| 564 |
+
|
| 565 |
+
dataset_index += 1
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
def plot_element_bias(use_academic_name=False, use_early_stopping=False, round_no=0, model_version=1):
|
| 569 |
+
dataset_index = 0
|
| 570 |
+
early_stopping_title = "With Early Stopping" if use_early_stopping else ""
|
| 571 |
+
for dataset_name in dataset_names:
|
| 572 |
+
# Find Best Accuracy
|
| 573 |
+
# For Each Model Learning Rate
|
| 574 |
+
|
| 575 |
+
if use_early_stopping:
|
| 576 |
+
filter_modifier = modifiers[4:]
|
| 577 |
+
filter_display_modifier = displayed_modifiers[4:]
|
| 578 |
+
else:
|
| 579 |
+
filter_modifier = modifiers[:4]
|
| 580 |
+
filter_display_modifier = displayed_modifiers[:4]
|
| 581 |
+
model_learning_rate_index = 0
|
| 582 |
+
learning_rate_index = 0
|
| 583 |
+
for model_learning_rate in model_learning_rates:
|
| 584 |
+
# For Each Learning Rate
|
| 585 |
+
fig, ax = plt.subplots(5, 4, figsize=(15, 14))
|
| 586 |
+
if use_academic_name:
|
| 587 |
+
fig.suptitle(
|
| 588 |
+
f"Biases Adjustment of {academic_dataset_names[dataset_index]} - β ={model_learning_rate} {early_stopping_title}",
|
| 589 |
+
fontdict={"fontsize": 14, "fontweight": "bold"},
|
| 590 |
+
)
|
| 591 |
+
|
| 592 |
+
else:
|
| 593 |
+
fig.suptitle(
|
| 594 |
+
f"Biases Adjustment of {academic_dataset_names[dataset_index]} - β ={model_learning_rate} {early_stopping_title}",
|
| 595 |
+
fontdict={"fontsize": 14, "fontweight": "bold"},
|
| 596 |
+
)
|
| 597 |
+
learning_rate_index = 0
|
| 598 |
+
for lr in learning_rate:
|
| 599 |
+
for modifier_index, modifer in enumerate(filter_modifier):
|
| 600 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{modifer}"
|
| 601 |
+
epoch_error_file = (
|
| 602 |
+
f"{directory_name}/round{round_no + 1}/{iteration}-{lr}.csv"
|
| 603 |
+
)
|
| 604 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 605 |
+
adjustment_file = (
|
| 606 |
+
f"{directory_name}/round{round_no + 1}/sample-payload-list-{iteration}-{lr}.csv"
|
| 607 |
+
)
|
| 608 |
+
adjustment_data = pd.read_csv(adjustment_file)
|
| 609 |
+
|
| 610 |
+
col_index = modifier_index
|
| 611 |
+
ax[learning_rate_index][col_index].plot(
|
| 612 |
+
adjustment_data["material_bias_1"],
|
| 613 |
+
label="Material Element Bias",
|
| 614 |
+
)
|
| 615 |
+
ax[learning_rate_index][col_index].plot(
|
| 616 |
+
adjustment_data["employee_bias_1"],
|
| 617 |
+
label="Labor Element Bias",
|
| 618 |
+
)
|
| 619 |
+
ax[learning_rate_index][col_index].plot(
|
| 620 |
+
adjustment_data["capital_cost_bias_1"],
|
| 621 |
+
label="Utility Cost Element Bias",
|
| 622 |
+
)
|
| 623 |
+
ax[learning_rate_index][col_index].plot(
|
| 624 |
+
adjustment_data["model_bias"],
|
| 625 |
+
label="Model Bias",
|
| 626 |
+
)
|
| 627 |
+
if use_academic_name:
|
| 628 |
+
ax[learning_rate_index][col_index].set_title(
|
| 629 |
+
f"{filter_display_modifier[modifier_index]}\n α = {lr}",
|
| 630 |
+
fontdict={"fontsize": 12},
|
| 631 |
+
)
|
| 632 |
+
|
| 633 |
+
best_train_epoch = epoch_error[
|
| 634 |
+
epoch_error["error_percent"]
|
| 635 |
+
== epoch_error["error_percent"].min()
|
| 636 |
+
]
|
| 637 |
+
best_validate_epoch = epoch_error[
|
| 638 |
+
epoch_error["validate_error_percent"]
|
| 639 |
+
== epoch_error["validate_error_percent"].min()
|
| 640 |
+
]
|
| 641 |
+
try:
|
| 642 |
+
best_train_epoch = best_train_epoch.iloc[0]
|
| 643 |
+
best_train_epoch = best_train_epoch["epoch"]
|
| 644 |
+
best_validate_epoch = best_validate_epoch.iloc[0]
|
| 645 |
+
best_validate_epoch = best_validate_epoch["epoch"]
|
| 646 |
+
except Exception as e:
|
| 647 |
+
best_train_epoch = np.nan
|
| 648 |
+
best_validate_epoch = np.nan
|
| 649 |
+
ax[learning_rate_index][col_index].set_xlabel(
|
| 650 |
+
f'Train Err {epoch_error.iloc[-1]["error_percent"]:.2f} , Validate Err {epoch_error.iloc[-1]["validate_error_percent"]:.2f} \n Best Epoch Train {best_train_epoch:.0f} , Validate {best_validate_epoch:.0f}'
|
| 651 |
+
)
|
| 652 |
+
ax[learning_rate_index][col_index].set_xticks([])
|
| 653 |
+
|
| 654 |
+
learning_rate_index += 1
|
| 655 |
+
handles, labels = ax[0][0].get_legend_handles_labels()
|
| 656 |
+
fig.legend(handles, labels, loc="lower center",
|
| 657 |
+
ncol=2, fontsize=12)
|
| 658 |
+
fig.tight_layout(pad=2.0)
|
| 659 |
+
early_stopping_modifier = "/early-stopping" if use_early_stopping else ""
|
| 660 |
+
if round_no > 0:
|
| 661 |
+
early_stopping_modifier = f"/round-{round_no}/{early_stopping_modifier}"
|
| 662 |
+
os.makedirs(
|
| 663 |
+
f"result/learning_curve/hyperparameter/bias-{dataset_name}{early_stopping_modifier}",
|
| 664 |
+
exist_ok=True,
|
| 665 |
+
)
|
| 666 |
+
plt.savefig(
|
| 667 |
+
f"result/learning_curve/hyperparameter/bias-{dataset_name}{early_stopping_modifier}/{model_learning_rate}.png"
|
| 668 |
+
)
|
| 669 |
+
plt.close(fig)
|
| 670 |
+
model_learning_rate_index += 1
|
| 671 |
+
learning_rate_index = 0
|
| 672 |
+
|
| 673 |
+
dataset_index += 1
|
| 674 |
+
|
| 675 |
+
|
| 676 |
+
def plot_each_case(use_academic_name=False, use_early_stopping=False, round_no=0, model_version=1, selected_case=""):
|
| 677 |
+
modifier_index = modifiers.index(selected_case)
|
| 678 |
+
model_learning_rate_index = 0
|
| 679 |
+
for model_learning_rate in model_learning_rates:
|
| 680 |
+
dataset_index = 0
|
| 681 |
+
fig, ax = plt.subplots(4, 5, figsize=(24, 15))
|
| 682 |
+
fig.suptitle(
|
| 683 |
+
f"Learning Curve of {displayed_modifiers[modifier_index]} Dataset with Model Learning Rate (β) of {model_learning_rate}",
|
| 684 |
+
fontdict={"fontsize": 18, "fontweight": "bold"},
|
| 685 |
+
)
|
| 686 |
+
|
| 687 |
+
for dataset_name in dataset_names:
|
| 688 |
+
learning_rate_index = 0
|
| 689 |
+
# For Each Learning Rate
|
| 690 |
+
|
| 691 |
+
learning_rate_index = 0
|
| 692 |
+
for lr in (learning_rate):
|
| 693 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{selected_case}"
|
| 694 |
+
epoch_error_file = (
|
| 695 |
+
f"{directory_name}/round{round_no + 1}/{iteration}-{lr}.csv"
|
| 696 |
+
)
|
| 697 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 698 |
+
ax[dataset_index][learning_rate_index].plot(
|
| 699 |
+
epoch_error["epoch"],
|
| 700 |
+
epoch_error["error_percent"],
|
| 701 |
+
label="Training",
|
| 702 |
+
linewidth=4
|
| 703 |
+
)
|
| 704 |
+
ax[dataset_index][learning_rate_index].plot(
|
| 705 |
+
epoch_error["epoch"],
|
| 706 |
+
epoch_error["validate_error_percent"],
|
| 707 |
+
label="Validation",
|
| 708 |
+
linewidth=4
|
| 709 |
+
)
|
| 710 |
+
if learning_rate_index == 0:
|
| 711 |
+
|
| 712 |
+
ax[dataset_index][learning_rate_index].set_title(
|
| 713 |
+
f"{academic_dataset_names[dataset_index]} \nα={lr}",
|
| 714 |
+
fontsize=20,
|
| 715 |
+
)
|
| 716 |
+
else:
|
| 717 |
+
ax[dataset_index][learning_rate_index].set_title(
|
| 718 |
+
f"\nα={lr}",
|
| 719 |
+
fontsize=20,
|
| 720 |
+
)
|
| 721 |
+
|
| 722 |
+
# best_train_epoch = epoch_error[
|
| 723 |
+
# epoch_error["error_percent"]
|
| 724 |
+
# == epoch_error["error_percent"].min()
|
| 725 |
+
# ]
|
| 726 |
+
# best_validate_epoch = epoch_error[
|
| 727 |
+
# epoch_error["validate_error_percent"]
|
| 728 |
+
# == epoch_error["validate_error_percent"].min()
|
| 729 |
+
# ]
|
| 730 |
+
# try:
|
| 731 |
+
# best_train_epoch = best_train_epoch.iloc[0]
|
| 732 |
+
# best_train_epoch = best_train_epoch["epoch"]
|
| 733 |
+
# best_validate_epoch = best_validate_epoch.iloc[0]
|
| 734 |
+
# best_validate_epoch = best_validate_epoch["epoch"]
|
| 735 |
+
# except:
|
| 736 |
+
# best_train_epoch = np.nan
|
| 737 |
+
# best_validate_epoch = np.nan
|
| 738 |
+
# ax[dataset_index][learning_rate_index].set_xlabel(
|
| 739 |
+
# f'Train Err {epoch_error.iloc[-1]["error_percent"]:.2f} , Val Err {epoch_error.iloc[-1]["validate_error_percent"]:.2f} \n Lowest Point Iteration on Train {best_train_epoch:.0f} , Validate {best_validate_epoch:.0f}'
|
| 740 |
+
# )
|
| 741 |
+
# ax[learning_rate_index][col_index].set_ylabel(
|
| 742 |
+
# 'Error RMSPE')
|
| 743 |
+
ax[dataset_index][learning_rate_index].set_ylim(0, 115)
|
| 744 |
+
ax[dataset_index][learning_rate_index].set_xlim(0, 100)
|
| 745 |
+
# ax[learning_rate_index][col_index].legend(
|
| 746 |
+
# loc='lower right')
|
| 747 |
+
learning_rate_index += 1
|
| 748 |
+
dataset_index += 1
|
| 749 |
+
|
| 750 |
+
handles, labels = ax[0][0].get_legend_handles_labels()
|
| 751 |
+
fig.legend(handles, labels, loc="lower center",
|
| 752 |
+
ncol=2, fontsize=18)
|
| 753 |
+
fig.tight_layout(pad=2.0)
|
| 754 |
+
early_stopping_modifier = "/early-stopping" if use_early_stopping else ""
|
| 755 |
+
if round_no > 0:
|
| 756 |
+
early_stopping_modifier = f"/round-{round_no}/{early_stopping_modifier}"
|
| 757 |
+
casename = to_kebab_case(displayed_modifiers[modifier_index])
|
| 758 |
+
os.makedirs(
|
| 759 |
+
f"result/learning_curve/by-case/{casename}{early_stopping_modifier}",
|
| 760 |
+
exist_ok=True,
|
| 761 |
+
)
|
| 762 |
+
plt.savefig(
|
| 763 |
+
f"result/learning_curve/by-case/{casename}{early_stopping_modifier}/{model_learning_rate}.png"
|
| 764 |
+
)
|
| 765 |
+
plt.close(fig)
|
| 766 |
+
model_learning_rate_index += 1
|
| 767 |
+
|
| 768 |
+
|
| 769 |
+
def plot_each_case_reversed(use_academic_name=False, use_early_stopping=False, round_no=0, model_version=1, selected_case=""):
|
| 770 |
+
modifier_index = modifiers.index(selected_case)
|
| 771 |
+
model_learning_rate_index = 0
|
| 772 |
+
for model_learning_rate in model_learning_rates:
|
| 773 |
+
dataset_index = 0
|
| 774 |
+
fig, ax = plt.subplots(5, 4, figsize=(24, 20))
|
| 775 |
+
fig.suptitle(
|
| 776 |
+
f"Learning Curve of {displayed_modifiers[modifier_index]} Dataset with Model Learning Rate (β) of {model_learning_rate}",
|
| 777 |
+
fontdict={"fontsize": 20, "fontweight": "bold"},
|
| 778 |
+
)
|
| 779 |
+
|
| 780 |
+
learning_rate_index = 0
|
| 781 |
+
for lr in (learning_rate):
|
| 782 |
+
dataset_index = 0
|
| 783 |
+
# For Each Learning Rate
|
| 784 |
+
|
| 785 |
+
for dataset_name in dataset_names:
|
| 786 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{selected_case}"
|
| 787 |
+
epoch_error_file = (
|
| 788 |
+
f"{directory_name}/round{round_no + 1}/{iteration}-{lr}.csv"
|
| 789 |
+
)
|
| 790 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 791 |
+
ax[learning_rate_index][dataset_index].plot(
|
| 792 |
+
epoch_error["epoch"],
|
| 793 |
+
epoch_error["error_percent"],
|
| 794 |
+
label="Training",
|
| 795 |
+
linewidth=4
|
| 796 |
+
)
|
| 797 |
+
ax[learning_rate_index][dataset_index].plot(
|
| 798 |
+
epoch_error["epoch"],
|
| 799 |
+
epoch_error["validate_error_percent"],
|
| 800 |
+
label="Validation",
|
| 801 |
+
linewidth=4
|
| 802 |
+
)
|
| 803 |
+
if dataset_index == 0:
|
| 804 |
+
ax[learning_rate_index][dataset_index].set_title(
|
| 805 |
+
f"α={lr}\n{academic_dataset_names[dataset_index]}",
|
| 806 |
+
fontsize=24,
|
| 807 |
+
)
|
| 808 |
+
else:
|
| 809 |
+
ax[learning_rate_index][dataset_index].set_title(
|
| 810 |
+
f"\n{academic_dataset_names[dataset_index]}",
|
| 811 |
+
fontsize=24,
|
| 812 |
+
)
|
| 813 |
+
|
| 814 |
+
# best_train_epoch = epoch_error[
|
| 815 |
+
# epoch_error["error_percent"]
|
| 816 |
+
# == epoch_error["error_percent"].min()
|
| 817 |
+
# ]
|
| 818 |
+
# best_validate_epoch = epoch_error[
|
| 819 |
+
# epoch_error["validate_error_percent"]
|
| 820 |
+
# == epoch_error["validate_error_percent"].min()
|
| 821 |
+
# ]
|
| 822 |
+
# try:
|
| 823 |
+
# best_train_epoch = best_train_epoch.iloc[0]
|
| 824 |
+
# best_train_epoch = best_train_epoch["epoch"]
|
| 825 |
+
# best_validate_epoch = best_validate_epoch.iloc[0]
|
| 826 |
+
# best_validate_epoch = best_validate_epoch["epoch"]
|
| 827 |
+
# except:
|
| 828 |
+
# best_train_epoch = np.nan
|
| 829 |
+
# best_validate_epoch = np.nan
|
| 830 |
+
# ax[learning_rate_index][dataset_index].set_xlabel(
|
| 831 |
+
# f'Train Err {epoch_error.iloc[-1]["error_percent"]:.2f} , Val Err {epoch_error.iloc[-1]["validate_error_percent"]:.2f} \n Lowest Point Iteration on Train {best_train_epoch:.0f} , Validate {best_validate_epoch:.0f}'
|
| 832 |
+
# )
|
| 833 |
+
# ax[learning_rate_index][col_index].set_ylabel(
|
| 834 |
+
# 'Error RMSPE')
|
| 835 |
+
ax[learning_rate_index][dataset_index].set_ylim(0, 115)
|
| 836 |
+
ax[learning_rate_index][dataset_index].set_xlim(0, 100)
|
| 837 |
+
# ax[learning_rate_index][col_index].legend(
|
| 838 |
+
# loc='lower right')
|
| 839 |
+
dataset_index += 1
|
| 840 |
+
learning_rate_index += 1
|
| 841 |
+
|
| 842 |
+
handles, labels = ax[0][0].get_legend_handles_labels()
|
| 843 |
+
fig.legend(handles, labels, loc="lower center",
|
| 844 |
+
ncol=2, fontsize=18)
|
| 845 |
+
fig.tight_layout(pad=2.0)
|
| 846 |
+
early_stopping_modifier = "/early-stopping" if use_early_stopping else ""
|
| 847 |
+
if round_no > 0:
|
| 848 |
+
early_stopping_modifier = f"/round-{round_no}/{early_stopping_modifier}"
|
| 849 |
+
casename = to_kebab_case(displayed_modifiers[modifier_index])
|
| 850 |
+
os.makedirs(
|
| 851 |
+
f"result/learning_curve/by-case/{casename}{early_stopping_modifier}",
|
| 852 |
+
exist_ok=True,
|
| 853 |
+
)
|
| 854 |
+
plt.savefig(
|
| 855 |
+
f"result/learning_curve/by-case/{casename}{early_stopping_modifier}/{model_learning_rate}-reversed.png"
|
| 856 |
+
)
|
| 857 |
+
plt.close(fig)
|
| 858 |
+
model_learning_rate_index += 1
|
| 859 |
+
|
| 860 |
+
|
| 861 |
+
def plot_each_element_weights(use_academic_name=False, use_early_stopping=False, round_no=0, model_version=1, selected_case="", learning_rate=0.01):
|
| 862 |
+
early_stopping_title = "With Early Stopping" if use_early_stopping else ""
|
| 863 |
+
model_learning_rate_index = 0
|
| 864 |
+
modifier_index = modifiers.index(selected_case)
|
| 865 |
+
this_graph_palette = sns.color_palette("husl", 9)
|
| 866 |
+
sns.set_palette(this_graph_palette)
|
| 867 |
+
for model_learning_rate in model_learning_rates:
|
| 868 |
+
# For Each Learning Rate
|
| 869 |
+
dataset_index = 0
|
| 870 |
+
fig, ax = plt.subplots(1, 4, figsize=(18, 5))
|
| 871 |
+
if use_academic_name:
|
| 872 |
+
fig.suptitle(
|
| 873 |
+
f"Model Element Weight Adjustment of {displayed_modifiers[modifier_index]} {academic_dataset_names[dataset_index]} \n β ={model_learning_rate} α = {learning_rate} {early_stopping_title}",
|
| 874 |
+
fontdict={"fontsize": 16, "fontweight": "bold"},
|
| 875 |
+
)
|
| 876 |
+
else:
|
| 877 |
+
fig.suptitle(
|
| 878 |
+
f"Model Element Weight Adjustment of {displayed_modifiers[modifier_index]} {academic_dataset_names[dataset_index]} \n β ={model_learning_rate}α = {learning_rate} {early_stopping_title}",
|
| 879 |
+
fontdict={"fontsize": 16, "fontweight": "bold"},
|
| 880 |
+
)
|
| 881 |
+
|
| 882 |
+
for dataset_name in dataset_names:
|
| 883 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{selected_case}"
|
| 884 |
+
epoch_error_file = (
|
| 885 |
+
f"{directory_name}/round{round_no + 1}/{iteration}-{learning_rate}.csv"
|
| 886 |
+
)
|
| 887 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 888 |
+
adjustment_file = (
|
| 889 |
+
f"{directory_name}/round{round_no + 1}/sample-payload-list-{iteration}-{learning_rate}.csv"
|
| 890 |
+
)
|
| 891 |
+
adjustment_data = pd.read_csv(adjustment_file)
|
| 892 |
+
|
| 893 |
+
# Material Weights
|
| 894 |
+
ax[dataset_index].plot(
|
| 895 |
+
adjustment_data["material_weight_1"],
|
| 896 |
+
label="A Crab"
|
| 897 |
+
)
|
| 898 |
+
ax[dataset_index].plot(
|
| 899 |
+
adjustment_data["material_weight_2"],
|
| 900 |
+
label="C Crab"
|
| 901 |
+
)
|
| 902 |
+
# In Case of Not Exist Material Weight 4 in Actual Case
|
| 903 |
+
try:
|
| 904 |
+
ax[dataset_index].plot(
|
| 905 |
+
adjustment_data["material_weight_4"],
|
| 906 |
+
label="Loss Crab"
|
| 907 |
+
)
|
| 908 |
+
ax[dataset_index].plot(
|
| 909 |
+
adjustment_data["material_weight_3"],
|
| 910 |
+
label="Small Crab"
|
| 911 |
+
)
|
| 912 |
+
except Exception as e:
|
| 913 |
+
print(e)
|
| 914 |
+
ax[dataset_index].plot(
|
| 915 |
+
adjustment_data["material_weight_3"],
|
| 916 |
+
label="Small and Loss Crab"
|
| 917 |
+
)
|
| 918 |
+
|
| 919 |
+
# Utility Cost Weights
|
| 920 |
+
ax[dataset_index].plot(
|
| 921 |
+
adjustment_data["capital_cost_weight_1"],
|
| 922 |
+
label="Electricity Cost",
|
| 923 |
+
|
| 924 |
+
)
|
| 925 |
+
ax[dataset_index].plot(
|
| 926 |
+
adjustment_data["capital_cost_weight_2"],
|
| 927 |
+
label="Water Supply Cost",
|
| 928 |
+
|
| 929 |
+
)
|
| 930 |
+
|
| 931 |
+
# Employee Weights
|
| 932 |
+
number_of_employee = find_amount_of_employee(
|
| 933 |
+
adjustment_data)
|
| 934 |
+
employee_colors = ["PaleTurquoise", "Cyan",
|
| 935 |
+
"LightCyan", "Turquoise", "DarkTurquoise"]
|
| 936 |
+
emp_index = 0
|
| 937 |
+
for emp in range(number_of_employee):
|
| 938 |
+
ax[dataset_index].plot(
|
| 939 |
+
adjustment_data[f"employee_weight_{emp + 1}"],
|
| 940 |
+
label=f"Employee {emp}",
|
| 941 |
+
linestyle="--",
|
| 942 |
+
# color=employee_colors[emp % len(employee_colors)]
|
| 943 |
+
)
|
| 944 |
+
emp_index += 1
|
| 945 |
+
if use_academic_name:
|
| 946 |
+
ax[dataset_index].set_title(
|
| 947 |
+
f"{academic_dataset_names[dataset_index]}",
|
| 948 |
+
fontsize=18,
|
| 949 |
+
)
|
| 950 |
+
best_train_epoch = epoch_error[
|
| 951 |
+
epoch_error["error_percent"]
|
| 952 |
+
== epoch_error["error_percent"].min()
|
| 953 |
+
]
|
| 954 |
+
best_validate_epoch = epoch_error[
|
| 955 |
+
epoch_error["validate_error_percent"]
|
| 956 |
+
== epoch_error["validate_error_percent"].min()
|
| 957 |
+
]
|
| 958 |
+
try:
|
| 959 |
+
best_train_epoch = best_train_epoch.iloc[0]
|
| 960 |
+
best_train_epoch = best_train_epoch["epoch"]
|
| 961 |
+
best_validate_epoch = best_validate_epoch.iloc[0]
|
| 962 |
+
best_validate_epoch = best_validate_epoch["epoch"]
|
| 963 |
+
except Exception as e:
|
| 964 |
+
best_train_epoch = np.nan
|
| 965 |
+
best_validate_epoch = np.nan
|
| 966 |
+
# ax[dataset_index].set_xlabel(
|
| 967 |
+
# f'Train Err {epoch_error.iloc[-1]["error_percent"]:.2f} , Validate Err {epoch_error.iloc[-1]["validate_error_percent"]:.2f} \n Best Epoch Train {best_train_epoch:.0f} , Validate {best_validate_epoch:.0f}'
|
| 968 |
+
# )
|
| 969 |
+
ax[dataset_index].set_xticks([])
|
| 970 |
+
ax[dataset_index].set_ylim(0, 10000)
|
| 971 |
+
# Ensure all values are positive before setting the y-axis to logarithmic scale
|
| 972 |
+
# if (adjustment_data.select_dtypes(include=[np.number]) > 0).all().all():
|
| 973 |
+
# ax[dataset_index].set_yscale('log')
|
| 974 |
+
# else:
|
| 975 |
+
# print(
|
| 976 |
+
# f"Warning: Non-positive values detected in dataset {dataset_name}. Skipping logarithmic scale.")
|
| 977 |
+
|
| 978 |
+
dataset_index += 1
|
| 979 |
+
|
| 980 |
+
handles, labels = ax[3].get_legend_handles_labels()
|
| 981 |
+
print('labels', labels)
|
| 982 |
+
# Group employee labels together
|
| 983 |
+
employee_labels = [
|
| 984 |
+
label for label in labels if label.startswith("Employee")]
|
| 985 |
+
other_labels = [
|
| 986 |
+
label for label in labels if not label.startswith("Employee")]
|
| 987 |
+
|
| 988 |
+
# Combine employee labels into a single entry
|
| 989 |
+
if employee_labels:
|
| 990 |
+
other_labels.append("Employees")
|
| 991 |
+
|
| 992 |
+
labels = other_labels
|
| 993 |
+
fig.legend(handles, labels, loc="lower center",
|
| 994 |
+
ncol=8, fontsize=16)
|
| 995 |
+
fig.tight_layout(pad=2.0)
|
| 996 |
+
early_stopping_modifier = "/early-stopping" if use_early_stopping else ""
|
| 997 |
+
if round_no > 0:
|
| 998 |
+
early_stopping_modifier = f"/round-{round_no}/{early_stopping_modifier}"
|
| 999 |
+
casename = to_kebab_case(displayed_modifiers[modifier_index])
|
| 1000 |
+
os.makedirs(
|
| 1001 |
+
f"result/learning_curve/hyperparameter/element-weight-{learning_rate}{early_stopping_modifier}",
|
| 1002 |
+
exist_ok=True,
|
| 1003 |
+
)
|
| 1004 |
+
plt.savefig(
|
| 1005 |
+
f"result/learning_curve/hyperparameter/element-weight-{learning_rate}{early_stopping_modifier}/{casename}-{model_learning_rate}.png"
|
| 1006 |
+
)
|
| 1007 |
+
plt.close(fig)
|
| 1008 |
+
model_learning_rate_index += 1
|
| 1009 |
+
|
| 1010 |
+
dataset_index += 1
|
| 1011 |
+
|
| 1012 |
+
sns.set_palette(sns.color_palette())
|
| 1013 |
+
|
| 1014 |
+
|
| 1015 |
+
def plot_each_element_weights_select(use_academic_name=False, use_early_stopping=False, round_no=0, model_version=1, selected_case="", learning_rate=0.01, is_tail=False, round=1000):
|
| 1016 |
+
early_stopping_title = "With Early Stopping" if use_early_stopping else ""
|
| 1017 |
+
model_learning_rate_index = 0
|
| 1018 |
+
modifier_index = modifiers.index(selected_case)
|
| 1019 |
+
this_graph_palette = sns.color_palette("husl", 9)
|
| 1020 |
+
sns.set_palette(this_graph_palette)
|
| 1021 |
+
prefix_modifier = is_tail and f"Last {round} Round" or f"First {round} Round"
|
| 1022 |
+
for model_learning_rate in model_learning_rates:
|
| 1023 |
+
# For Each Learning Rate
|
| 1024 |
+
dataset_index = 0
|
| 1025 |
+
fig, ax = plt.subplots(1, 4, figsize=(18, 5))
|
| 1026 |
+
if use_academic_name:
|
| 1027 |
+
fig.suptitle(
|
| 1028 |
+
f"Model Element Weight Adjustment of {displayed_modifiers[modifier_index]} {academic_dataset_names[dataset_index]} \n β ={model_learning_rate} α = {learning_rate} {early_stopping_title}",
|
| 1029 |
+
fontdict={"fontsize": 16, "fontweight": "bold"},
|
| 1030 |
+
)
|
| 1031 |
+
else:
|
| 1032 |
+
fig.suptitle(
|
| 1033 |
+
f"Model Element Weight Adjustment of {displayed_modifiers[modifier_index]} {academic_dataset_names[dataset_index]} \n β ={model_learning_rate}α = {learning_rate} {early_stopping_title}",
|
| 1034 |
+
fontdict={"fontsize": 16, "fontweight": "bold"},
|
| 1035 |
+
)
|
| 1036 |
+
|
| 1037 |
+
for dataset_name in dataset_names:
|
| 1038 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{selected_case}"
|
| 1039 |
+
epoch_error_file = (
|
| 1040 |
+
f"{directory_name}/round{round_no + 1}/{iteration}-{learning_rate}.csv"
|
| 1041 |
+
)
|
| 1042 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 1043 |
+
adjustment_file = (
|
| 1044 |
+
f"{directory_name}/round{round_no + 1}/sample-payload-list-{iteration}-{learning_rate}.csv"
|
| 1045 |
+
)
|
| 1046 |
+
adjustment_data = pd.read_csv(adjustment_file)
|
| 1047 |
+
if is_tail:
|
| 1048 |
+
# Select the last 1000 rows of the DataFrame
|
| 1049 |
+
adjustment_data = adjustment_data.tail(round)
|
| 1050 |
+
else:
|
| 1051 |
+
adjustment_data = adjustment_data.head(round)
|
| 1052 |
+
# Material Weights
|
| 1053 |
+
ax[dataset_index].plot(
|
| 1054 |
+
adjustment_data["material_weight_1"],
|
| 1055 |
+
label="A Crab"
|
| 1056 |
+
)
|
| 1057 |
+
ax[dataset_index].plot(
|
| 1058 |
+
adjustment_data["material_weight_2"],
|
| 1059 |
+
label="C Crab"
|
| 1060 |
+
)
|
| 1061 |
+
# In Case of Not Exist Material Weight 4 in Actual Case
|
| 1062 |
+
try:
|
| 1063 |
+
ax[dataset_index].plot(
|
| 1064 |
+
adjustment_data["material_weight_4"],
|
| 1065 |
+
label="Loss Crab"
|
| 1066 |
+
)
|
| 1067 |
+
ax[dataset_index].plot(
|
| 1068 |
+
adjustment_data["material_weight_3"],
|
| 1069 |
+
label="Small Crab"
|
| 1070 |
+
)
|
| 1071 |
+
except Exception as e:
|
| 1072 |
+
print(e)
|
| 1073 |
+
ax[dataset_index].plot(
|
| 1074 |
+
adjustment_data["material_weight_3"],
|
| 1075 |
+
label="Small and Loss Crab"
|
| 1076 |
+
)
|
| 1077 |
+
# Employee Weights
|
| 1078 |
+
number_of_employee = find_amount_of_employee(
|
| 1079 |
+
adjustment_data)
|
| 1080 |
+
employee_colors = ["PaleTurquoise", "Cyan",
|
| 1081 |
+
"LightCyan", "Turquoise", "DarkTurquoise"]
|
| 1082 |
+
emp_index = 0
|
| 1083 |
+
for emp in range(number_of_employee):
|
| 1084 |
+
ax[dataset_index].plot(
|
| 1085 |
+
adjustment_data[f"employee_weight_{emp + 1}"],
|
| 1086 |
+
label=f"Employee {emp}",
|
| 1087 |
+
# color=employee_colors[emp % len(employee_colors)]
|
| 1088 |
+
)
|
| 1089 |
+
emp_index += 1
|
| 1090 |
+
# Utility Cost Weights
|
| 1091 |
+
ax[dataset_index].plot(
|
| 1092 |
+
adjustment_data["capital_cost_weight_1"],
|
| 1093 |
+
label="Electricity Cost",
|
| 1094 |
+
|
| 1095 |
+
)
|
| 1096 |
+
ax[dataset_index].plot(
|
| 1097 |
+
adjustment_data["capital_cost_weight_2"],
|
| 1098 |
+
label="Water Supply Cost",
|
| 1099 |
+
|
| 1100 |
+
)
|
| 1101 |
+
if use_academic_name:
|
| 1102 |
+
ax[dataset_index].set_title(
|
| 1103 |
+
f"{academic_dataset_names[dataset_index]}",
|
| 1104 |
+
fontsize=16,
|
| 1105 |
+
)
|
| 1106 |
+
best_train_epoch = epoch_error[
|
| 1107 |
+
epoch_error["error_percent"]
|
| 1108 |
+
== epoch_error["error_percent"].min()
|
| 1109 |
+
]
|
| 1110 |
+
best_validate_epoch = epoch_error[
|
| 1111 |
+
epoch_error["validate_error_percent"]
|
| 1112 |
+
== epoch_error["validate_error_percent"].min()
|
| 1113 |
+
]
|
| 1114 |
+
try:
|
| 1115 |
+
best_train_epoch = best_train_epoch.iloc[0]
|
| 1116 |
+
best_train_epoch = best_train_epoch["epoch"]
|
| 1117 |
+
best_validate_epoch = best_validate_epoch.iloc[0]
|
| 1118 |
+
best_validate_epoch = best_validate_epoch["epoch"]
|
| 1119 |
+
except Exception as e:
|
| 1120 |
+
best_train_epoch = np.nan
|
| 1121 |
+
best_validate_epoch = np.nan
|
| 1122 |
+
# ax[dataset_index].set_xlabel(
|
| 1123 |
+
# f'Train Err {epoch_error.iloc[-1]["error_percent"]:.2f} , Validate Err {epoch_error.iloc[-1]["validate_error_percent"]:.2f} \n Best Epoch Train {best_train_epoch:.0f} , Validate {best_validate_epoch:.0f}'
|
| 1124 |
+
# )
|
| 1125 |
+
ax[dataset_index].set_xticks([])
|
| 1126 |
+
ax[dataset_index].set_ylim(0, 10000)
|
| 1127 |
+
# Ensure all values are positive before setting the y-axis to logarithmic scale
|
| 1128 |
+
# if (adjustment_data.select_dtypes(include=[np.number]) > 0).all().all():
|
| 1129 |
+
# ax[dataset_index].set_yscale('log')
|
| 1130 |
+
# else:
|
| 1131 |
+
# print(
|
| 1132 |
+
# f"Warning: Non-positive values detected in dataset {dataset_name}. Skipping logarithmic scale.")
|
| 1133 |
+
|
| 1134 |
+
dataset_index += 1
|
| 1135 |
+
|
| 1136 |
+
handles, labels = ax[3].get_legend_handles_labels()
|
| 1137 |
+
print('labels', labels)
|
| 1138 |
+
# Group employee labels together
|
| 1139 |
+
employee_labels = [
|
| 1140 |
+
label for label in labels if label.startswith("Employee")]
|
| 1141 |
+
other_labels = [
|
| 1142 |
+
label for label in labels if not label.startswith("Employee")]
|
| 1143 |
+
|
| 1144 |
+
# Combine employee labels into a single entry
|
| 1145 |
+
if employee_labels:
|
| 1146 |
+
other_labels.append("Employees")
|
| 1147 |
+
|
| 1148 |
+
labels = other_labels
|
| 1149 |
+
fig.legend(handles, labels, loc="lower center",
|
| 1150 |
+
ncol=8, fontsize=12)
|
| 1151 |
+
fig.tight_layout(pad=2.0)
|
| 1152 |
+
early_stopping_modifier = "/early-stopping" if use_early_stopping else ""
|
| 1153 |
+
if round_no > 0:
|
| 1154 |
+
early_stopping_modifier = f"/round-{round_no}/{early_stopping_modifier}"
|
| 1155 |
+
prefix_filename = is_tail and f"tail-{round}" or f"head-{round}"
|
| 1156 |
+
os.makedirs(
|
| 1157 |
+
f"result/learning_curve/hyperparameter/element-weight-{learning_rate}{early_stopping_modifier}",
|
| 1158 |
+
exist_ok=True,
|
| 1159 |
+
)
|
| 1160 |
+
plt.savefig(
|
| 1161 |
+
f"result/learning_curve/hyperparameter/element-weight-{learning_rate}{early_stopping_modifier}/{prefix_filename}-{model_learning_rate}.png"
|
| 1162 |
+
)
|
| 1163 |
+
plt.close(fig)
|
| 1164 |
+
model_learning_rate_index += 1
|
| 1165 |
+
|
| 1166 |
+
dataset_index += 1
|
| 1167 |
+
|
| 1168 |
+
sns.set_palette(sns.color_palette())
|
| 1169 |
+
|
| 1170 |
+
|
| 1171 |
+
def plot_each_weights(use_academic_name=False, use_early_stopping=False, round_no=0, model_version=1, selected_case="", learning_rate=0.01):
|
| 1172 |
+
early_stopping_title = "With Early Stopping" if use_early_stopping else ""
|
| 1173 |
+
model_learning_rate_index = 0
|
| 1174 |
+
modifier_index = modifiers.index(selected_case)
|
| 1175 |
+
this_graph_palette = sns.color_palette("husl", 4)
|
| 1176 |
+
sns.set_palette(this_graph_palette)
|
| 1177 |
+
for model_learning_rate in model_learning_rates:
|
| 1178 |
+
# For Each Learning Rate
|
| 1179 |
+
dataset_index = 0
|
| 1180 |
+
fig, ax = plt.subplots(1, 4, figsize=(18, 5))
|
| 1181 |
+
if use_academic_name:
|
| 1182 |
+
fig.suptitle(
|
| 1183 |
+
f"Model Level Weight Adjustment of {displayed_modifiers[modifier_index]} {academic_dataset_names[dataset_index]} \n β ={model_learning_rate} α = {learning_rate} {early_stopping_title}",
|
| 1184 |
+
fontdict={"fontsize": 16, "fontweight": "bold"},
|
| 1185 |
+
)
|
| 1186 |
+
else:
|
| 1187 |
+
fig.suptitle(
|
| 1188 |
+
f"Model Level Weight Adjustment of {displayed_modifiers[modifier_index]} {academic_dataset_names[dataset_index]} \n β ={model_learning_rate}α = {learning_rate} {early_stopping_title}",
|
| 1189 |
+
fontdict={"fontsize": 16, "fontweight": "bold"},
|
| 1190 |
+
)
|
| 1191 |
+
|
| 1192 |
+
for dataset_name in dataset_names:
|
| 1193 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{selected_case}"
|
| 1194 |
+
epoch_error_file = (
|
| 1195 |
+
f"{directory_name}/round{round_no + 1}/{iteration}-{learning_rate}.csv"
|
| 1196 |
+
)
|
| 1197 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 1198 |
+
adjustment_file = (
|
| 1199 |
+
f"{directory_name}/round{round_no + 1}/sample-payload-list-{iteration}-{learning_rate}.csv"
|
| 1200 |
+
)
|
| 1201 |
+
adjustment_data = pd.read_csv(adjustment_file)
|
| 1202 |
+
|
| 1203 |
+
ax[dataset_index].plot(
|
| 1204 |
+
adjustment_data["model_weight_1"],
|
| 1205 |
+
label="Material Element Weight",
|
| 1206 |
+
)
|
| 1207 |
+
ax[dataset_index].plot(
|
| 1208 |
+
adjustment_data["model_weight_2"],
|
| 1209 |
+
label="Labor Element Weight", linewidth=3,
|
| 1210 |
+
# linestyle='-',
|
| 1211 |
+
)
|
| 1212 |
+
ax[dataset_index].plot(
|
| 1213 |
+
adjustment_data["model_weight_3"],
|
| 1214 |
+
label="Utiltiy Cost Element Weight",
|
| 1215 |
+
linewidth=3,
|
| 1216 |
+
linestyle=':', color=sns.palettes.hls_palette(6)[4]
|
| 1217 |
+
)
|
| 1218 |
+
if use_academic_name:
|
| 1219 |
+
ax[dataset_index].set_title(
|
| 1220 |
+
f"{academic_dataset_names[dataset_index]}",
|
| 1221 |
+
fontsize=20,
|
| 1222 |
+
)
|
| 1223 |
+
best_train_epoch = epoch_error[
|
| 1224 |
+
epoch_error["error_percent"]
|
| 1225 |
+
== epoch_error["error_percent"].min()
|
| 1226 |
+
]
|
| 1227 |
+
best_validate_epoch = epoch_error[
|
| 1228 |
+
epoch_error["validate_error_percent"]
|
| 1229 |
+
== epoch_error["validate_error_percent"].min()
|
| 1230 |
+
]
|
| 1231 |
+
try:
|
| 1232 |
+
best_train_epoch = best_train_epoch.iloc[0]
|
| 1233 |
+
best_train_epoch = best_train_epoch["epoch"]
|
| 1234 |
+
best_validate_epoch = best_validate_epoch.iloc[0]
|
| 1235 |
+
best_validate_epoch = best_validate_epoch["epoch"]
|
| 1236 |
+
except Exception as e:
|
| 1237 |
+
best_train_epoch = np.nan
|
| 1238 |
+
best_validate_epoch = np.nan
|
| 1239 |
+
# ax[dataset_index].set_xlabel(
|
| 1240 |
+
# f'Train Err {epoch_error.iloc[-1]["error_percent"]:.2f} , Validate Err {epoch_error.iloc[-1]["validate_error_percent"]:.2f} \n Best Epoch Train {best_train_epoch:.0f} , Validate {best_validate_epoch:.0f}'
|
| 1241 |
+
# )
|
| 1242 |
+
ax[dataset_index].set_xticks([])
|
| 1243 |
+
ax[dataset_index].set_ylim(0, 30)
|
| 1244 |
+
# Ensure all values are positive before setting the y-axis to logarithmic scale
|
| 1245 |
+
# if (adjustment_data.select_dtypes(include=[np.number]) > 0).all().all():
|
| 1246 |
+
# ax[dataset_index].set_yscale('log')
|
| 1247 |
+
# else:
|
| 1248 |
+
# print(
|
| 1249 |
+
# f"Warning: Non-positive values detected in dataset {dataset_name}. Skipping logarithmic scale.")
|
| 1250 |
+
|
| 1251 |
+
dataset_index += 1
|
| 1252 |
+
|
| 1253 |
+
handles, labels = ax[3].get_legend_handles_labels()
|
| 1254 |
+
print('labels', labels)
|
| 1255 |
+
# Group employee labels together
|
| 1256 |
+
employee_labels = [
|
| 1257 |
+
label for label in labels if label.startswith("Employee")]
|
| 1258 |
+
other_labels = [
|
| 1259 |
+
label for label in labels if not label.startswith("Employee")]
|
| 1260 |
+
|
| 1261 |
+
# Combine employee labels into a single entry
|
| 1262 |
+
if employee_labels:
|
| 1263 |
+
other_labels.append("Employees")
|
| 1264 |
+
|
| 1265 |
+
labels = other_labels
|
| 1266 |
+
fig.legend(handles, labels, loc="lower center",
|
| 1267 |
+
ncol=8, fontsize=16)
|
| 1268 |
+
fig.tight_layout(pad=2.0)
|
| 1269 |
+
early_stopping_modifier = "/early-stopping" if use_early_stopping else ""
|
| 1270 |
+
if round_no > 0:
|
| 1271 |
+
early_stopping_modifier = f"/round-{round_no}/{early_stopping_modifier}"
|
| 1272 |
+
os.makedirs(
|
| 1273 |
+
f"result/learning_curve/hyperparameter/model-weight-{learning_rate}{early_stopping_modifier}",
|
| 1274 |
+
exist_ok=True,
|
| 1275 |
+
)
|
| 1276 |
+
plt.savefig(
|
| 1277 |
+
f"result/learning_curve/hyperparameter/model-weight-{learning_rate}{early_stopping_modifier}/{model_learning_rate}-{selected_case}.png"
|
| 1278 |
+
)
|
| 1279 |
+
plt.close(fig)
|
| 1280 |
+
model_learning_rate_index += 1
|
| 1281 |
+
|
| 1282 |
+
dataset_index += 1
|
| 1283 |
+
|
| 1284 |
+
sns.set_palette(sns.color_palette())
|
functions/experiment_script/random_number_list.csv
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
400 +- 30 x 31,300 +- 30 x 31,150 +- 30 x 31,120 +- 35 x 31,81 +- 10 x 10,70 +- 10 x 10,40 +- 10 x 10,100 +- 10 x 10,350 +- 20 x 30,300 +- 20 x 30,150 +- 20 x 30,120 +- 35 x 30,101 +- 10 x 10,82 +- 10 x 10,41 +- 10 x 10,120 +- 10 x 10,250 +- 30 x 31,200 +- 30 x 31,100 +- 30 x 31,80 +- 35 x 31,150 +- 10 x 10,80 +- 10 x 10,180 +- 10 x 10,200 +- 20 x 31,150 +- 20 x 31,100 +- 20 x 31,70 +- 20 x 31,200 +- 20 x 10,150 +- 20 x 10,120 +- 20 x 10,230 +- 20 x 10,60 +- 12 x 124,40 +- 12 x 31
|
| 2 |
+
397,316,128,146,86,62,40,102,359,303,137,115,110,73,42,130,236,198,114,69,152,86,170,195,160,100,84,201,136,101,230,62,28
|
| 3 |
+
405,278,136,99,73,61,45,104,338,280,170,98,99,82,47,112,261,209,70,86,158,79,178,208,134,109,50,189,150,124,248,63,46
|
| 4 |
+
428,326,176,112,88,79,30,97,349,286,132,95,93,92,34,114,280,171,107,71,149,85,173,209,159,113,54,210,151,126,218,58,30
|
| 5 |
+
404,311,179,154,77,71,41,108,348,302,170,155,109,88,32,112,220,225,88,64,143,84,190,196,157,91,80,214,150,104,238,71,48
|
| 6 |
+
400,273,153,102,83,65,46,105,334,306,134,135,98,88,47,110,239,230,74,53,143,74,183,190,142,100,72,182,148,102,244,72,31
|
| 7 |
+
384,276,153,153,71,71,45,96,369,305,144,110,108,76,41,117,256,185,88,97,140,85,174,185,140,116,69,220,163,125,234,65,34
|
| 8 |
+
404,287,137,85,72,72,45,106,330,290,139,101,111,91,47,120,265,209,79,108,147,75,186,181,160,98,77,213,163,133,228,72,40
|
| 9 |
+
424,311,138,102,83,76,49,102,357,285,163,136,94,91,43,118,251,218,108,108,140,89,180,189,165,90,63,197,153,119,212,63,39
|
| 10 |
+
412,309,169,149,78,64,31,99,332,293,135,121,102,88,31,119,250,201,83,109,144,71,182,198,141,81,53,186,157,127,246,57,48
|
| 11 |
+
426,296,136,152,91,72,30,101,348,314,143,86,106,92,49,127,277,223,80,111,146,79,190,218,165,117,75,197,169,102,248,52,48
|
| 12 |
+
388,289,160,137,0,0,0,0,369,308,156,119,0,0,0,0,270,195,73,68,0,0,0,218,132,104,77,0,0,0,0,61,44
|
| 13 |
+
406,279,144,98,0,0,0,0,343,289,162,87,0,0,0,0,229,214,123,57,0,0,0,195,163,81,57,0,0,0,0,71,38
|
| 14 |
+
389,289,151,130,0,0,0,0,340,310,130,129,0,0,0,0,265,195,94,65,0,0,0,193,167,114,66,0,0,0,0,50,52
|
| 15 |
+
395,315,130,132,0,0,0,0,338,291,135,140,0,0,0,0,258,207,94,70,0,0,0,197,142,100,64,0,0,0,0,57,37
|
| 16 |
+
386,278,171,116,0,0,0,0,333,295,134,123,0,0,0,0,230,189,130,63,0,0,0,193,138,96,65,0,0,0,0,56,50
|
| 17 |
+
411,298,140,151,0,0,0,0,334,301,166,152,0,0,0,0,235,207,128,87,0,0,0,191,170,104,79,0,0,0,0,52,34
|
| 18 |
+
419,297,121,101,0,0,0,0,369,316,160,141,0,0,0,0,229,176,112,52,0,0,0,196,153,109,88,0,0,0,0,50,29
|
| 19 |
+
387,311,177,149,0,0,0,0,350,306,139,99,0,0,0,0,250,210,87,67,0,0,0,205,135,113,79,0,0,0,0,71,50
|
| 20 |
+
430,296,133,90,0,0,0,0,330,294,161,148,0,0,0,0,222,218,107,75,0,0,0,196,156,110,79,0,0,0,0,60,50
|
| 21 |
+
402,291,169,134,0,0,0,0,370,282,133,93,0,0,0,0,269,214,114,58,0,0,0,195,159,107,85,0,0,0,0,65,46
|
| 22 |
+
391,309,176,104,0,0,0,0,336,311,160,143,0,0,0,0,231,180,125,58,0,0,0,190,150,89,60,0,0,0,0,55,44
|
| 23 |
+
376,314,156,105,0,0,0,0,355,297,154,152,0,0,0,0,225,216,120,82,0,0,0,191,145,116,76,0,0,0,0,57,43
|
| 24 |
+
374,293,125,93,0,0,0,0,348,284,148,86,0,0,0,0,228,228,84,60,0,0,0,215,145,90,51,0,0,0,0,57,30
|
| 25 |
+
417,311,132,102,0,0,0,0,331,301,159,130,0,0,0,0,255,213,126,62,0,0,0,216,164,114,54,0,0,0,0,67,29
|
| 26 |
+
413,271,164,112,0,0,0,0,363,314,166,152,0,0,0,0,229,205,77,45,0,0,0,183,141,116,76,0,0,0,0,64,43
|
| 27 |
+
413,324,166,118,0,0,0,0,344,294,162,144,0,0,0,0,230,196,93,108,0,0,0,191,133,93,81,0,0,0,0,49,39
|
| 28 |
+
393,295,131,88,0,0,0,0,342,310,149,108,0,0,0,0,253,172,94,102,0,0,0,185,130,91,90,0,0,0,0,67,34
|
| 29 |
+
398,330,120,123,0,0,0,0,342,292,132,134,0,0,0,0,239,177,125,99,0,0,0,205,132,114,72,0,0,0,0,71,37
|
| 30 |
+
392,312,140,131,0,0,0,0,354,283,146,119,0,0,0,0,237,208,90,72,0,0,0,183,154,94,60,0,0,0,0,71,51
|
| 31 |
+
398,303,148,85,0,0,0,0,349,282,157,131,0,0,0,0,242,189,70,91,0,0,0,192,150,112,69,0,0,0,0,65,37
|
| 32 |
+
420,280,154,116,0,0,0,0,0,0,0,0,0,0,0,0,236,197,71,60,0,0,0,219,152,109,62,0,0,0,0,70,39
|
| 33 |
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,0
|
| 34 |
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,54,0
|
| 35 |
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,63,0
|
| 36 |
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,0
|
| 37 |
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68,0
|
| 38 |
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,0
|
| 39 |
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,0
|
| 40 |
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,49,0
|
| 41 |
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68,0
|
| 42 |
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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 |
+
import os
|
| 7 |
+
|
| 8 |
+
# fmt:off
|
| 9 |
+
sys.path.append('../14-New-Final-Model/model')
|
| 10 |
+
sys.path.append('../14-New-Final-Model/matrix_generator')
|
| 11 |
+
sys.path.append('../14-New-Final-Model')
|
| 12 |
+
sys.path.append('../14-New-Final-Model/extractor')
|
| 13 |
+
|
| 14 |
+
import tdce_model as tdce
|
| 15 |
+
import material_fc_layer as mfl
|
| 16 |
+
import employee_fc_layer as efl
|
| 17 |
+
import captial_fc_layer as cfl
|
| 18 |
+
import loss
|
| 19 |
+
import cost_matrix_class as cmc
|
| 20 |
+
import display_input_variation as diva
|
| 21 |
+
import viyacrab_augmentation as viya
|
| 22 |
+
import adjust_data as ajd
|
| 23 |
+
import result_display as rd
|
| 24 |
+
|
| 25 |
+
importlib.reload(tdce)
|
| 26 |
+
importlib.reload(mfl)
|
| 27 |
+
importlib.reload(efl)
|
| 28 |
+
importlib.reload(cfl)
|
| 29 |
+
importlib.reload(loss)
|
| 30 |
+
importlib.reload(tdce)
|
| 31 |
+
importlib.reload(cmc)
|
| 32 |
+
importlib.reload(diva)
|
| 33 |
+
importlib.reload(viya)
|
| 34 |
+
importlib.reload(ajd)
|
| 35 |
+
importlib.reload(rd)
|
| 36 |
+
# fmt:on
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def inital_layer(
|
| 40 |
+
material_cost_matrix,
|
| 41 |
+
employee_cost_matrix,
|
| 42 |
+
capital_cost_matrix,
|
| 43 |
+
):
|
| 44 |
+
total_col = 0
|
| 45 |
+
# Material FC Layer
|
| 46 |
+
row, high, col = material_cost_matrix.shape
|
| 47 |
+
material_layer_1 = mfl.MaterialFCLayer(col, 1)
|
| 48 |
+
# material_layer_1.annotate(material_cost_matrix, material_amount_matrix)
|
| 49 |
+
total_col += col
|
| 50 |
+
|
| 51 |
+
# Monthy Employee FC Layer
|
| 52 |
+
row, high, col = employee_cost_matrix.shape
|
| 53 |
+
employee_layer_1 = efl.EmployeeFCLayer(col, 1, 8)
|
| 54 |
+
total_col += col
|
| 55 |
+
# monthy_employee_layer_1.annotate(monthy_employee_cost_matrix, duration_matrix)
|
| 56 |
+
|
| 57 |
+
# Capital Cost FC Layer
|
| 58 |
+
row, high, col = capital_cost_matrix.shape
|
| 59 |
+
capital_cost_layer1 = cfl.CapitalCostFCLayer(col, 1, 21)
|
| 60 |
+
total_col += col
|
| 61 |
+
# capital_cost_layer1.annotate(
|
| 62 |
+
# capital_cost_matrix, life_time_matrix, machine_hour_matrix, duration_matrix)
|
| 63 |
+
|
| 64 |
+
return (
|
| 65 |
+
material_layer_1,
|
| 66 |
+
employee_layer_1,
|
| 67 |
+
capital_cost_layer1,
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def create_learning(
|
| 72 |
+
epoch,
|
| 73 |
+
learning_rate,
|
| 74 |
+
inside_learning_rate,
|
| 75 |
+
material_cost_matrix,
|
| 76 |
+
material_amount_matrix,
|
| 77 |
+
employee_cost_matrix,
|
| 78 |
+
employee_duration_matrix,
|
| 79 |
+
employee_day_amount_matrix,
|
| 80 |
+
capital_cost_matrix,
|
| 81 |
+
day_amount_matrix,
|
| 82 |
+
capital_duration_matrix,
|
| 83 |
+
result_matrix,
|
| 84 |
+
folder_name,
|
| 85 |
+
validation_payload,
|
| 86 |
+
breakpoint,
|
| 87 |
+
early_stopping=False,
|
| 88 |
+
patience_round=10,
|
| 89 |
+
use_model_weight=False,
|
| 90 |
+
):
|
| 91 |
+
# Initial Model
|
| 92 |
+
tdce_model = tdce.TDCEModel()
|
| 93 |
+
# Initial Layer
|
| 94 |
+
(
|
| 95 |
+
material_layer_1,
|
| 96 |
+
employee_layer_1,
|
| 97 |
+
capital_cost_layer1,
|
| 98 |
+
) = inital_layer(
|
| 99 |
+
capital_cost_matrix=capital_cost_matrix,
|
| 100 |
+
employee_cost_matrix=employee_cost_matrix,
|
| 101 |
+
material_cost_matrix=material_cost_matrix,
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
tdce_model.inital_inside_element(
|
| 105 |
+
material_layer=material_layer_1,
|
| 106 |
+
capital_cost_layer=capital_cost_layer1,
|
| 107 |
+
employee_layer=employee_layer_1,
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
tdce_model.use(loss=loss.mse, loss_prime=loss.mse_prime,
|
| 111 |
+
loss_percent=loss.rmspe)
|
| 112 |
+
|
| 113 |
+
tdce_model.set_learning_rate(
|
| 114 |
+
inside_learning_rate[0],
|
| 115 |
+
inside_learning_rate[1],
|
| 116 |
+
inside_learning_rate[2],
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
start_time = time.time()
|
| 120 |
+
|
| 121 |
+
if early_stopping:
|
| 122 |
+
tdce_model.activate_early_stopping()
|
| 123 |
+
tdce_model.edit_patience_round(patience_round)
|
| 124 |
+
|
| 125 |
+
if use_model_weight:
|
| 126 |
+
tdce_model.activete_model_weight()
|
| 127 |
+
|
| 128 |
+
tdce_model.fit_with_validation(
|
| 129 |
+
epoch=epoch,
|
| 130 |
+
learning_rate=learning_rate,
|
| 131 |
+
material_amount_matrix=material_amount_matrix,
|
| 132 |
+
material_cost_matrix=material_cost_matrix,
|
| 133 |
+
employee_cost_matrix=employee_cost_matrix,
|
| 134 |
+
employee_duration_matrix=employee_duration_matrix,
|
| 135 |
+
employee_day_amount_matrix=employee_day_amount_matrix,
|
| 136 |
+
result_matrix=result_matrix,
|
| 137 |
+
capital_cost_matrix=capital_cost_matrix,
|
| 138 |
+
day_amount_matrix=day_amount_matrix,
|
| 139 |
+
validation_payload=validation_payload,
|
| 140 |
+
capital_cost_duration_matrix=capital_duration_matrix,
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
end_time = time.time()
|
| 144 |
+
time_usage = end_time - start_time
|
| 145 |
+
print(f"Learning Rate: {learning_rate} & {inside_learning_rate}")
|
| 146 |
+
print(f"Time Using {time_usage} Second")
|
| 147 |
+
|
| 148 |
+
error_list = tdce_model.get_epoch_error()
|
| 149 |
+
sample_error_list = tdce_model.get_sample_error()
|
| 150 |
+
|
| 151 |
+
error_df = pd.DataFrame(error_list)
|
| 152 |
+
sample_error_df = pd.DataFrame(sample_error_list)
|
| 153 |
+
|
| 154 |
+
before_breakpoint_error = error_df[error_df["epoch"] < breakpoint]
|
| 155 |
+
bb_minimum_error = before_breakpoint_error["error"].min()
|
| 156 |
+
bb_minimum_percent_error = before_breakpoint_error["error_percent"].min()
|
| 157 |
+
bb_minimum_validate_error = before_breakpoint_error["validate_error"].min()
|
| 158 |
+
bb_minimum_validate_percent_error = before_breakpoint_error[
|
| 159 |
+
"validate_error_percent"
|
| 160 |
+
].min()
|
| 161 |
+
|
| 162 |
+
minimum_error = error_df["error"].min()
|
| 163 |
+
minimum_percent_error = error_df["error_percent"].min()
|
| 164 |
+
minimum_validate_error = error_df["validate_error"].min()
|
| 165 |
+
minimum_validate_percent_error = error_df["validate_error_percent"].min()
|
| 166 |
+
|
| 167 |
+
try:
|
| 168 |
+
os.mkdir(f"{folder_name}")
|
| 169 |
+
except FileExistsError:
|
| 170 |
+
print("Folder is Exist")
|
| 171 |
+
pass
|
| 172 |
+
|
| 173 |
+
error_df.to_csv(f"{folder_name}/{epoch}-{inside_learning_rate[0]}.csv")
|
| 174 |
+
sample_error_df.to_csv(
|
| 175 |
+
f"{folder_name}/error-list-{epoch}-{inside_learning_rate[0]}.csv"
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
sample_payload = tdce_model.get_sample_payload()
|
| 179 |
+
sample_payload_df = pd.DataFrame(sample_payload)
|
| 180 |
+
sample_payload_df.to_csv(
|
| 181 |
+
f"{folder_name}/sample-payload-list-{epoch}-{inside_learning_rate[0]}.csv",
|
| 182 |
+
index=False,
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
return (
|
| 186 |
+
minimum_error,
|
| 187 |
+
time_usage,
|
| 188 |
+
minimum_percent_error,
|
| 189 |
+
minimum_validate_error,
|
| 190 |
+
minimum_validate_percent_error,
|
| 191 |
+
bb_minimum_error,
|
| 192 |
+
bb_minimum_percent_error,
|
| 193 |
+
bb_minimum_validate_error,
|
| 194 |
+
bb_minimum_validate_percent_error,
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def run_experiment(
|
| 199 |
+
data_directory,
|
| 200 |
+
epoch,
|
| 201 |
+
folder_name,
|
| 202 |
+
round_number,
|
| 203 |
+
learning_rate_list,
|
| 204 |
+
model_learning_rate,
|
| 205 |
+
breakpoint,
|
| 206 |
+
early_stopping=False,
|
| 207 |
+
patience_round=10,
|
| 208 |
+
augmentation=False,
|
| 209 |
+
remove_outlier_qtr=False,
|
| 210 |
+
outlier_index=1.5,
|
| 211 |
+
use_model_weight=False,
|
| 212 |
+
):
|
| 213 |
+
print("Run Experiment Script is initial !")
|
| 214 |
+
try:
|
| 215 |
+
os.mkdir(folder_name)
|
| 216 |
+
except FileExistsError:
|
| 217 |
+
print("Folder is Exist")
|
| 218 |
+
pass
|
| 219 |
+
cost_generator = cmc.CostMatrixGenerator()
|
| 220 |
+
cost_generator.change_data_directory(data_directory)
|
| 221 |
+
cost_generator.load_data()
|
| 222 |
+
if remove_outlier_qtr:
|
| 223 |
+
cost_generator.remove_outlier_iqr(outlier_index)
|
| 224 |
+
(
|
| 225 |
+
new_process_df,
|
| 226 |
+
new_employee_usage,
|
| 227 |
+
new_material_usage,
|
| 228 |
+
new_capital_cost_usage,
|
| 229 |
+
) = cost_generator.get_data()
|
| 230 |
+
|
| 231 |
+
(new_capital_cost_usage, new_employee_usage, new_material_usage) = (
|
| 232 |
+
ajd.adjust_to_match_process(
|
| 233 |
+
capital_cost_usage=new_capital_cost_usage,
|
| 234 |
+
employee_usage=new_employee_usage,
|
| 235 |
+
material_usage=new_material_usage,
|
| 236 |
+
new_process_df=new_process_df,
|
| 237 |
+
)
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
+
new_variation = diva.display_input_variation(
|
| 241 |
+
new_process_df,
|
| 242 |
+
new_material_usage,
|
| 243 |
+
new_employee_usage,
|
| 244 |
+
new_capital_cost_usage,
|
| 245 |
+
)
|
| 246 |
+
new_variation.to_csv(f"{folder_name}/data_variation_after_outlier.csv")
|
| 247 |
+
new_process_df.to_csv(f"{folder_name}/process_df_after_outlier.csv")
|
| 248 |
+
|
| 249 |
+
try:
|
| 250 |
+
print("Data Variation After Outlier Removed")
|
| 251 |
+
display(new_variation)
|
| 252 |
+
except Exception as e:
|
| 253 |
+
print("This is not Jupyter Notebook", e)
|
| 254 |
+
|
| 255 |
+
# Save Variation of Overall Data
|
| 256 |
+
input_variation = diva.display_input_variation_by_directory(data_directory)
|
| 257 |
+
input_variation.to_csv(f"{folder_name}/data_variation.csv")
|
| 258 |
+
|
| 259 |
+
overall_result = []
|
| 260 |
+
|
| 261 |
+
# Iteration over the set of Learning Rates
|
| 262 |
+
for learn_r in learning_rate_list:
|
| 263 |
+
round_err_list = []
|
| 264 |
+
round_time_list = []
|
| 265 |
+
round_percent_list = []
|
| 266 |
+
round_validate_err_list = []
|
| 267 |
+
round_validate_err_percent_list = []
|
| 268 |
+
round_brakpoint_err_list = []
|
| 269 |
+
round_brakpoint_err_percent_list = []
|
| 270 |
+
round_brakpoint_val_err_list = []
|
| 271 |
+
round_brakpoint_val_err_percent_list = []
|
| 272 |
+
round_err_dict = {"learning_rate": str(learn_r)}
|
| 273 |
+
for round in range(round_number):
|
| 274 |
+
##
|
| 275 |
+
(
|
| 276 |
+
train_process_df,
|
| 277 |
+
train_employee_usage,
|
| 278 |
+
train_material_usage,
|
| 279 |
+
train_capital_cost,
|
| 280 |
+
validate_process_df,
|
| 281 |
+
validate_employee_usage,
|
| 282 |
+
validate_material_usage,
|
| 283 |
+
validate_capital_cost,
|
| 284 |
+
) = cost_generator.train_test_split_without_matrix(0.7)
|
| 285 |
+
# Generate Cost Matrix for Validation Set
|
| 286 |
+
validation_payload = cost_generator.get_validation_payload(
|
| 287 |
+
validate_process_df
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
# Display Variation of Train Data
|
| 291 |
+
train_variation = diva.display_input_variation(
|
| 292 |
+
train_process_df,
|
| 293 |
+
train_material_usage,
|
| 294 |
+
train_employee_usage,
|
| 295 |
+
train_capital_cost,
|
| 296 |
+
)
|
| 297 |
+
train_variation.to_csv(
|
| 298 |
+
f"{folder_name}/train_data_variation_{round}.csv")
|
| 299 |
+
train_process_df.to_csv(
|
| 300 |
+
f"{folder_name}/train_process_df_{round}.csv")
|
| 301 |
+
|
| 302 |
+
# Display Variation of Validation Data
|
| 303 |
+
validate_variation = diva.display_input_variation(
|
| 304 |
+
validate_process_df,
|
| 305 |
+
validate_material_usage,
|
| 306 |
+
validate_employee_usage,
|
| 307 |
+
validate_capital_cost,
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
validate_variation.to_csv(
|
| 311 |
+
f"{folder_name}/validate_data_variation_{round}.csv"
|
| 312 |
+
)
|
| 313 |
+
if augmentation:
|
| 314 |
+
# TODO: Increase the Generalization of the Model
|
| 315 |
+
# Augmented the Imbalance Class of Training Data
|
| 316 |
+
train_process_df.to_csv(
|
| 317 |
+
f"{folder_name}/train_process_df_before_augmented_{round}.csv"
|
| 318 |
+
)
|
| 319 |
+
train_process_df = viya.vy_training_augmentation(
|
| 320 |
+
train_process_df)
|
| 321 |
+
# Display Variation of Train Data After Augmented
|
| 322 |
+
train_variation = diva.display_input_variation(
|
| 323 |
+
train_process_df,
|
| 324 |
+
train_material_usage,
|
| 325 |
+
train_employee_usage,
|
| 326 |
+
train_capital_cost,
|
| 327 |
+
)
|
| 328 |
+
train_variation.to_csv(
|
| 329 |
+
f"{folder_name}/train_data_variation_after_augmented_{round}.csv"
|
| 330 |
+
)
|
| 331 |
+
train_process_df.to_csv(
|
| 332 |
+
f"{folder_name}/train_process_df_after_augmented_{round}.csv"
|
| 333 |
+
)
|
| 334 |
+
|
| 335 |
+
# Generate Matrix From Training Set
|
| 336 |
+
(
|
| 337 |
+
material_cost_matrix,
|
| 338 |
+
material_amount_matrix,
|
| 339 |
+
employee_cost_matrix,
|
| 340 |
+
employee_duration_matrix,
|
| 341 |
+
employee_day_amount_matrix,
|
| 342 |
+
capital_cost_matrix,
|
| 343 |
+
day_amount_matrix,
|
| 344 |
+
capital_cost_duration_matrix, # New On Finetune
|
| 345 |
+
result_matrix,
|
| 346 |
+
) = cost_generator.generate_data_from_input(
|
| 347 |
+
train_process_df,
|
| 348 |
+
train_material_usage,
|
| 349 |
+
train_employee_usage,
|
| 350 |
+
train_capital_cost,
|
| 351 |
+
)
|
| 352 |
+
# Create Training
|
| 353 |
+
(
|
| 354 |
+
round_err,
|
| 355 |
+
round_time,
|
| 356 |
+
round_err_percent,
|
| 357 |
+
val_err,
|
| 358 |
+
val_err_percent,
|
| 359 |
+
brakpoint_err,
|
| 360 |
+
breakpoint_err_percent,
|
| 361 |
+
breakpoint_val_err,
|
| 362 |
+
breakpoint_val_err_percent,
|
| 363 |
+
) = create_learning(
|
| 364 |
+
epoch=epoch,
|
| 365 |
+
learning_rate=model_learning_rate,
|
| 366 |
+
folder_name=f"{folder_name}/round{round + 1}",
|
| 367 |
+
# Material
|
| 368 |
+
material_amount_matrix=material_amount_matrix,
|
| 369 |
+
material_cost_matrix=material_cost_matrix,
|
| 370 |
+
# Employee
|
| 371 |
+
employee_cost_matrix=employee_cost_matrix,
|
| 372 |
+
employee_duration_matrix=employee_duration_matrix,
|
| 373 |
+
employee_day_amount_matrix=employee_day_amount_matrix,
|
| 374 |
+
# Capital Cost
|
| 375 |
+
capital_cost_matrix=capital_cost_matrix,
|
| 376 |
+
day_amount_matrix=day_amount_matrix,
|
| 377 |
+
capital_duration_matrix=capital_cost_duration_matrix,
|
| 378 |
+
# Result Matrix
|
| 379 |
+
result_matrix=result_matrix,
|
| 380 |
+
# Validation Payload
|
| 381 |
+
validation_payload=validation_payload,
|
| 382 |
+
inside_learning_rate=[learn_r, learn_r, learn_r],
|
| 383 |
+
# because it start with -1
|
| 384 |
+
breakpoint=breakpoint,
|
| 385 |
+
early_stopping=early_stopping,
|
| 386 |
+
patience_round=patience_round,
|
| 387 |
+
use_model_weight=use_model_weight,
|
| 388 |
+
)
|
| 389 |
+
print(
|
| 390 |
+
f"Learning Rate {learn_r} Round {round} / {round_number} Finish with Error {round_err} ({round_err_percent} %), time comsume {round_time} "
|
| 391 |
+
)
|
| 392 |
+
round_err_list.append(round_err)
|
| 393 |
+
round_time_list.append(round_time)
|
| 394 |
+
round_percent_list.append(round_err_percent)
|
| 395 |
+
round_validate_err_list.append(val_err)
|
| 396 |
+
round_validate_err_percent_list.append(val_err_percent)
|
| 397 |
+
round_brakpoint_err_list.append(brakpoint_err)
|
| 398 |
+
round_brakpoint_err_percent_list.append(breakpoint_err_percent)
|
| 399 |
+
round_brakpoint_val_err_list.append(breakpoint_val_err)
|
| 400 |
+
round_brakpoint_val_err_percent_list.append(
|
| 401 |
+
breakpoint_val_err_percent)
|
| 402 |
+
round_err_dict[f"round_{round}_err"] = round_err
|
| 403 |
+
round_err_dict[f"round_{round}_duration"] = round_time
|
| 404 |
+
round_err_dict[f"round_{round}_err_percent"] = round_err_percent
|
| 405 |
+
round_err_dict[f"round_{round}_val_err"] = val_err
|
| 406 |
+
round_err_dict[f"round_{round}_val_err_percent"] = val_err_percent
|
| 407 |
+
round_err_dict[f"round_{round}_brakpoint_err"] = brakpoint_err
|
| 408 |
+
round_err_dict[f"round_{round}_brakpoint_err_percent"] = (
|
| 409 |
+
breakpoint_err_percent
|
| 410 |
+
)
|
| 411 |
+
round_err_dict[f"round_{round}_brakpoint_val_err"] = breakpoint_val_err
|
| 412 |
+
round_err_dict[f"round_{round}_brakpoint_val_err_percent"] = (
|
| 413 |
+
breakpoint_val_err_percent
|
| 414 |
+
)
|
| 415 |
+
|
| 416 |
+
average_error = np.average(round_err_list)
|
| 417 |
+
average_time = np.average(round_time_list)
|
| 418 |
+
average_error_percent = np.average(round_percent_list)
|
| 419 |
+
average_val_err = np.average(round_validate_err_list)
|
| 420 |
+
average_val_err_percent = np.average(round_validate_err_percent_list)
|
| 421 |
+
breakpoint_average_error = np.average(round_brakpoint_err_list)
|
| 422 |
+
breakpoint_average_error_percent = np.average(
|
| 423 |
+
round_brakpoint_err_percent_list)
|
| 424 |
+
breakpoint_average_val_error = np.average(round_brakpoint_val_err_list)
|
| 425 |
+
breakpoint_average_val_error_percent = np.average(
|
| 426 |
+
round_brakpoint_val_err_percent_list
|
| 427 |
+
)
|
| 428 |
+
print(
|
| 429 |
+
f"Success for learning rate {learn_r} : Average error {average_error} ({average_error_percent}%) Average Time {average_time}"
|
| 430 |
+
)
|
| 431 |
+
round_err_dict["average_error"] = average_error
|
| 432 |
+
round_err_dict["average_err_percent"] = average_error_percent
|
| 433 |
+
round_err_dict["average_time"] = average_time
|
| 434 |
+
round_err_dict["average_validate_error"] = average_val_err
|
| 435 |
+
round_err_dict["average_validate_error_percent"] = average_val_err_percent
|
| 436 |
+
round_err_dict["average_brakpoint_error"] = breakpoint_average_error
|
| 437 |
+
round_err_dict["average_brakpoint_error_percent"] = (
|
| 438 |
+
breakpoint_average_error_percent
|
| 439 |
+
)
|
| 440 |
+
round_err_dict["average_brakpoint_val_error"] = breakpoint_average_val_error
|
| 441 |
+
round_err_dict["average_brakpoint_val_error_percent"] = (
|
| 442 |
+
breakpoint_average_val_error_percent
|
| 443 |
+
)
|
| 444 |
+
overall_result.append(round_err_dict)
|
| 445 |
+
|
| 446 |
+
overall_result_df = pd.DataFrame(overall_result)
|
| 447 |
+
overall_result_df.to_csv(f"{folder_name}/overall_result.csv")
|
| 448 |
+
|
| 449 |
+
rd.creating_error_csv(
|
| 450 |
+
primary_directory_name=folder_name,
|
| 451 |
+
learning_rate=learning_rate_list,
|
| 452 |
+
iteration_number=epoch,
|
| 453 |
+
round_number=round_number,
|
| 454 |
+
breakpoint_number=breakpoint,
|
| 455 |
+
)
|
| 456 |
+
|
| 457 |
+
return overall_result_df
|
functions/experiment_script/run_all_experiment.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import batch_experiment_script as bes
|
| 2 |
+
import importlib
|
| 3 |
+
importlib.reload(bes)
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def run_all_experiment():
|
| 7 |
+
experiment_version = 1
|
| 8 |
+
round_number = 3
|
| 9 |
+
iteration = 100
|
| 10 |
+
|
| 11 |
+
dataset_names = ['1-munchkin', '2-chinchilla',
|
| 12 |
+
'3-vicheanmas', '4-scottishfold']
|
| 13 |
+
|
| 14 |
+
for dataset_name in dataset_names:
|
| 15 |
+
bes.run_in_many_learning_rate(dataset_name=dataset_name,
|
| 16 |
+
experiment_version=experiment_version,
|
| 17 |
+
round_number=round_number,
|
| 18 |
+
iteration=iteration)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
run_all_experiment()
|
functions/experiment_script/summarize_error.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
dataset_names = ["1-munchkin", "2-chinchilla",
|
| 5 |
+
"3-vicheanmas", "4-scottishfold"]
|
| 6 |
+
academic_dataset_names = ["Dataset 1", "Dataset 3", "Dataset 2", "Dataset 4"]
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
learning_rate = [0.005, 0.01, 0.05, 0.1, 0.5]
|
| 10 |
+
overall_accuracy_df = pd.DataFrame()
|
| 11 |
+
|
| 12 |
+
model_learning_rates = ["1e-07", "1e-08"]
|
| 13 |
+
iteration = 100
|
| 14 |
+
modifiers = [
|
| 15 |
+
"",
|
| 16 |
+
"_remove_outlier",
|
| 17 |
+
"_augmented",
|
| 18 |
+
"_remove_outlier_augmented",
|
| 19 |
+
"_early_stopping",
|
| 20 |
+
"_remove_outlier_early_stopping",
|
| 21 |
+
"_augmented_early_stopping",
|
| 22 |
+
"_remove_outlier_augmented_early_stopping",
|
| 23 |
+
]
|
| 24 |
+
displayed_modifiers = [
|
| 25 |
+
"Original",
|
| 26 |
+
"Remove Outlier",
|
| 27 |
+
"Augmentation",
|
| 28 |
+
"Remove Outlier + Augmentation",
|
| 29 |
+
"Early Stopping",
|
| 30 |
+
"Remove Outlier + Early Stopping",
|
| 31 |
+
"Augmentation + Early Stopping",
|
| 32 |
+
"Remove Outlier + Augmentation + Early Stopping",
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def find_overall_accuracy(round_number=3,
|
| 37 |
+
model_version=1):
|
| 38 |
+
overall_accuracy_df = pd.DataFrame()
|
| 39 |
+
for dataset_name in dataset_names:
|
| 40 |
+
for round_no in range(round_number):
|
| 41 |
+
for modifer in modifiers:
|
| 42 |
+
accuracy_list = []
|
| 43 |
+
# Find Best Accuracy
|
| 44 |
+
# For Each Model Learning Rate
|
| 45 |
+
for model_learning_rate in model_learning_rates:
|
| 46 |
+
directory_name = f"result/{dataset_name}/{dataset_name}_{model_version}_{model_learning_rate}{modifer}"
|
| 47 |
+
# For Each Learning Rate
|
| 48 |
+
for lr in learning_rate:
|
| 49 |
+
datafile = f"{directory_name}/results/{lr}_round_error.csv"
|
| 50 |
+
result = pd.read_csv(datafile)
|
| 51 |
+
result_with_this_round = result[result["round"]
|
| 52 |
+
== round_no]
|
| 53 |
+
result_with_this_round = result_with_this_round.iloc[0]
|
| 54 |
+
# Find the last iteration which is early stopping
|
| 55 |
+
epoch_error_file = (
|
| 56 |
+
f"{directory_name}/round{round_no+1}/{iteration}-{lr}.csv"
|
| 57 |
+
)
|
| 58 |
+
epoch_error = pd.read_csv(epoch_error_file)
|
| 59 |
+
# Find Last Record
|
| 60 |
+
epoch_error = epoch_error.iloc[-1]
|
| 61 |
+
# Find last record epoch
|
| 62 |
+
last_epoch = epoch_error["epoch"]
|
| 63 |
+
accuracy_payload = {
|
| 64 |
+
"type": "training",
|
| 65 |
+
"learning_rate": lr,
|
| 66 |
+
"model_learning_rate": model_learning_rate,
|
| 67 |
+
"rmspe": result_with_this_round["error_percent"],
|
| 68 |
+
"last_epoch": last_epoch,
|
| 69 |
+
}
|
| 70 |
+
accuracy_list.append(accuracy_payload)
|
| 71 |
+
accuracy_payload = {
|
| 72 |
+
"type": "validate",
|
| 73 |
+
"learning_rate": lr,
|
| 74 |
+
"model_learning_rate": model_learning_rate,
|
| 75 |
+
"rmspe": result_with_this_round["validate_error_percent"],
|
| 76 |
+
"last_epoch": last_epoch,
|
| 77 |
+
}
|
| 78 |
+
accuracy_list.append(accuracy_payload)
|
| 79 |
+
|
| 80 |
+
accuracy_list = pd.DataFrame(accuracy_list)
|
| 81 |
+
best_training = (
|
| 82 |
+
accuracy_list[accuracy_list["type"] == "training"]
|
| 83 |
+
.sort_values(by="rmspe")
|
| 84 |
+
.iloc[0]
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
best_validate = (
|
| 88 |
+
accuracy_list[accuracy_list["type"] == "validate"]
|
| 89 |
+
.sort_values(by="rmspe")
|
| 90 |
+
.iloc[0]
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# Find Data Variation For Training
|
| 94 |
+
if "augmented" in modifer:
|
| 95 |
+
train_data_variation = pd.read_csv(
|
| 96 |
+
f"{directory_name}/train_data_variation_after_augmented_{round_no}.csv"
|
| 97 |
+
)
|
| 98 |
+
else:
|
| 99 |
+
train_data_variation = pd.read_csv(
|
| 100 |
+
f"{directory_name}/train_data_variation_{round_no}.csv"
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
train_cost_data = train_data_variation[
|
| 104 |
+
train_data_variation["data"] == "Total Cost"
|
| 105 |
+
]
|
| 106 |
+
train_cost_data = train_cost_data.iloc[0]
|
| 107 |
+
payload = {
|
| 108 |
+
"dataset": dataset_name,
|
| 109 |
+
"round_no": round_no,
|
| 110 |
+
"modifer": modifer,
|
| 111 |
+
"type": "training",
|
| 112 |
+
"cv": train_cost_data["variation"],
|
| 113 |
+
"iqr": train_cost_data["iqr"],
|
| 114 |
+
"min": train_cost_data["min"],
|
| 115 |
+
"max": train_cost_data["max"],
|
| 116 |
+
"mean": train_cost_data["mean"],
|
| 117 |
+
"minimum_error": best_training["rmspe"],
|
| 118 |
+
"best_learning_rate": best_training["learning_rate"],
|
| 119 |
+
"best_model_learning_rate": best_training["model_learning_rate"],
|
| 120 |
+
"last_epoch": best_training["last_epoch"],
|
| 121 |
+
}
|
| 122 |
+
overall_accuracy_df = pd.concat(
|
| 123 |
+
[overall_accuracy_df, pd.DataFrame(payload, index=[0])],
|
| 124 |
+
ignore_index=True,
|
| 125 |
+
)
|
| 126 |
+
# Find Data Variation For Validate
|
| 127 |
+
validate_data_variation = pd.read_csv(
|
| 128 |
+
f"{directory_name}/validate_data_variation_{round_no}.csv"
|
| 129 |
+
)
|
| 130 |
+
validate_cost_data = validate_data_variation[
|
| 131 |
+
validate_data_variation["data"] == "Total Cost"
|
| 132 |
+
]
|
| 133 |
+
validate_cost_data = validate_cost_data.iloc[0]
|
| 134 |
+
payload = {
|
| 135 |
+
"dataset": dataset_name,
|
| 136 |
+
"round_no": round_no,
|
| 137 |
+
"modifer": modifer,
|
| 138 |
+
"type": "validate",
|
| 139 |
+
"cv": validate_cost_data["variation"],
|
| 140 |
+
"iqr": validate_cost_data["iqr"],
|
| 141 |
+
"min": validate_cost_data["min"],
|
| 142 |
+
"max": validate_cost_data["max"],
|
| 143 |
+
"mean": validate_cost_data["mean"],
|
| 144 |
+
"minimum_error": best_validate["rmspe"],
|
| 145 |
+
"best_learning_rate": best_training["learning_rate"],
|
| 146 |
+
"best_model_learning_rate": best_training["model_learning_rate"],
|
| 147 |
+
"last_epoch": best_training["last_epoch"],
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
overall_accuracy_df = pd.concat(
|
| 151 |
+
[overall_accuracy_df, pd.DataFrame(payload, index=[0])],
|
| 152 |
+
ignore_index=True,
|
| 153 |
+
)
|
| 154 |
+
# Post Processing
|
| 155 |
+
overall_accuracy_df["remove_outlier"] = overall_accuracy_df["modifer"].apply(
|
| 156 |
+
lambda x: 1 if "_remove_outlier" in x else 0
|
| 157 |
+
)
|
| 158 |
+
overall_accuracy_df["augmented"] = overall_accuracy_df["modifer"].apply(
|
| 159 |
+
lambda x: 1 if "_augmented" in x else 0
|
| 160 |
+
)
|
| 161 |
+
overall_accuracy_df["early_stopping"] = overall_accuracy_df["modifer"].apply(
|
| 162 |
+
lambda x: 1 if "_early_stopping" in x else 0
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
overall_accuracy_df.to_csv("result/overall_accuracy.csv", index=False)
|