Browse Source

docs(knowing app): add README for iris_ml_demo

pull/8/head
yangtuo250 11 months ago
parent
commit
9a555bc8b5
  1. 71
      APP_Framework/Applications/knowing_app/iris_ml_demo/README.md

71
APP_Framework/Applications/knowing_app/iris_ml_demo/README.md

@ -0,0 +1,71 @@
# 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](https://scikit-learn.org/stable/) and converted to C language by [micromlgen](https://forgeplus.trustie.net/projects/yangtuo250/micromlgen).
### Enviroment preparation
```shell
pip install scikit-learn
git clone https://git.trustie.net/yangtuo250/micromlgen.git -b C
cd micromlgen && pip install -e .
```
### Train it!
```python
# 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:
```shell
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
```
Loading…
Cancel
Save