[PYTHON] I made a muscle training estimation app using Qore SDK

tl;dr

--I made a muscle training estimation app --Qore uses an algorithm called reservoir computing --Performed a task of classifying time series data from acceleration data that can be acquired with a smartphone. -Code --The accuracy is pretty good --Test data, accuracy 99.6% ――You should be a muscle engineer with this

strategy

--Collect accelerometer data on your smartphone (iphone) --You can get time series data with 3 components of x, y, z axis --Learning with 4 types of muscle training: push-ups, abs, squats, and abs rollers ――You can see what kind of muscle training you did with just your smartphone

Data collection

--Muscle training with your smartphone in your pants pocket ――This time, put your smartphone in the pocket in the same direction for all muscle training. ――It seems that it will be more difficult to estimate if you turn it in a different direction. --I used the following app to measure acceleration. -["Acceleration / Gyroscope / Magnetic Sensor Logger"](https://apps.apple.com/jp/app/%E5%8A%A0%E9%80%9F%E5%BA%A6-%E3% 82% B8% E3% 83% A3% E3% 82% A4% E3% 83% AD% E3% 82% B9% E3% 82% B3% E3% 83% BC% E3% 83% 97-% E7% A3 % 81% E5% 8A% 9B% E3% 82% BB% E3% 83% B3% E3% 82% B5% E3% 83% BC% E3% 83% AD% E3% 82% AC% E3% 83% BC / id448070865) --Measurement interval is 0.1 sec --Number of muscle trainings performed --Push-ups: 21 times (~ 35 sec) --Abs: 20 times (~ 66 sec) --Squat: 20 times (~ 51 sec) --Abdominal muscle roller (sitting roller): 12 times (~ 50 sec) ――In order to increase the amount of data, you have to do more muscle training ――You should be able to become macho someday

――The following is the raw data of the acceleration that was actually measured.

image.png

--Abs

image.png

--Squat

image.png

--Abdominal muscle roller (sitting roller)

image.png

――It's periodic, and I got more beautiful data than I expected.

Data preprocessing

--I tried using qore_sdk.utils provided by Qore SDK.

Learning and reasoning

--For learning and reasoning, [Sample Code](https://github.com/qcore-info/advent-calendar-2019/blob/master/Qore%E3%82%B5%E3%83%B3%E3%83 % 97% E3% 83% AB1_with_UCI.ipynb) exactly the same --Set up your account information below

client = WebQoreClient(username=username, 
                       password=password, 
                       endpoint=endpoint)   

--Learn below

res = client.classifier_train(X=X_train, Y=y_train)
print(res)
# {'res': 'ok', 'train_time': 7.2200915813446045}

――Learning was completed in about 7.2 seconds --Quite early --Test (inference)

res = client.classifier_test(X=X_test, Y=y_test)
print(res)
{'accuracy': 0.9964285714285714, 'f1': 0.9964301018846474, 'res': 'ok'}

--Accuracy is 0.9964

Linear regression, compare with simple deep learning

--This is also the sample code --Linear regression --Learning time: 0.28547000885009766 \ [sec ] --Accuracy: 0.9964285714285714

Impressions I tried using

--SDK was simple and easy to use ――The accuracy was high, but linear regression and MLP also gave sufficient accuracy. --The problem may have been too easy --I want to try a more difficult estimation task --I would like to verify what happens if I use qore_sdk.featurizer that I could not try this time (time) if there is)

Below, what I investigated and organized

Qore algorithm

The following article (1st day of Advent calendar) has a brief explanation.

[World of Reservoir Computing ~ With Qore ~ --Qiita](https://qiita.com/ryoppippi/items/f607c8828238094eade0#qore%E3%81%AB%E3%81%A4%E3%81%84%E3% 81% A6)

It is an application of reservoir computing with some modifications.

Achieve a highly accurate model even with a small reservoir size by developing original mechanisms for pretreatment and posttreatment as well as inside the reservoir.

It seems that.

Does it seem to be based on the following paper? Van der Sande, Guy & Brunner, Daniel & Soriano, Miguel. (2017). Advances in photonic reservoir computing. Nanophotonics. 6. 561-576. 10.1515/nanoph-2016-0132.

I want to read it when I have time.

Specific procedure code

The jupyter notebook has been published in the following repository. See the README and notebook scripts for instructions.

GitHub - hnishi/muscle_QoreSDK_AdvCal2019

What you can do with the Qore SDK

--classification Classification task

――I wanted to use the full functionality of the Qure SDK. ――I want you to be able to detect change points and anomalies.

Official document link

advent repo GitHub --qcore-info / advent-calendar-2019: Machine learning and applied technologies other than deep learning by QuantumCore Advent Calendar 2019

QoreSDK doc QoreSDK 0.1.0 documentation

2019/12/22 postscript

With Featurizer, the accuracy is even higher

Feature extraction is performed by frequency decomposition so that the number of classes is 40.

n_filters = 40
featurizer = Featurizer(n_filters)
X = featurizer.featurize(X, axis=2)

QoreSDK accuracy for test data is below

acc= 1.0 f1= 1.0 elapsed_time:52.20956110954285[sec]

The result is an accuracy of 1.

On the contrary, logistic regression and MLP are less accurate than before using Featurizer.

===LogisticRegression(Using Sklearn)===
elapsed_time:0.2480778694152832[sec]
acc= 0.6291666666666667
f1= 0.630372638509498
===MLP(Using Sklearn)===
elapsed_time:8.673331499099731[sec]
acc= 0.95
f1= 0.9502859082452324

Added the state without muscle training

Added the non-muscle training state to the classification task class. (Data was collected as a control while preparing lunch.) Again, the accuracy was 1.

Click here for the notebook used for the work. https://github.com/hnishi/muscle_QoreSDK_AdvCal2019/blob/master/muscle_QoreSDK_v2.ipynb

Validate with newly acquired data

Create a data set different from the one used at the time of learning with the abdominal muscle roller. Inference was made using this data.

Click here for the notebook used for the work. https://github.com/hnishi/muscle_QoreSDK_AdvCal2019/blob/master/muscle_QoreSDK_v2.ipynb

As a result, the accuracy for this verification data is as follows

With the QoreSDK, the correct answer rate was about 70%. In order to improve the accuracy, it seems necessary to expand and learn various patterns of learning data for each item of muscle training.

Recommended Posts

I made a muscle training estimation app using Qore SDK
I made a Line-bot using Python!
Beginner: I made a launcher using dictionary
〇✕ I made a game
I made a login / logout process using Python Bottle.
I made a net news notification app with Python
I made a school festival introduction game using Ren’py
I made a quick feed reader using feedparser in Python
I made a fucking app that won't let you skip
I made a VGG16 model using TensorFlow (on the way)
I made a discord bot
I made a Chatbot using LINE Messaging API and Python
I made a game called Battle Ship using pygame and tkinter
I made a Dir en gray face classifier using TensorFlow --(1) Introduction
I made a Dir en gray face classifier using TensorFlow-④ Face extraction
I made a poker game server chat-holdem using websocket with python
I made a Chatbot using LINE Messaging API and Python (2) ~ Server ~
[Kaggle] I made a collection of questions using the Titanic tutorial
I made a C ++ learning site
I made a CUI-based translation script (2)
I made a wikipedia gacha bot
I made a CUI-based translation script
I made a daemon with Python
I made a Dir en gray face classifier using TensorFlow --⑩ Face classification test
I made a Dir en gray face classifier using TensorFlow --⑥ Learning program
I made a Dir en gray face classifier using TensorFlow --- ⑧ Learning execution
I made a Dir en gray face classifier using TensorFlow --- ⑦ Learning model
I made a Dir en gray face classifier using TensorFlow --② Environment construction
I made an image discrimination (cifar10) model using a convolutional neural network.
I made a new AWS S3 bucket
I made a dash docset for Holoviews
I made a payroll program in Python!
I touched "Orator" so I made a note
I made a character counter with Python
I tried playing a ○ ✕ game using TensorFlow
I made an online frequency analysis app
I tried drawing a line using turtle
I made a conversation partner like Siri
I made a script to display emoji
I made a Hex map with Python
I made a life game with Numpy
I made a stamp generator with GAN
I made a browser automatic stamping tool.
After studying Python3, I made a Slackbot
I tried using pipenv, so a memo
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a library for actuarial science
I made a WEB application with Django
I made a neuron simulator with Python
I tried to predict the deterioration of the lithium ion battery using the Qore SDK
I made a LINE BOT that returns a terrorist image using the Flickr API
I made an appdo command to execute a command in the context of the app
I made a Dir en gray face classifier using TensorFlow --⑪ Web release preparation
I made a script to record the active window using win32gui of Python