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

This commit is contained in:
yangtuo250 2021-08-11 17:07:26 +08:00
parent 9a1a407ea6
commit be3b3b8016
2 changed files with 78 additions and 2 deletions

View File

@ -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;
}
}
}
}

View File

@ -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