Very simple support vector machine by Java
Download the MNIST or EMNIST dataset from here.
Change your path in trainFile and testFile.
public String trainFile = "/home/vietbt/java/mnist_digits_train.txt";
public String testFile = "/home/vietbt/java/mnist_digits_test.txt";
More information about MNIST or EMNIST datasets is in here. After that, run this code with your Java IDE or by linux command line:
javac tinySVM.java
java tinySVM
If you have a java memory heap error, reduce batchSize to smaller.
The update version can run with maximum 10 CPUs and return the best result after serval hours.
- Best test accuracy: 98.47% after 112 steps
- Confusion matrix:
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 993 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 2 | 0 |
1 | 2 | 993 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 1 |
2 | 2 | 4 | 989 | 4 | 2 | 0 | 0 | 2 | 0 | 2 |
3 | 0 | 1 | 6 | 984 | 0 | 4 | 1 | 4 | 8 | 1 |
4 | 1 | 2 | 1 | 1 | 984 | 1 | 2 | 3 | 3 | 5 |
5 | 0 | 0 | 1 | 5 | 2 | 991 | 4 | 2 | 4 | 5 |
6 | 0 | 0 | 0 | 0 | 0 | 3 | 992 | 2 | 2 | 2 |
7 | 1 | 0 | 1 | 1 | 2 | 0 | 0 | 983 | 5 | 7 |
8 | 1 | 0 | 1 | 4 | 4 | 0 | 0 | 2 | 972 | 11 |
9 | 0 | 0 | 0 | 1 | 5 | 1 | 0 | 2 | 1 | 966 |
Bui The Viet - FPT University - vietpro213tb@gmail.com