MeanNearestNeighbors (MNN) - algorithm for balancing dataset - In progress #1

Image
One of the challenges in classification problems are unbalanced datasets. I was Data Science Intern when the company that I worked for, assigned me such an interesting challenge where the dataset was unbalanced.  However, I realized this type of problem like unbalanced dataset is а common thing in real life. I tried most of the algorithms (undersampling, oversampling) like SMOTE, NearMiss, CondensedNearestNeighbors, RandomUnderSampler, RandomOverSampler,  KMeansSMOTЕ and rest of them. Anyway, they didn't help me in that case, on the contrary, they worsened my model.  I was like: "but, but, you should have been helpful in creating the predictive model" So, I'm trying to create another algorithm based on undersampling concept when it comes to balancing datasets. I called it Mean Nearest Neighbors (MNN). What's the initial idea: It's simple. Actually, the algorithm is just a modification of the other undersampling algorithms. In the data where target labe...

Competitive Programming #27 : [Reducing Walls]

Ishaan is trapped in a city full of walls. To escape from there, if needs to climb N walls, one after the other. He can climb a wall if its height is atmost K.
Ishaan also has a superpower. He can reduce the height of a wall by K by using his superpower once. Since he can't use this power many times, calculate the minimum number of times he has to use this power to go over all the walls.

Input : 
First line of input contains a single integer T denoting the number of test cases.
The first line of each test case contains 2 space-separated integers N and K.
The second line contains N space-separated integers denoting the heights of the walls.

Output : 
For each test case, print the required answer in a new line.

Constraints : 
1 <= T <= 100
1 <= N <= 250
1 <= K <= 10^5
1 <= Height of a Wall <= 10^9

Example :
Input : 

3
5 5
5 3 2 6 8
6 4
2 6 4 8 1 6
4 3
2 2 2 2
Output : 
2
3
0

Explanation : 
Case 1 : 

Heights : 5 3 2 6 8
Ishaan can climb a wall with height atmost 5. So he climbs the first 3 walls easily.
Now he has to use his power to reduce the height of the 4th wall.
After using his power, heights : 5 3 2 1 8
Now to climb the last wall, he again uses his power.
Final heights : 5 3 2 1 3

Case 2 : 
Heights : 2 4 6 8 1 6
Ishaan can climb a wall with height atmost 4. So he climbs the first 2 walls easily.
Now he has to use his power to reduce the height of the 3rd wall.
After using his power, heights : 2 4 2 8 1 6
Now to climb the next wall, he again uses his power.
Heights : 2 4 2 4 1 6
He climbs the 5th wall easily.
To climb the last wall, h uses his power again.
Final Heights : 2 4 2 4 1 2

Case 3 : 
Since all the heights are already below K(=3), Ishaan can climb all the walls without using his powers.


Solution:
---------------------------------------- 
I was afraid of this problem too ... Not cause I thought it is hard, but how many submissions were sent and were incorrect .
(GeeksForGeeks is the platform where I  solve problems) 
So I read the problem and I said 'Hey this is easy , why so  incorrect submissions , where programmers stuck ? ' 
The only thing here is to count how many elements are bigger than Ishaan's SUPERPOWER and to reduce it ...

Popular posts from this blog

Math Problem -> Combinatorics: Foreign alphabet

Competitive Programming #29 : [LineUp]

Intro to Quantum Computing: Што ќе ми треба ова сега? #1