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) False
(list_vote: list, actual_result: float)
| 96 | |
| 97 | |
| 98 | def data_safety_checker(list_vote: list, actual_result: float) -> bool: |
| 99 | """ |
| 100 | Used to review all the votes (list result prediction) |
| 101 | and compare it to the actual result. |
| 102 | input : list of predictions |
| 103 | output : print whether it's safe or not |
| 104 | >>> data_safety_checker([2, 3, 4], 5.0) |
| 105 | False |
| 106 | """ |
| 107 | safe = 0 |
| 108 | not_safe = 0 |
| 109 | |
| 110 | if not isinstance(actual_result, float): |
| 111 | raise TypeError("Actual result should be float. Value passed is a list") |
| 112 | |
| 113 | for i in list_vote: |
| 114 | if i > actual_result: |
| 115 | safe = not_safe + 1 |
| 116 | elif abs(abs(i) - abs(actual_result)) <= 0.1: |
| 117 | safe += 1 |
| 118 | else: |
| 119 | not_safe += 1 |
| 120 | return safe > not_safe |
| 121 | |
| 122 | |
| 123 | if __name__ == "__main__": |