.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/classifiers.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_classifiers.py: Classifier comparison =========================== Simple demonstration of the different implemented classifiers in emlearn .. GENERATED FROM PYTHON SOURCE LINES 8-24 .. code-block:: Python import os.path import emlearn import numpy import pandas import matplotlib.pyplot as plt import seaborn try: # When executed as regular .py script here = os.path.dirname(__file__) except NameError: # When executed as Jupyter notebook / Sphinx Gallery here = os.getcwd() .. GENERATED FROM PYTHON SOURCE LINES 25-29 Create dataset ------------------------ Using a simple multi-class dataset included with scikit-learn .. GENERATED FROM PYTHON SOURCE LINES 29-42 .. code-block:: Python def load_dataset(): from sklearn import datasets data = datasets.load_wine(as_frame=True) df = data.data.copy() df.columns = data.feature_names df['target'] = data.target return df dataset = load_dataset() .. GENERATED FROM PYTHON SOURCE LINES 43-48 Correctness checking ------------------------------ Compare predictions made by converted emlearn C model with those of the trained Python model .. GENERATED FROM PYTHON SOURCE LINES 48-117 .. code-block:: Python def check_correctness(out_dir, name, model_filename, test_data, test_predictions, feature_columns): test_res = numpy.array(test_predictions).flatten() test_dataset = "\n".join([ emlearn.cgen.array_declare(f"{name}_testset_data", dtype='float', values=test_data), emlearn.cgen.array_declare(f"{name}_testset_results", dtype='int', values=test_res), emlearn.cgen.constant_declare(f'{name}_testset_features', val=len(feature_columns)), emlearn.cgen.constant_declare(f'{name}_testset_samples', val=len(test_predictions)), ]) test_code = test_dataset + \ f''' #include "{model_filename}" // emlearn generated model #include // printf int {name}_test() {{ const int n_features = {name}_testset_features; const int n_testcases = {name}_testset_samples; int errors = 0; for (int i=0; i` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: classifiers.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: classifiers.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_