Logistic Regression vs. SVM

Logistic Regression and SVM often give the similar results. SVM costs longer to train than logistic regression, so it seems that there is no obvious reason to use SVM. Actually, in industry logistic regression is the most frequently used algorithm.

The reason that logistic regression and SVM have similar performance is that the training data is linearly separable, which happens very often. Therefore, there is no need to project the value to a higher dimension to separate them.

Read more

Get Target Number Using Number List and Arithmetic Operations

Given a list of numbers and a target number, write a program to determine whether the target number can be calculated by applying “+-*/” operations to the number list? You can assume () is automatically added when necessary. An operator should be put between each two consecutive numbers. So each number has to be used.

For example, given {1,2,3,4} and 21, return true. Because (1+2)*(3+4)=21

Read more

LeetCode -Toeplitz Matrix

A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Given a matrix, check if it is toeplitz. (Assume the matrix is not empty) Java Solution public boolean isToeplitzMatrix(int[][] matrix) { int m=matrix.length; int n=matrix[0].length; for(int i=0; i<m; i++){ for(int j=0; j<n; j++){ if(i+1<m && j+1<n && matrix[i][j]!=matrix[i+1][j+1]){ return false; … Read more

LeetCode – Rotated Digits (Java)

X is a good number if after rotating EACH digit individually by 180 degrees, we get a valid number that is different from X. A number is valid if each digit remains a digit after rotation. 0, 1, and 8 rotate to themselves; 2 and 5 rotate to each other; 6 and 9 rotate to each other, and the rest of the numbers do not rotate to any other number.

Read more

Top 16 Java Utility Classes

In Java, a utility class is a class that defines a set of methods that perform common functions. This post shows the most frequently used Java utility classes and their most commonly used methods. Both the class list and their method list are ordered by popularity. The data is based on randomly selected 50,000 open source Java projects from GitHub.

Read more

LeetCode – Count of Smaller Numbers After Self (Java)

You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i]. Example: Input: [5,2,6,1] Output: [2,1,1,0] Java Solution 1 public List<Integer> countSmaller(int[] nums) { List<Integer> result = new ArrayList<Integer>(); ArrayList<Integer> sorted … Read more

LeetCode – Minimum Increment to Make Array Unique (Java)

Java Solution 1 public int minIncrementForUnique(int[] A) { Arrays.sort(A);   int count = 0; for(int i=1; i<A.length; i++){ if(A[i]<=A[i-1]){ count+=A[i-1]+1; A[i]=A[i]+1; } }   return count; }public int minIncrementForUnique(int[] A) { Arrays.sort(A); int count = 0; for(int i=1; i<A.length; i++){ if(A[i]<=A[i-1]){ count+=A[i-1]+1; A[i]=A[i]+1; } } return count; } Actually we do not need to increment … Read more

Compile and run Eclipse Java projects from Linux terminal

If you are developing a Java project in Eclipse under a linux system, you may want to remote access the project from another location. You can remote desktop the linux box by using teamviewer, but sometimes that can be very slow. You can also edit, compile and execute your Java project from a regular ssh terminal. Using terminal to edit, compile and run your remote eclipse project is often faster. This post shows you how to compile and run eclipse project in terminal.

Read more