2017/8/27

Introduction

This application goals to recognize handwriting numbers with machine learning trained model.

  • The model is based on the Radial SVM algorithm.
  • The training and testing data are the MNIST dataset http://yann.lecun.com/exdb/mnist/.
  • The recognition error on the test data set is 1.98%.
  • Below is some samples of the MNIST dataset.

Training process and result

library(caret)
fit2 <- train(y ~ ., data = training, 
              method = 'svmRadial', tuneLength = 9)
fit2$results
##        sigma     C  Accuracy     Kappa   AccuracySD     KappaSD
## 1 0.01063739  0.25 0.9640127 0.9600011 0.0011739388 0.001304053
## 2 0.01063739  0.50 0.9705297 0.9672445 0.0011794591 0.001310233
## 3 0.01063739  1.00 0.9752271 0.9724656 0.0010846432 0.001205295
## 4 0.01063739  2.00 0.9782802 0.9758590 0.0009134394 0.001015332
## 5 0.01063739  4.00 0.9797290 0.9774692 0.0010262711 0.001140656
## 6 0.01063739  8.00 0.9801942 0.9779863 0.0009619072 0.001068995
## 7 0.01063739 16.00 0.9801452 0.9779320 0.0009539227 0.001059886
## 8 0.01063739 32.00 0.9800800 0.9778595 0.0010167117 0.001129699
## 9 0.01063739 64.00 0.9800692 0.9778475 0.0010309669 0.001145548

Preprocessing for handwiting image

imgData <- imageData("03.png") %>% sapply(function(x){ifelse(x<1,1,0)})
imgData <- c(0, imgData); imgData <- as.data.frame(matrix(imgData, nrow = 1))
show_digit(as.matrix(imgData[2:785]))

Prediction

names(imgData) <- c("y", paste0("X", 1:784))
predict(fit2, newdata=imgData)
## [1] 3
## Levels: 0 1 2 3 4 5 6 7 8 9

How to use the application:

  • Draw a 0-9 digit with your mouse at the box and submit.
  • Then the prediction result and a plot will be shown underneath.
  • Use clear button when you need to revise.

URL here: https://ryu-iku.shinyapps.io/handwriting_numbers_recognization/