normalization wikipedia https en wikipedia orgwikinormalization normalization 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 is xnorm x xminxmax xmin where xnorm is the normalized value x is the value xmin is the minimum value within the column or list of data and xmax is the maximum value within the column or list of data normalization is used to speed up the training of data and put all of the data on a similar scale this is useful because variance in the range of values of a dataset can heavily impact optimization particularly gradient descent standardization wikipedia https en wikipedia orgwikistandardization standardization is the process of converting numerical data to a normally distributed range of values this range will have a mean of 0 and standard deviation of 1 this is also known as zscore normalization the equation for standardization is xstd x musigma where mu is the mean of the column or list of values and sigma is the standard deviation of the column or list of values choosing between normalization standardization is more of an art of a science but it is 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 standardization 2 nongaussian nonnormal distributions work better with normalization 3 if a column or list of values has extreme values outliers use standardization 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 normalization2 7 10 20 30 50 0 0 0 104 0 167 0 375 0 583 1 0 normalization5 10 15 20 25 0 0 0 25 0 5 0 75 1 0 variables for calculation normalize data 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 standardization2 7 10 20 30 50 0 999 0 719 0 551 0 009 0 57 1 69 standardization5 10 15 20 25 1 265 0 632 0 0 0 632 1 265 variables for calculation standardize data 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 10 15 20 25 0 0 0 25 0 5 0 75 1 0 variables for calculation normalize data 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 standardization 5 10 15 20 25 1 265 0 632 0 0 0 632 1 265 variables for calculation standardize data
from statistics import mean, stdev


def normalization(data: list, ndigits: int = 3) -> list:
    
    
    x_min = min(data)
    x_max = max(data)
    
    return [round((x - x_min) / (x_max - x_min), ndigits) for x in data]


def standardization(data: list, ndigits: int = 3) -> list:
    
    
    mu = mean(data)
    sigma = stdev(data)
    
    return [round((x - mu) / (sigma), ndigits) for x in data]