Looking for the best performing classifiers with a minimum amount of parameters to set?Don't look anywhere else: Gauss Naive Bayes is what you're looking for, and thanks to microML, you can now easily move it to your microcontroller.
Gaussian Naive Bayes
Naive Bayes classifiers are simple models based on probability theory that can be used for classification.
They are due to the assumption of independence between input variables.Although this assumption is not true in the vast majority of cases, they usually perform very well in most classification missions, so they are quite popular.
Gauss Naive Bayes combines another (mostly false) assumption: a Gauss probability distribution of variables.
While it's hard to accept that so many false assumptions lead to such good performances, the fact that it's a classifier that works quite well makes it one of the reasons why it works.
However, what is important to us is that sklear implements GaussianNB,so we easily train such a classifier.
The most interesting part is that gaussianNB can be adjusted with a single parameter: var_smoothing.
This simple code will train a group of classifiers with a different
var_smoothingfactor and select the best performer.
Once you have your trained classifier, it is as easy as ever to move it to C:
port is a useful method that can carry many classifiers: it will automatically detect the converter that is suitable for you.
What does the exported code look like?
Report of tests with Arduino Nano 33 Ble Sense:
|Classifier||Dataset||Flash||Data store||Implementation time||Precision|
|GaussNB||Iris (150×4)||82 kb||42 Kb||65 ms||%97|
|LinearSVC||Iris (150×4)||83 Kb||42 Kb||76 ms||%99|
|GaussNB||Breast cancer (80×40)||90 Kb||42 Kb||160 ms||%77|
|LinearSVC||Breast cancer (80×40)||112 Kb||42 Kb||378 ms||%73|
|GaussNB||Winw (100×13)||85 Kb||42 Kb||130 ms||%97|
|LinearSVC||Wine (100×13)||89 Kb||42 Kb||125 ms||%99|
We can see that accuracy is equal to a linear SVM and reaches 97% in some datasets. Its simplicity is taken into account by high-size datasets (breast cancer), where the execution time is half the lines: we can see this pattern repeated with other real-world, medium-sized datasets.
You may receive a TemplateNotFound error when using
micromlgen, in which case you can go through the problem by removing and reinstaling the library:
pip uninstall micromlgen
Then go to Github,download the package as a zip and take the
micromlgenfolder to your project.