Return a normalized list of values. @params: data, a list of values to normalize @returns: a list of normalized values (rounded to ndigits decimal places) @examples: >>> normalization([2, 7, 10, 20, 30, 50]) [0.0, 0.104, 0.167, 0.375, 0.583, 1.0] >>> normalization([5, 1
(data: list, ndigits: int = 3)
| 30 | |
| 31 | |
| 32 | def normalization(data: list, ndigits: int = 3) -> list: |
| 33 | """ |
| 34 | Return a normalized list of values. |
| 35 | |
| 36 | @params: data, a list of values to normalize |
| 37 | @returns: a list of normalized values (rounded to ndigits decimal places) |
| 38 | @examples: |
| 39 | >>> normalization([2, 7, 10, 20, 30, 50]) |
| 40 | [0.0, 0.104, 0.167, 0.375, 0.583, 1.0] |
| 41 | >>> normalization([5, 10, 15, 20, 25]) |
| 42 | [0.0, 0.25, 0.5, 0.75, 1.0] |
| 43 | """ |
| 44 | # variables for calculation |
| 45 | x_min = min(data) |
| 46 | x_max = max(data) |
| 47 | # normalize data |
| 48 | return [round((x - x_min) / (x_max - x_min), ndigits) for x in data] |
| 49 | |
| 50 | |
| 51 | def standardization(data: list, ndigits: int = 3) -> list: |
nothing calls this directly
no outgoing calls
no test coverage detected