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 #3: [Fact Digit Sum]

Here is the problem: 

Let's define A(n) for positive integer n as a sum of factorials of its digits. For example, A(154)=1!+ 5! +4!= 145.
Given a number 'x' , you need to print the minimum number L such that A(L)=x. If no such L exists, then print -1
Input:
First line contains 'T' - the number of test cases
Then each line contains an integer 'x'.

Output:
Print the answer for each value 'x'.

Constraints:
1<=T<=542
1000<=x<=1000000000

Example:
Input:

1
40321
Output:
18

Explanations:
A(18)=1!+ 8! =40321  and 18 is the smallest element for which A(18) is 40321
Note that A(80) = A(81) is also 40321, But among them 18 is the smallest number.


Solution:
Another interesting problem. I thought it is hard problem but actually it is very easy.(Dont worry I am not good at all with competitive programming  :D )
The approach is with Greedy Algorithm ... So we have:



It is with recursive function , if u still dont understand recursion , u can use 'for'
factoriels[9] = {1! , 2!, 3! , 4! , 5! , 6! , 7! , 8! , 9!}
Example:

5
RecursiveF(5,factoriels[9], 8 , facts);
   ->else

         -> if(factoriels[8] > 5) ? YES #RecursiveF(5,factoriels[9],7,facts) ; 
(so now repeat the step until factioriel[i] < = 5)
        (after that) ->else #facts.push_back(2);
#RecursiveF(2,factoriels[9],1,facts) ; 
(repeat until n!=0, when n==0 , it gonna output  the reserve order of elements in array facts)
 
 

Popular posts from this blog

Math Problem -> Combinatorics: Foreign alphabet

Competitive Programming #29 : [LineUp]

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