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: [Summed Matrix]

Here is the problem: 
 
A matrix is constructed of size n*n. such that Mi,j= i+j.Count the number of cells having value q. Assume, 1 based indexing.

Input:
The first line contains an integer
, the number of tescases.
Then each test case contains an integer n-
size of the matrix , q- whose count you need to tell.

Output:
For every 
testcase, Output the count of q.

Constraints:
1<=T<=100
1<=n<=1000000000000000(10^16)
2<=q<=2*n

Example:
Input:

2
4 7
5 4

Output:
2
3


Explanation:
1st 
testcase- Matrix becomes
2 3 4 5
3 4 5 6
4 5 6 7
5 6 7 8

The count of 7 is 2
2nd testcase-Matrix becomes
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9
6 7 8 9 10
The count of 4 is 3

Solution:
Interesting problem ...It is more math (Math is fun :D)
You can solve this problem with Time Complexity O(1);
Input N is very very very big 10^16 , you should  use unsigned long long int (0 - 18,446,744,073,709,551,615)
So let's see the logic (algorithm)






  Here is a example :           

Popular posts from this blog

Math Problem -> Combinatorics: Foreign alphabet

Competitive Programming #29 : [LineUp]

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