Browse Source

feat(knowing app): add stm32f4 iris decision tree classifier demo

pull/7/head
yangtuo250 11 months ago
parent
commit
be3b3b8016
  1. 57
      APP_Framework/Applications/knowing_app/iris_ml_demo/DecisionTreeClassifierModel.h
  2. 23
      APP_Framework/Applications/knowing_app/iris_ml_demo/iris_ml_demo.c

57
APP_Framework/Applications/knowing_app/iris_ml_demo/DecisionTreeClassifierModel.h

@ -0,0 +1,57 @@
#include <stdarg.h>
/**
* Predict class for features vector
*/
int predict(float *x)
{
if (x[2] <= 2.449999988079071) {
return 0;
}
else {
if (x[3] <= 1.75) {
if (x[2] <= 4.950000047683716) {
if (x[3] <= 1.6500000357627869) {
return 1;
}
else {
return 2;
}
}
else {
if (x[3] <= 1.550000011920929) {
return 2;
}
else {
if (x[2] <= 5.450000047683716) {
return 1;
}
else {
return 2;
}
}
}
}
else {
if (x[2] <= 4.8500001430511475) {
if (x[1] <= 3.100000023841858) {
return 2;
}
else {
return 1;
}
}
else {
return 2;
}
}
}
}

23
APP_Framework/Applications/knowing_app/iris_ml_demo/iris_ml_demo.c

@ -1,8 +1,6 @@
#include <string.h>
#include <transform.h>
#include "SVCModel.h"
#define FEATURE_NUM 4
#define CSV_PATH "/csv/iris.csv"
#define CSV_BUFFER_SIZE (1 * 1024)
@ -41,6 +39,7 @@ void simple_CSV_read()
void iris_SVC_predict()
{
#include "SVCModel.h"
int result;
simple_CSV_read();
@ -57,3 +56,23 @@ void iris_SVC_predict()
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(iris_SVC_predict, iris predict by SVC);
#endif
void iris_DecisonTree_predict()
{
#include "DecisionTreeClassifierModel.h"
int result;
simple_CSV_read();
for (int i = 0; i < data_len; i++) {
result = predict(data[i]);
printf("data %d: ", i + 1);
for (int j = 0; j < FEATURE_NUM; j++) {
printf("%.4f ", data[i][j]);
}
printf("result: %d\n", result);
}
}
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(iris_DecisonTree_predict, iris predict by decison tree classifier);
#endif

Loading…
Cancel
Save