# Min Max Normalization Python and Matlab – Data Mining

## Min Max Normalization Python and Matlab – Data Mining

Min Max Normalization in Python and Matlab is today topic of discussion in this tutorial. Min-Max normalization is very helpful in data mining, mathematics, and statistics. Hopefully, you will get benefit from this.

## Data Before and After Normalization

Let’s see in the figure, the data before and after min-max normalization. ## Min Max Normalization Python Source Code

Lets see the source code of Min Max Normalization in Python.

def __normalize(self , data ) :
# Save the Real shape of the Given Data
shape = data.shape
# Smoothing the  Given Data Valuesto 1 dimension
data = np.reshape( data , (-1 , ) )
# Find MinValue and MaxValue
MaxValue = np.max( data )
MinValue = np.min( data )
# Normalized values are store in a newly created array
normalized_values = list()
# Iterate through every value in data
for AttributeValue in the given data:
# Normalize
AttributeValue_normalized = (AttributeValue – MinValue ) / ( MaxValue – MinValue )
# Append it in the array
normalized_values.append( AttributeValue_normalized )
# Convert to numpy array
n_array = np.array( normalized_values )
# Reshape the array to its Real shape and return it.
return np.reshape( n_array , shape )

Explanation of the code

# Save the Real shape of the Given Data
shape = data.shape
# Smoothing the  Given Data Values to 1 dimension
data = np.reshape( data , (-1 , ) )

Some further steps:

1. We need to Save the Real shape of the data.
2. We need to smooth the given data.
3. The data is reshaped to a single-dimension.

# Find MinValue and MaxValue
MaxValue = np.max( data )
MinValue = np.min( data )

1. Then, we find the MinValue and MaxValue of the data.

normalized_values = list()
# Iterate through every value in data
for AttributeValue in the given data:
# Normalize
AttributeValue_normalized = (AttributeValue – MinValue ) / ( MaxValue – MinValue )
# Append it in the array
normalized_values.append( AttributeValue_normalized )
5. After normalization, we can Save it in the normalized_values list.

# Convert to numpy array
n_array = np.array( normalized_values )
# Reshape the array to its Real shape and return it.
return np.reshape( n_array , shape )

Latest posts by Prof. Fazal Rehman Shamil (see all)