MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / standardization

Function standardization

machine_learning/data_transformations.py:51–67  ·  view source on GitHub ↗

Return a standardized list of values. @params: data, a list of values to standardize @returns: a list of standardized values (rounded to ndigits decimal places) @examples: >>> standardization([2, 7, 10, 20, 30, 50]) [-0.999, -0.719, -0.551, 0.009, 0.57, 1.69] >>> standa

(data: list, ndigits: int = 3)

Source from the content-addressed store, hash-verified

49
50
51def standardization(data: list, ndigits: int = 3) -> list:
52 """
53 Return a standardized list of values.
54
55 @params: data, a list of values to standardize
56 @returns: a list of standardized values (rounded to ndigits decimal places)
57 @examples:
58 >>> standardization([2, 7, 10, 20, 30, 50])
59 [-0.999, -0.719, -0.551, 0.009, 0.57, 1.69]
60 >>> standardization([5, 10, 15, 20, 25])
61 [-1.265, -0.632, 0.0, 0.632, 1.265]
62 """
63 # variables for calculation
64 mu = mean(data)
65 sigma = stdev(data)
66 # standardize data
67 return [round((x - mu) / (sigma), ndigits) for x in data]

Callers

nothing calls this directly

Calls 1

meanFunction · 0.85

Tested by

no test coverage detected