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 #29 : [LineUp]

To prepare his students for an upcoming game, the sports coach decides to try some new training drills. To begin with, he lines them up and starts with the following warm-up exercise: when the coach says 'L', he instructs the students to turn to the left. Alternatively, when he says 'R', they should turn to the right. Finally, when the coach says 'A', the students should turn around.
Unfortunately some students (not all of them, but at least one) can't tell left from right, meaning they always turn right when they hear 'L' and left when they hear 'R'. The coach wants to know how many times the students end up facing the same direction.
Given the list of commands the coach has given, count the number of such commands after which the students will be facing the same direction.
Example
For commands = "LLARL", the output should be
lineUp(commands) = 3.
Let's say that there are 4 students, and the second one can't tell left from right. In this case, only after the second, third and fifth commands will the students face the same direction.
Input/Output
  • [execution time limit] 0.5 seconds (cpp)
  • [input] string commands
    String consisting of characters 'L''R' and 'A' only.
    Guaranteed constraints:
    0 ≤ commands.length ≤ 35.
  • [output] integer
    The number of commands after which students face the same direction


Solution:
------------------------------------------------------------
Let's
p- students that do correct turns
l - students that do opposite turns (L -> R, R  ->L)
s - The number of commands after which students face the same direction

Thats all for variables, Next we have this
Image result for North east west east

When the student turn on the clockwise direction
it will increase his value
When  it is opposite (counterclockwise), the value will decrease
and  if value of p and l are divisible by 2 then s++;
So when the students turn left or right  their values always gonna be odd number , forward and back - even number.
With these statements, you will be able to understand the code:


Popular posts from this blog

Math Problem -> Combinatorics: Foreign alphabet

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