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 #19: [Check if array contains contiguous integers with duplicates allowed]

Given an array of n integers(duplicates allowed). Print “Yes” if it is a set of contiguous integers else print “No”.

INPUT: The first line consists of an integer T i.e. the number of test cases. First line of each test case consists of an integer n, denoting the size of array. Next line consists of n spaced integers, denoting elements of array.

OUTPUT:  Print “Yes” if it is a set of contiguous integers else print “No”.

CONSTRAINTS:
1<=T<=100
1<=n<100000 br=""> a[i]<=105

 Example:
 2
8
5  2  3  6  4  4  6  6

7
10  14  10  12  12  13  15

Output :
 Yes
 No

Explanation:
Test Case 1 : The elements  of array form a contiguous set of integers which is {2, 3, 4, 5, 6} so the output is Yes.
Test Case 2: We are unable to 
form contiguous set of integers using elements of array.

_____________________________________________________________
Solution: 

 
Lets take a example like this one
8

1 2 3 4 6 7 8 9
in our array contg_numbers we have
                               0     1     2      3    4      5      6    7     8     9
contg_numbers={false,true,true,true,true,false,true,true,true,true,.....}
Variable 'flag' is until it find TRUE value...and its flow until it find FALSE.'.flag1' is if find another TRUE then 'flag'=true
in our example we have
if contg_numbers[0]=true AND flag=false -> (TRUE) ->  flag=true
i=1;

if contg_numbers[1]=true AND flag=false -> (NO)-> /
else if contg_numbers[1]=false AND flag=true -> (NO) ->
else if contg_numbers[1]=true  AND flag1=true ->NO ->
until 5 then  we have
ELSE IF congt_numbers[5]=false AND flag=true  ->(YES) ->flag1=true
i=6;
ELSE IF contg_numbers[6]=true AND flag1=true -> (YES) -> flag=false; break;
and Output will be "No"

Popular posts from this blog

Math Problem -> Combinatorics: Foreign alphabet

Competitive Programming #29 : [LineUp]

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