"""Normalization Wikipedia: https://en.wikipedia.org/wiki/NormalizationNormalization is the process of converting numerical data to a standard range of values.This range is typically between [0, 1] or [-1, 1]. The equation for normalization isx_norm = (x - x_min)/(x_max - x_min) where x_norm is the normalized value, x is thevalue, x_min is the minimum value within the column or list of data, and x_max is themaximum value within the column or list of data. Normalization is used to speed up thetraining of data and put all of the data on a similar scale. This is useful becausevariance in the range of values of a dataset can heavily impact optimization(particularly Gradient Descent).Standardization Wikipedia: https://en.wikipedia.org/wiki/StandardizationStandardization is the process of converting numerical data to a normally distributedrange of values. This range will have a mean of 0 and standard deviation of 1. This isalso known as z-score normalization. The equation for standardization isx_std = (x - mu)/(sigma) where mu is the mean of the column or list of values and sigmais the standard deviation of the column or list of values.Choosing between Normalization & Standardization is more of an art of a science, but itis often recommended to run experiments with both to see which performs better.Additionally, a few rules of thumb are:1. gaussian (normal) distributions work better with standardization2. non-gaussian (non-normal) distributions work better with normalization3. If a column or list of values has extreme values / outliers, use standardization"""from statistics import mean, stdevdef normalization(data: list, ndigits: int = 3) -> list:"""Returns 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, 10, 15, 20, 25])[0.0, 0.25, 0.5, 0.75, 1.0]"""# variables for calculationx_min = min(data)x_max = max(data)# normalize datareturn [round((x - x_min) / (x_max - x_min), ndigits) for x in data]def standardization(data: list, ndigits: int = 3) -> list:"""Returns 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]>>> standardization([5, 10, 15, 20, 25])[-1.265, -0.632, 0.0, 0.632, 1.265]"""# variables for calculationmu = mean(data)sigma = stdev(data)# standardize datareturn [round((x - mu) / (sigma), ndigits) for x in data]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。