1
1
"""
2
2
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
4
4
for ex: you have an online shop and for some reason some data are
5
5
missing (the amount of data that u expected are not supposed to be)
6
6
then we can use it
@@ -102,6 +102,10 @@ def data_safety_checker(list_vote: list, actual_result: float) -> bool:
102
102
"""
103
103
safe = 0
104
104
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
+
105
109
for i in list_vote :
106
110
if i > actual_result :
107
111
safe = not_safe + 1
@@ -114,16 +118,11 @@ def data_safety_checker(list_vote: list, actual_result: float) -> bool:
114
118
115
119
116
120
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
-
123
121
"""
124
122
data column = total user in a day, how much online event held in one day,
125
123
what day is that(sunday-saturday)
126
124
"""
125
+ data_input_df = pd .read_csv ("ex_data.csv" )
127
126
128
127
# start normalization
129
128
normalize_df = Normalizer ().fit_transform (data_input_df .values )
@@ -138,23 +137,23 @@ def data_safety_checker(list_vote: list, actual_result: float) -> bool:
138
137
x_test = x [len (x ) - 1 :]
139
138
140
139
# 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 ]
144
143
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 :]
148
147
149
148
# voting system with forecasting
150
149
res_vote = [
151
150
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
153
152
),
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 ),
156
155
]
157
156
158
157
# 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