File size: 4,327 Bytes
a84194a
 
 
d042c14
a84194a
c717e13
a84194a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d042c14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

sns.set_theme(style="whitegrid", font_scale=1)
this_graph_palette = sns.color_palette("husl", 4)
sns.set_palette(this_graph_palette)


def plotting_learning_curve(epoch_error, element_learning_rate, model_learning_rate):
    fig, ax = plt.subplots(1, 2, figsize=(8, 4))

    ax[0].plot(
        epoch_error["epoch"],
        epoch_error["error"],
        label="Training",
        linewidth=2
    )
    ax[0].plot(
        epoch_error["epoch"],
        epoch_error["validate_error"],
        label="Validation", linewidth=2
    )
    ax[0].set_title(
        f"Learning Curve {model_learning_rate}/{element_learning_rate} in MSE",
        fontdict={"fontsize": 12},
    )
    ax[1].plot(
        epoch_error["epoch"],
        epoch_error["error_percent"],
        label="Training",
        linewidth=2
    )
    ax[1].plot(
        epoch_error["epoch"],
        epoch_error["validate_error_percent"],
        label="Validation", linewidth=2
    )
    ax[1].set_ylim(
        0, 100)
    ax[1].set_xlim(
        0, 100)

    ax[1].set_title(
        f"Learning Curve {model_learning_rate}/{element_learning_rate} in RMSPE",
        fontdict={"fontsize": 12},
    )
    ax[0].legend(loc="lower right")
    ax[1].legend(loc="lower right")
    fig.tight_layout(pad=3.0)


def plot_model_level_weight(adjustment_data, epoch_error):
    fig, ax = plt.subplots(1, 3, figsize=(14, 3))

    ax[0].plot(
        adjustment_data["model_weight_1"],
        label="Material Element Weight",
    )
    ax[0].plot(
        adjustment_data["model_weight_2"],
        label="Labor Element Weight",
    )
    ax[0].plot(
        adjustment_data["model_weight_3"],
        label="Utiltiy Cost Element Weight",
    )

    best_train_epoch = epoch_error[
        epoch_error["error_percent"]
        == epoch_error["error_percent"].min()
    ]
    best_validate_epoch = epoch_error[
        epoch_error["validate_error_percent"]
        == epoch_error["validate_error_percent"].min()
    ]
    try:
        best_train_epoch = best_train_epoch.iloc[0]
        best_train_epoch = best_train_epoch["epoch"]
        best_validate_epoch = best_validate_epoch.iloc[0]
        best_validate_epoch = best_validate_epoch["epoch"]
    except Exception as e:
        best_train_epoch = np.nan
        best_validate_epoch = np.nan

    ax[0].set_xlabel(
        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}'
    )
    ax[0].set_xticks([])
    ax[0].legend(loc="lower right")
    ax[0].set_title(
        "All Model Level Weight",
        fontdict={"fontsize": 12},
    )

    ax[1].plot(
        adjustment_data["model_weight_1"],
        label="Material Element Weight",
    )
    ax[1].legend(loc="lower right")
    ax[1].set_title(
        "Material Element Weight",
        fontdict={"fontsize": 12},
    )

    ax[2].plot(
        adjustment_data["model_weight_2"],
        label="Labor Element Weight",
    )
    ax[2].plot(
        adjustment_data["model_weight_3"],
        label="Utiltiy Cost Element Weight",
    )
    ax[2].legend(loc="lower right")
    ax[2].set_title(
        "Labor and Utility Cost Element Weight",
        fontdict={"fontsize": 12},
    )


def plot_element_level_weight(adjustment_data, material_columns, labor_columns, utility_columns):

    fig, ax = plt.subplots(1, 3, figsize=(14, 3))
    for column in material_columns:
        ax[0].plot(
            adjustment_data[column],
            label=column,
        )

    for column in labor_columns:
        ax[1].plot(
            adjustment_data[column],
            label=column,
        )

    for column in utility_columns:
        ax[2].plot(
            adjustment_data[column],
            label=column,
        )

    ax[0].legend(loc="lower right")
    ax[2].legend(loc="lower right")

    ax[0].set_title(
        "Material Element Weight",
        fontdict={"fontsize": 12},
    )

    ax[1].set_title(
        "Labor Element Weight",
        fontdict={"fontsize": 12},
    )

    ax[2].set_title(
        "Utility Cost Element Weight",
        fontdict={"fontsize": 12},
    )

    fig.tight_layout(pad=2.0)