Today I Learnt — 09/12/23

Jahnvi Singh
4 min readDec 9, 2023

--

  1. Numpy Seed Function — numpy.random.seed(int_value)

Apparently, random numbers generated in python are not completely random. Instead, they are generated using certain functions.

By using the “seed” function, you can define exactly which set of random numbers you are going to use.

For example —

import numpy
numpy.random.seed(10)
num_arr = numpy.random.rand(5)
print(num_arr)

Here, firstly numpy library is imported and seed is set to 10. Then an array is created by numpy.random.rand() function with 5 random integers between 0 and 1. and lastly this list is printed. Easy and simple!

Now every time we will run this block of code we’ll get the same set of numbers in our list. In this case, it will be :

[0.77132064 0.02075195 0.63364823 0.74880388 0.49850701]

Try copy-pasting the above code and you too will get the same array, even though we’re calling it random.

This is because when you ask a computer for a random number, it doesn’t just pick a number out of thin air. It uses a mathematical formula called a random number generator to create that number. However, this process is actually deterministic — meaning that if you start from the same initial conditions, you’ll get the same sequence of “random” numbers every time.

The np.random.seed() function sets the initial condition for the random number generator in NumPy. When you set the seed to a specific value (for example, np.random.seed(10)), you're telling the random number generator to start from this specific point in its sequence.

This is helpful when you want to:

  1. Reproduce results: If you’re doing some experiment or simulation that involves randomness, setting the seed ensures that others can replicate your exact results.
  2. Debugging: If you encounter an issue in your code that involves randomness, setting the seed allows you to trace and debug the issue more easily because the same sequence of “random” numbers will be generated every time you run the code.

2. Normalization — In statistics, the term “normalization” refers to the scaling down of the data set such that the normalized data falls between 0 and 1. This normalization technique helps compare corresponding normalized values from two or more data sets.

Maths or Statistics is better to understand through questions or examples rather than pages and pages of incomprehensible theory.

So here’s an example to show what normalization actually means.

Take a data set that represents the test marks scored by 10 students during a test. Present the test scores of all the students in the range of 0 to 1 with the help of a normalization technique. The original test scores (out of 100) are as follows:

Now using a simple normalization formula, we’ll find the normalized value for each score in this data. The formula used here is as follows :

x normalized = (xx minimum) / (x maximum — x minimum)

Using the above formula we get the normalized values as follows :

Normalization can be understood as similar to finding percentages.

Assume you score 20 out of 25 on a test. Then finding your percentage means how much you would have scored if total marks was 100. So scoring 20 out of 25 would mean same as scoring 80 out of 100. Finding percentages makes comparing easier i.e, if you score 25 out of 30 next time, that would mean you scored 83.33%. So now you’d know that you performed better in the second test, even though the total scores were different.

Similarly, if you have 2 different datasets whose value range is different, then it will not be easy to compare them or find relation between them. Here you can use normalization, and scale down the values to the same range(just like finding a percentage out of 100). In our case, it was between 0 and 1.

You can see this by plotting a graph.

Since the normalized values are between 0 and 1, the graph is not very clear hear. So while plotting the graph, I multiplied the normalized values with 91(max value from our data). The result is shown below :

Credit : https://www.wallstreetmojo.com/normalization-formula/

This was all for today. Happy Learning!!

--

--

Jahnvi Singh
Jahnvi Singh

No responses yet