Skip to content

Commit dde5b32

Browse files
authored
Merge pull request #326 from Noth2006/main
New Problem : Min-Max-Normalization
2 parents 0c631f4 + a5907e1 commit dde5b32

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Min-Max Normalization
2+
3+
Min-Max Normalization is a technique used to scale numerical data between *0 and 1*. It ensures that values are transformed while maintaining their original distribution. A machine learning model usually assigns a higher weight to a feature with larger values and a lower weight to a feature with smaller values.
4+
The goal of normalization is to make every datapoint have the same scale so each feature is equally important to the model.
5+
6+
7+
The formula used for Min-Max Normalization is:
8+
9+
$$
10+
X' = \frac{X - X_{\min}}{X_{\max} - X_{\min}}
11+
$$
12+
13+
- Note 1 : In case the input array has identical elements just return an array of the same size filled with zeros.
14+
- Note 2 : Round the resultant values upto the 4th decimal place.
15+
16+
## Where:
17+
- \( X \) is the original value.
18+
- $$(X_{\min})$$ is the minimum value in the dataset.
19+
- $$( X_{\text{max}} )$$ is the maximum value in the dataset.
20+
- \( X' \) is the normalized value.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def min_max(x:list[int])->list[float]:
2+
3+
#trying to modify the input list in-place instead creating a new list
4+
5+
largest=max(x) #finding the largest value in the input array
6+
smallest=min(x) #finding the minimum value in the input array
7+
8+
if largest==smallest: # if input has identical elements
9+
return[0.0]*len(x)
10+
for i in range(len(x)):
11+
#using the formula to normalize the input
12+
x[i]=round((x[i]-smallest)/(largest-smallest),4)
13+
14+
return(x)
15+
16+
def test_min_max():
17+
#first_test_case:
18+
19+
assert min_max([1,2,3,4,5])==[0.0, 0.25, 0.5, 0.75, 1.0],"Test Case 1 failed"
20+
21+
assert min_max([30,45,56,70,88])==[0.0, 0.2586, 0.4483, 0.6897, 1.0],"Test Case 2 failed"
22+
23+
assert min_max([5,5,5,5])==[0.0,0.0,0.0,0.0], "Test Case 3 failed"
24+
25+
26+
if __name__=="__main__":
27+
test_min_max()
28+
print("All Min Max Normalization test cases passed.")
29+

0 commit comments

Comments
 (0)