Posts

Showing posts from January, 2018

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 #22: [Find x and y satisfying ax + by = c]

Image
Given a, b and n. Find x and y that satisfies ax + by = n. Print any of the x and y satisfying the equation.    (-1000<=a,b,c<=1000)   Solution: So solving this equation with pen and paper gives y=(n-ax)/b and similarly we get the other number to be x=(n-by)/a. 

Artificial Intelligence #9: Traffic counting based on OpenCV

Image

Artificial Intelligence #8: Facial Recognition

Image

Artificial Intelligence #7: How do you describe what AI can do ?

Image

Competitive Programming #21: [ Sum of first n terms ]

Image
Given and integer n . Print the sum of series 1 3 + 2 3 + 3 3 + 4 3 + …….+ n 3 till n-th term. Input: The first line consists of an integer T i.e number of test cases. The first and only line of each test case consists of an integer n . As the output could be large so take mod with 10 9 +7. Output: Print the required sum. Constraints:   1<=T<=100 1<=n<=10 9 Example: Input: 2 5 7 Output: 225 784 Solution:    

Competitive Programming #20: [Non-Repeating Element]

Image
Find the first non-repeating element in a given array of integers. Note: Array consists of only positive and negative integers and not zero. Input: The first line of input is an integer T, denoting the number of test cases. Each test case has subsequent two lines of input. First line is an integer N, denoting size of integer array A. Second line consists of N space separated integers of the array A. Output: The only line of output for each test case is the first non-repeating element in the array A. If there is no such element, print 0 as the output. Constraints: 1<=T<=100; 1<=N<=100; A[i] belongs to [-100,100]-{0}, where i is an integer denoting index of array. Example: Input: 4 5 -1 2 -1 3 2 6 9 4 9 6 7 4 3 1 1 1 2 -3 2 Output: 3 6 0 -3 Explanation: In the first test case, -1 and 2 are repeating whereas 3 is the only number occuring once. Hence, the output is 3. In the second test case, there are 3 distinct...

Competitive Programming #19: [Check if array contains contiguous integers with duplicates allowed]

Image
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 a[i]<=10 5   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 element s of array . _____________________________________________________________ Solu...

Competitive Programming #18 : [Close to Perfection]

Image
Geek likes this girl Garima from his neighborhood, and wants to impress her so that she may go on a date with him. Garima is a Perfectionist and likes only PERFECT things . This makes Geek really nervous, and so Geek asks for your Help.! Geek has baked a cake for Garima, which is basically an array of Numbers. Garima will take only a Perfect Piece of the cake. A Perfect Piece is defined  as -  a subarray such that the difference between the minimum and the maximum value in that range is at most 1. Now, Since garima just loves cake, She wants a Perfect Piece Of Maximum length possible. Help Geek go on a date.! Input The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains an integer n-denoting the length of the array. The second line contains n space separated integers -denoting the cake Output For each  testcase , output a single line containing the maximum Possible length of the s...

Competitive Programming #17 : [Find whether path exist]

Image
Given a N X N matrix (M) filled with 1 , 0 , 2 , 3 . Your task is to find whether there is a path possible from source to destination, while traversing through blank cells only. You can traverse up, down, right and left. A value of cell  1  means Source. A value of cell  2  means Destination. A value of cell  3  means Blank cell. A value of cell 0  means Blank Wall. Note : there is only single source and single destination. Examples: Input : M[3][3] = {{ 0 , 3 , 2 }, { 3 , 3 , 0 }, { 1 , 3 , 0 }}; Output : Yes Input : M[4][4] = {{ 0 , 3 , 1 , 0 }, { 3 , 0 , 3 , 3 }, { 2 , 3 , 0 , 3 }, { 0 , 3 , 3 , 3 }}; Output : Yes Input: The first line of input is an integer T denoting the no of test cases. Then T test cases follow. Each test case consists of 2 lines . The first line of each test case contains an integer N denoting the ...