Posts

Showing posts from December, 2017

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 #16: [Fast and Efficient Method to Check Sum Of The Digits In Number is Multiple Of 3]

Image
The very first solution that comes to our mind is the one that we learned in school. If sum of digits in a number is multiple of 3 then number is multiple of 3 e.g., for 612 sum of digits is 9 so it’s a multiple of 3. But this solution is not efficient. You have to get all decimal digits one by one, add them and then check if sum is multiple of 3. There is a pattern in binary representation of the number that can be used to find if number is a multiple of 3. If difference between count of odd set bits (Bits set at odd positions) and even set bits is multiple of 3 then is the number. Example: 23 (00..10111) 1) Get count of all set bits at odd positions (For 23 it’s 3). 2) Get count of all set bits at even positions (For 23 it’s 1). 3) If difference of above two counts is a multiple of 3 then number is also a multiple of 3. (For 23 it’s 2 so 23 is not a multiple of 3) Take some more examples like 21, 15, etc… Solution:  

Competitive Programming #15 : [Count unset bits in a given Range]

Image
Given a non-negative number  n  and two values  l  and  r . The problem is to count the number of unset bits in the range  l  to  r  in the binary representation of  n , i.e. to count unset bits from the rightmost  lth  bit to the rightmost  rth  bit. Examples: Input : n = 42, l = 2, r = 5 Output : 2 (42) 10 = (1 0101 0) 2 There are '2' unset bits in the range 2 to 5. Input : n = 80, l = 1, r = 4 Output : 4   Input: The first line of the input contains a single integer T , denoting the number of test cases. Then T test cases follow. Each test-case has one line of the input, the line contains three integers n , l and r . Output: Print the required output. Constraints: 1<=T<=100 1<=n<=100000 Examples: Input: 2 64 4 7 80 1 4 Output: 3 4 Solution:    The most important thing is RANGE in that number !!!

Competitive Programming #14: [Maximize the volume of Cuboid]

Image
Given the sum of length, breadth and height of a cuboid. The task is to find the maximum volume that can be achieved such that the sum of sides is S. Input: The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer S. Output: For each test case, print the maximum volume you can obtain in new line. Constraints: 1<=T<=500 3<=S<=10 5 Example: Input: 2 4 8 Output: 2 18 Explanation: Input : S = 8 Output : 18 All possible edge dimensions: [1, 1, 6], volume = 6 [1, 2, 5], volume = 10 [1, 3, 4], volume = 12 [2, 2, 4], volume = 16 [2, 3, 3], volume = 18   Solution:   Lets give our examples: INPUT: 3 65 21 31  1# Sum_Of_Sides = 65; We check if Sum_Of_Sides is divisible by 3. No it isn't Check if Sum_Of_Sides modul by 3 has remindеr 1. No, it hasn't So Sum_Of_Sides % 3 = 2 print (Sum_Of_Sides ➗3 + 1 ) ^2 * (Sum_Of_Sides ➗ 3...

Competitive Programming #13 : [The Mighty Divisible Number]

Image
Given four numbers X, Y, Z and N . Your task is to find smallest N digit Number that is divisible by all the three numbers X, Y and Z . Note: If no such number can be formed then print "-1". Input: The first line of the input contains an integer T , denoting the number of test cases. Then T test case follows. The only line of each test case contains four space separated integers denoting the values of X, Y, Z and N respectively. Output: For each test case output the smallest N digit number divisible by X, Y and Z. If no such number can be formed then print "-1" . Constraints: 1<=T<=10 3 1<=X,Y,Z<=10 3 1<=N<=18 Example: Input: 3 2 3 5 4 4 5 6 3 3 5 7 2 Output: 1020 120 -1 Solution:   So how gonna this works ? The most important thing here is LCM (x,y,z); if LCM is greater or equal ten*10 it is impossible to get result about any three numbers (ten is smallest n digits number, example: the smallest 3 digits nu...

Competitive Programming #12 : [Count numbers with unit digit K in given range]

Image
I had exams this week and finally its f****** over . So we continue with our competitive programming problems. This is the problem: Given a range from low to high and a number K. The task is to count the number which has the unit digit equal to K. Input: The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains three numbers low, high and K. Output: For each test case, print the count  of numbers in new line. Constraints: 1<=T<=100 1<=low<=high<=10 9 0<=K<=9 Example: Input: 2 4 9 4 3 35 3 Output: 1 4 Explanation: Input : low = 3, high = 35, K = 3 Output : 4 Numbers are 3, 13, 23, 33.   Solution :    

Artificial Intelligence #8: Using of Machine Learning

Image

Technology Things #6 : [ Q# New Quantum Programming Language by Microsoft]

Image

Artificial Intelligence #7: [First Minister of State for AI]

Image

Artificial Intelligence #6

Image

Competitive Programming #11: [Find the Shortest Path in Graph with BFS]

Image
I have no specific explanation here ! You can find out what is the point of this code !!!

Competitive Programming #10: [Connected graph, cycles, edges,BiParity]

Image
We have graph : (Its bad but is okay as example 😀😀😀) 1. Check if graph is connected at all ! (Are all nodes are connected) 2. Are there any cycles ?! 3. How many edges has in this graph?! 4. Check if graph is BiParity (No adjacent nodes are even or odd numbers) Here is the Code: Simply use Depth-First Search (is more better choice,cause it is easier to implement).