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 #1: [Longest sub-sequence such that difference between adjacents is one]

Here is the problem :

Given an array of size n. The task is to find the longest subsequence such that absolute difference between adjacents is one.
                                                                                Input:
The first line consists of an integer T i.e number of test cases. The first line of each test case consists of an integer n.The next line consists of n spaced integers.
   
Output:
Print the required answer.

Constraints
1<=T<=100
1<=n,a[i]<=100000

Example:
Input:

2
7
10 9 4 5 4 8 6
8
1 2 3 2 3 7 2 1

Output:
3
7

First what comes to your mind that solution can be done with nested loops, but we see the input of elements in array is 1<=n . n can be very big number (lets say 10^5 >). So time complexity must be O(n). Here is my code:


  And this is all about the algorithm . Finally the integer maxi is that longest sub-sequence . If you don't understand this explаnation, use Debugger

Popular posts from this blog

Math Problem -> Combinatorics: Foreign alphabet

Competitive Programming #29 : [LineUp]

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