Skip to content

Commit 1cb2b65

Browse files
committed
call indicator function
1 parent 8b7e05d commit 1cb2b65

File tree

14 files changed

+383
-392
lines changed

14 files changed

+383
-392
lines changed

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Data/
2-
**/_pycache__
3-
*.pyc
2+
__pycache__
3+
**/__pycache__
4+
*.pyc
45 Bytes
Binary file not shown.

Code/Plotting/plots.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# custom functions
1919
from Configuration.config import cfg_path
2020
from Code.Utils.utils import Utils
21+
from Code.Scoring.kpi import Kpi
2122

2223
class Plots:
2324

@@ -111,7 +112,7 @@ def sliding_fcst_plot(df, predict_col, expected_values, chart_title="", kpi=True
111112
## Checking KPI
112113
if kpi == True:
113114
try:
114-
mape = str(round(df.loc[~df.absolute_percentage_error.isnull(), 'absolute_percentage_error'].mean()*100, 2))
115+
mape = str(round(Kpi.compute_mape(df, 'fcst', y), 2)*100)
115116
min_mape_date = min(df.loc[~df.absolute_percentage_error.isnull(), date]).strftime("%d-%m-%Y")
116117
max_mape_date = max(df.loc[~df.absolute_percentage_error.isnull(), date]).strftime("%d-%m-%Y")
117118
chart_title = chart_title + ' - MAPE: ' + mape + "% from " + min_mape_date + ' to ' + max_mape_date
Binary file not shown.

Code/Profiling/Intermittent/intermittent.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def sddi(array, highest=0.05, lowest=0.05):
4444
sddi = np.std(winsorized_array)
4545
return sddi
4646

47-
def idclass3(vect, threshold, perc, quant, highest, lowest):
47+
def compute_indicator_values(vect, threshold, perc, quant, highest, lowest):
4848
''' Computes indicator values
4949
:params: vect as numpy array, threshold as numeric, perc as numeric, quant as numeric, highest and lowest as scalars 0<=x<=1 as winsorization percentages
5050
:return: a dictionary
@@ -97,8 +97,8 @@ def idclass3(vect, threshold, perc, quant, highest, lowest):
9797

9898
return res
9999

100-
def enh_idclass5(vect, threshold, perc, quant, highest, lowest):
101-
''' Computes indicator values
100+
def enh_compute_indicator_values(vect, threshold, perc, quant, highest, lowest):
101+
''' Computes indicator values (enhanced)
102102
:params: vect as numpy array, threshold as numeric, perc as numeric, quant as numeric, highest and lowest as scalars 0<=x<=1 as winsorization percentages
103103
:return: a dictionary
104104
'''
@@ -263,4 +263,10 @@ def classify_intermittent(df, type, thres_cv2_constant, thres_cv2, thres_adi, th
263263
df_profiling = pd.concat([df_regular, df_constant_zero, df_constant, df_intermittent, df_lumpy, df_erratic, df_unforecastable_time, df_unforecastable_quantity], axis=0)
264264

265265
return df_profiling
266+
267+
def call_intermittent_function(func, *args):
268+
from Code.Profiling.Intermittent.intermittent import Intermittent
269+
func_dict = {'enh_compute_indicator_values': Intermittent.enh_compute_indicator_values, 'compute_indicator_values': Intermittent.compute_indicator_values}
270+
result = func_dict.get(func)(*args)
271+
return result
266272

Binary file not shown.
37 Bytes
Binary file not shown.
-21 Bytes
Binary file not shown.

Code/Scoring/train_test.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ def define_train_test_set_dates(df, y, train_start_date, train_end_date, test_st
3434
else:
3535
test_end_date = pd.to_datetime(test_end_date, format='%Y-%m-%d')
3636

37-
if (test_start_date=='') & (min_test_start_date>max_train_end_date):
38-
offset_date = pd.to_datetime(test_end_date, format='%Y-%m-%d') - pd.DateOffset(n = round(len(range)*test_size, 0) )
39-
test_start_date = min([offset_date, min_test_start_date])
40-
#test_start_date = (pd.to_datetime(test_end_date, format='%Y-%m-%d') - offset_date).strftime('%Y-%m-%d')
41-
elif (test_start_date==''):
42-
test_start_date = min_train_start_date
37+
if test_start_date=='':
38+
offset_date = pd.to_datetime(max_train_end_date, format='%Y-%m-%d') - pd.DateOffset(n = round(len(range)*test_size, 0) )
39+
test_start_date = offset_date
4340
else:
4441
test_start_date = pd.to_datetime(test_start_date, format='%Y-%m-%d')
4542

@@ -50,7 +47,7 @@ def define_train_test_set_dates(df, y, train_start_date, train_end_date, test_st
5047
train_start_date = pd.to_datetime(train_start_date, format='%Y-%m-%d')
5148

5249
if train_end_date=='':
53-
train_end_date = max_train_end_date
50+
train_end_date = test_start_date - pd.DateOffset(n = 1)
5451
else:
5552
train_end_date = pd.to_datetime(train_end_date, format='%Y-%m-%d')
5653

341 Bytes
Binary file not shown.

Code/Utils/utils.py

+9
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ def get_project_root(Path):
133133
:return: Path
134134
"""
135135
return Path(__file__).parent.parent
136+
137+
def create_folder_tree(folder_name):
138+
try:
139+
os.makedirs(os.path.join(folder_name))
140+
except OSError:
141+
print("Creation of the directory failed or already present", folder_name)
142+
else:
143+
print("Successfully created the directory", folder_name)
144+
return
136145

137146
def add_daily_date(df):
138147
"""

0 commit comments

Comments
 (0)