top of page

Hand motion prediction - Part 1

In many sci fi movies released about 10 or 15 years ago, people imagined they would be able to control computers or electrical devices with their hand gestures. Now we have technologies using cameras that detect motions by calculating the coordinates of hands or body. Motion detection is widely used, and has great potential in game industries virtual reality (VR) and tech industries. This time, I built classification models to classify hand gestures.


UCI repository provides hand gesture data: "Gesture Phase Segmentation Data Set". It is open source data and you can download from here. The details of data are explained in their pages, so I will not explain here and I only used their process data (excluded raw data).


1. Pandas DataFrame

Let's import data into python.




2. Build classification models


I will try 10 different classification models in 'sklearn' and choose top models. I will make a function that will take models and data, and call the function for 10 models.




Many classification model requires scaling as preprocessing, especially KNN, SVM, and Logistic Regression models. You can normalize your data with 'from sklearn.preprocessing import StandardScaler'. It will subtract data with the mean of train set and divide by the standard deviation of train set. You can apply the normalization on your test data set as well. Next, I will use the function and build classification models. This data is multi class, and some of the classification models are not inherently multi class, thus we need to use a technique called 'one verse all' or 'one verse rest' to use the binary classification models in our data.



On this stage, I did not provide the parameter optimization options, but you can insert the parameter ranges into 'grids'.

Now let's plot confusion matrices for classification models.





We can calculate accuracy from the confusion matrices. Random Forest and Extra Trees models have the highest accuracy.

gbt : 0.579675894666

knn : 0.582039162728

xgbt : 0.580351114112

ada : 0.501350438893

dt : 0.420999324781

edt : 0.63571910871

rf : 0.619513841999

lr : 0.467251856853

svc : 0.54591492235

nb : 0.420661715057


We also can calculate F1 score for each class from precision and recall in the confusion matrices. I calculated F1 scores for the top 2 models: Random Forest and Extra Trees.




3. Parameter optimization


All classification models we built so far were not tuned. We can try different parameters to increase the model accuracy, and since some parameter settings can cause overfitting, it should be cross validated to optimize the values for parameters. GridSearchCV explores all parameter combinations and returns only the best result.



Plot below shows the F1 scores for each class before and after parameter optimization. Most of classes have slightly better F1 Scores.

Preparation and retraction phases are similar behaviors to stroke, and hold is similar behavior to rest. It is ambiguous to distinguish those behaviors from the main phases: stroke and rest. It might be better to have binary classes consisted with motion state and steady state rather than having all 5 classes. Next posting will categorize the target variable as binary and compare the results to multi class models.


Go To Next Posting ->



Featued Posts 
Recent Posts 
Find Me On
  • LinkedIn Social Icon
Serach By Tags

© 2017 by Jay Kim.

  • LinkedIn Social Icon
bottom of page