Skip to main content
. 2020 Nov 7;9(11):1622. doi: 10.3390/foods9111622
Algorithm 1 Searching the optimal number of features
Given a set of features F of n elements with gain ratio values F0, F1, F2, …, Fn−1 sorted such that F0 > F1 > F2 … > Fn−1, and the accuracym being the correctness classifying the dataset using the first m features. The following algorithm is based on the binary search to find the index m in F that corresponds to the minimum index to classify the dataset properly.
  1. Set L to 0 and R to n − 1

  2. Set m = R, mold = m

  3. If accuracym < 99%, stop, the classifier must use the all features

  4. Set m (the middle position) to the floor of L+R2

  5. If accuracym > 99%, set R to m

  6. If accuracym < 99%, set L to m

  7. If abs(mmold) > 0, mold = m, goto 4

  8. Stop, the classifier must use the first m + 1 features