xiuos/APP_Framework/Applications/knowing_app/iris_ml_demo
yangtuo250 62df72af5b fix(knowing framework/yolov2 region layer): free region layer thresholds 2021-12-16 15:03:37 +08:00
..
DecisionTreeClassifierModel.h feat(knowing app): add stm32f4 iris decision tree classifier demo 2021-08-11 17:07:26 +08:00
Kconfig feat(knowing app): stm32f4 svc iris demo 2021-08-10 18:02:16 +08:00
LogisticRegressionModel.h feat(knowing app): stm32f4 logistic regression iris demo 2021-08-12 00:02:10 +08:00
README.md docs(knowing app): add README for iris_ml_demo 2021-08-13 14:42:18 +08:00
SConscript feat(knowing app): stm32f4 svc iris demo 2021-08-10 18:02:16 +08:00
SVCModel.h feat(knowing app): stm32f4 svc iris demo 2021-08-10 18:02:16 +08:00
iris.csv feat(knowing app): stm32f4 svc iris demo 2021-08-10 18:02:16 +08:00
iris_ml_demo.c fix(knowing framework/yolov2 region layer): free region layer thresholds 2021-12-16 15:03:37 +08:00

README.md

Machine learning demo using iris dataset

Classification task demo, tested on stm32f4 and k210-based edge devices. Training on iris dataset by Decision Tree classifier, Support Vector Machine classifier and Logistic Regression classifier.


Training

Model generated by Sklearn and converted to C language by micromlgen.

Enviroment preparation

pip install scikit-learn
git clone https://git.trustie.net/yangtuo250/micromlgen.git -b C
cd micromlgen && pip install -e .

Train it!

# load iris dataset
from sklearn.datasets import load_iris
X, y = load_iris(return_X_y=True)

# train SVC classifier and convert
clf = SVC(kernel='linear', gamma=0.001).fit(X, y)
print(port(clf, cplusplus=False, platform=platforms.STM32F4))

# train logistic regression classifier and convert
clf = LogisticRegression(max_iter=1000).fit(X, y)
print(port(clf, cplusplus=False, platform=platforms.STM32F4))

# train decision tree classifier and convert
clf = DecisionTreeClassifier().fit(X, y)
print(port(clf, cplusplus=False, platform=platforms.STM32F4)

Copy each content generated by print to a single C language file.


Deployment

compile and burn

Use (scons --)menuconfig in bsp folder(Ubiquitous/RT_Thread/bsp/k210(or stm32f407-atk-coreboard)), open APP_Framwork --> Applications --> knowing app --> enable apps/iris ml demo to enable this app. scons -j(n) to compile and burn in by st-flash(for ARM) or kflash(for k210).

testing set

Copy iris.csv to SD card /csv/iris.csv.


Run

In serial terminal:

  • iris_SVC_predict for SVC prediction
  • iris_DecisonTree_predict for decision tree prediction
  • iris_LogisticRegression_predict for logistic regression prediction

Example output:

data 1: 5.1000 3.5000 1.4000 0.2000 result: 0
data 2: 6.4000 3.2000 4.5000 1.5000 result: 1
data 3: 5.8000 2.7000 5.1000 1.9000 result: 2
data 4: 7.7000 3.8000 6.7000 2.2000 result: 2
data 5: 5.5000 2.6000 4.4000 1.2000 result: 1
data 6: 5.1000 3.8000 1.9000 0.4000 result: 0
data 7: 5.8000 2.7000 3.9000 1.2000 result: 1