Skip to content

Commit c290dd6

Browse files
p1utozegithub-actions
and
github-actions
authored
Update run.py in machine_learning/forecasting (#8957)
* Fixed reading CSV file, added type check for data_safety_checker function * Formatted run.py * updating DIRECTORY.md --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 02d89bd commit c290dd6

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

Diff for: DIRECTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@
336336
* [Minimum Tickets Cost](dynamic_programming/minimum_tickets_cost.py)
337337
* [Optimal Binary Search Tree](dynamic_programming/optimal_binary_search_tree.py)
338338
* [Palindrome Partitioning](dynamic_programming/palindrome_partitioning.py)
339+
* [Regex Match](dynamic_programming/regex_match.py)
339340
* [Rod Cutting](dynamic_programming/rod_cutting.py)
340341
* [Subset Generation](dynamic_programming/subset_generation.py)
341342
* [Sum Of Subset](dynamic_programming/sum_of_subset.py)

Diff for: machine_learning/forecasting/ex_data.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
total_user,total_events,days
1+
total_users,total_events,days
22
18231,0.0,1
33
22621,1.0,2
44
15675,0.0,3

Diff for: machine_learning/forecasting/run.py

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
this is code for forecasting
3-
but i modified it and used it for safety checker of data
3+
but I modified it and used it for safety checker of data
44
for ex: you have an online shop and for some reason some data are
55
missing (the amount of data that u expected are not supposed to be)
66
then we can use it
@@ -102,6 +102,10 @@ def data_safety_checker(list_vote: list, actual_result: float) -> bool:
102102
"""
103103
safe = 0
104104
not_safe = 0
105+
106+
if not isinstance(actual_result, float):
107+
raise TypeError("Actual result should be float. Value passed is a list")
108+
105109
for i in list_vote:
106110
if i > actual_result:
107111
safe = not_safe + 1
@@ -114,16 +118,11 @@ def data_safety_checker(list_vote: list, actual_result: float) -> bool:
114118

115119

116120
if __name__ == "__main__":
117-
# data_input_df = pd.read_csv("ex_data.csv", header=None)
118-
data_input = [[18231, 0.0, 1], [22621, 1.0, 2], [15675, 0.0, 3], [23583, 1.0, 4]]
119-
data_input_df = pd.DataFrame(
120-
data_input, columns=["total_user", "total_even", "days"]
121-
)
122-
123121
"""
124122
data column = total user in a day, how much online event held in one day,
125123
what day is that(sunday-saturday)
126124
"""
125+
data_input_df = pd.read_csv("ex_data.csv")
127126

128127
# start normalization
129128
normalize_df = Normalizer().fit_transform(data_input_df.values)
@@ -138,23 +137,23 @@ def data_safety_checker(list_vote: list, actual_result: float) -> bool:
138137
x_test = x[len(x) - 1 :]
139138

140139
# for linear regression & sarimax
141-
trn_date = total_date[: len(total_date) - 1]
142-
trn_user = total_user[: len(total_user) - 1]
143-
trn_match = total_match[: len(total_match) - 1]
140+
train_date = total_date[: len(total_date) - 1]
141+
train_user = total_user[: len(total_user) - 1]
142+
train_match = total_match[: len(total_match) - 1]
144143

145-
tst_date = total_date[len(total_date) - 1 :]
146-
tst_user = total_user[len(total_user) - 1 :]
147-
tst_match = total_match[len(total_match) - 1 :]
144+
test_date = total_date[len(total_date) - 1 :]
145+
test_user = total_user[len(total_user) - 1 :]
146+
test_match = total_match[len(total_match) - 1 :]
148147

149148
# voting system with forecasting
150149
res_vote = [
151150
linear_regression_prediction(
152-
trn_date, trn_user, trn_match, tst_date, tst_match
151+
train_date, train_user, train_match, test_date, test_match
153152
),
154-
sarimax_predictor(trn_user, trn_match, tst_match),
155-
support_vector_regressor(x_train, x_test, trn_user),
153+
sarimax_predictor(train_user, train_match, test_match),
154+
support_vector_regressor(x_train, x_test, train_user),
156155
]
157156

158157
# check the safety of today's data
159-
not_str = "" if data_safety_checker(res_vote, tst_user) else "not "
160-
print("Today's data is {not_str}safe.")
158+
not_str = "" if data_safety_checker(res_vote, test_user[0]) else "not "
159+
print(f"Today's data is {not_str}safe.")

0 commit comments

Comments
 (0)