-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecision_tree_classification.c
49 lines (45 loc) · 1.13 KB
/
decision_tree_classification.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* ----------------------------------------------------------------------
* Project: Autonomous Edge Pipeline
* Title: decision_tree_classification.c
* Description: Decision Tree classifier
* Target Processor: Cortex-M cores
* -------------------------------------------------------------------- */
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include <iostream>
#include <cstring>
#include "main.h"
#include "dataset.h"
#include "decision_tree_training.h"
/**
* @brief decision_tree_classification
* @param[in] root decision tree root node
* @param[in] X pointer to input sample
* @return The function returns the best class for the X sample
*/
int decision_tree_classifier(struct Node* root, float X[])
{
if(X[root->feature] < root->threshold)
{
if(root->left != NULL)
{
decision_tree_classifier(root->left, X);
}
else
{
return root->left_class;
}
}
else
{
if(root->right != NULL)
{
decision_tree_classifier(root->right, X);
}
else
{
return root->right_class;
}
}
}