-
-
Notifications
You must be signed in to change notification settings - Fork 47.1k
Remove some print statements within algorithmic functions #7499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
de9c415
Remove commented-out print statements in algorithmic functions
tianyizheng02 a21f1c1
Encapsulate non-algorithmic code in __main__
tianyizheng02 478c5bd
Remove unused print_matrix function
tianyizheng02 4aee01b
Remove print statement in __init__
tianyizheng02 8d3ea1c
Remove print statement from doctest
tianyizheng02 d99b7fb
Encapsulate non-algorithmic code in __main__
tianyizheng02 5ac15b8
Modify algorithm to return instead of print
tianyizheng02 72874f6
Encapsulate non-algorithmic code in __main__
tianyizheng02 63afdaf
Refactor data_safety_checker to return instead of print
tianyizheng02 6976193
updating DIRECTORY.md
e0d7ba5
Merge branch 'TheAlgorithms:master' into print
tianyizheng02 5ba6e06
updating DIRECTORY.md
375fa3f
Apply suggestions from code review
cclauss 1715bad
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
""" | ||
this is code for forecasting | ||
but i modified it and used it for safety checker of data | ||
for ex: you have a online shop and for some reason some data are | ||
for ex: you have an online shop and for some reason some data are | ||
missing (the amount of data that u expected are not supposed to be) | ||
then we can use it | ||
*ps : 1. ofc we can use normal statistic method but in this case | ||
|
@@ -91,14 +91,14 @@ def interquartile_range_checker(train_user: list) -> float: | |
return low_lim | ||
|
||
|
||
def data_safety_checker(list_vote: list, actual_result: float) -> None: | ||
def data_safety_checker(list_vote: list, actual_result: float) -> bool: | ||
""" | ||
Used to review all the votes (list result prediction) | ||
and compare it to the actual result. | ||
input : list of predictions | ||
output : print whether it's safe or not | ||
>>> data_safety_checker([2,3,4],5.0) | ||
Today's data is not safe. | ||
>>> data_safety_checker([2, 3, 4], 5.0) | ||
False | ||
""" | ||
safe = 0 | ||
not_safe = 0 | ||
|
@@ -107,50 +107,54 @@ def data_safety_checker(list_vote: list, actual_result: float) -> None: | |
safe = not_safe + 1 | ||
else: | ||
if abs(abs(i) - abs(actual_result)) <= 0.1: | ||
safe = safe + 1 | ||
safe += 1 | ||
else: | ||
not_safe = not_safe + 1 | ||
print(f"Today's data is {'not ' if safe <= not_safe else ''}safe.") | ||
not_safe += 1 | ||
return safe > not_safe | ||
|
||
|
||
# data_input_df = pd.read_csv("ex_data.csv", header=None) | ||
data_input = [[18231, 0.0, 1], [22621, 1.0, 2], [15675, 0.0, 3], [23583, 1.0, 4]] | ||
data_input_df = pd.DataFrame(data_input, columns=["total_user", "total_even", "days"]) | ||
if __name__ == "__main__": | ||
# data_input_df = pd.read_csv("ex_data.csv", header=None) | ||
data_input = [[18231, 0.0, 1], [22621, 1.0, 2], [15675, 0.0, 3], [23583, 1.0, 4]] | ||
data_input_df = pd.DataFrame( | ||
data_input, columns=["total_user", "total_even", "days"] | ||
) | ||
|
||
""" | ||
data column = total user in a day, how much online event held in one day, | ||
what day is that(sunday-saturday) | ||
""" | ||
""" | ||
data column = total user in a day, how much online event held in one day, | ||
what day is that(sunday-saturday) | ||
""" | ||
|
||
# start normalization | ||
normalize_df = Normalizer().fit_transform(data_input_df.values) | ||
# split data | ||
total_date = normalize_df[:, 2].tolist() | ||
total_user = normalize_df[:, 0].tolist() | ||
total_match = normalize_df[:, 1].tolist() | ||
|
||
# for svr (input variable = total date and total match) | ||
x = normalize_df[:, [1, 2]].tolist() | ||
x_train = x[: len(x) - 1] | ||
x_test = x[len(x) - 1 :] | ||
|
||
# for linear reression & sarimax | ||
trn_date = total_date[: len(total_date) - 1] | ||
trn_user = total_user[: len(total_user) - 1] | ||
trn_match = total_match[: len(total_match) - 1] | ||
|
||
tst_date = total_date[len(total_date) - 1 :] | ||
tst_user = total_user[len(total_user) - 1 :] | ||
tst_match = total_match[len(total_match) - 1 :] | ||
|
||
|
||
# voting system with forecasting | ||
res_vote = [] | ||
res_vote.append( | ||
linear_regression_prediction(trn_date, trn_user, trn_match, tst_date, tst_match) | ||
) | ||
res_vote.append(sarimax_predictor(trn_user, trn_match, tst_match)) | ||
res_vote.append(support_vector_regressor(x_train, x_test, trn_user)) | ||
|
||
# check the safety of todays'data^^ | ||
data_safety_checker(res_vote, tst_user) | ||
# start normalization | ||
normalize_df = Normalizer().fit_transform(data_input_df.values) | ||
# split data | ||
total_date = normalize_df[:, 2].tolist() | ||
total_user = normalize_df[:, 0].tolist() | ||
total_match = normalize_df[:, 1].tolist() | ||
|
||
# for svr (input variable = total date and total match) | ||
x = normalize_df[:, [1, 2]].tolist() | ||
x_train = x[: len(x) - 1] | ||
x_test = x[len(x) - 1 :] | ||
|
||
# for linear regression & sarimax | ||
trn_date = total_date[: len(total_date) - 1] | ||
trn_user = total_user[: len(total_user) - 1] | ||
trn_match = total_match[: len(total_match) - 1] | ||
|
||
tst_date = total_date[len(total_date) - 1 :] | ||
tst_user = total_user[len(total_user) - 1 :] | ||
tst_match = total_match[len(total_match) - 1 :] | ||
|
||
# voting system with forecasting | ||
res_vote = [ | ||
linear_regression_prediction( | ||
trn_date, trn_user, trn_match, tst_date, tst_match | ||
), | ||
sarimax_predictor(trn_user, trn_match, tst_match), | ||
support_vector_regressor(x_train, x_test, trn_user), | ||
] | ||
|
||
# check the safety of today's data | ||
not_str = "" if data_safety_checker(res_vote, tst_user) else "not " | ||
print("Today's data is {not_str}safe.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cclauss This string needs to be an f-string for |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.