nok / sklearn-porter

Transpile trained scikit-learn estimators to C, Java, JavaScript and others.
BSD 3-Clause "New" or "Revised" License
1.28k stars 170 forks source link

C RandomForestClassifier code generation applies num_format lambda to feature indicis #40

Closed apasanen closed 5 years ago

apasanen commented 5 years ago

Example: I would like to use float constants.

porter = Porter(clf, language='c')
output = porter.export(embed_data=True, num_format=lambda o: str(o) + 'f' )

C- Output

#include <stdlib.h>                                                                                                                                
#include <stdio.h>                                                                                                                                 
#include <math.h>                                                                                                                                  

int predict_0(float features[]) {                                                                                                                  
    int classes[3];

    if (features[3f] <= 0.800000011920929f) {
        classes[0] = 49;
        classes[1] = 0;
        classes[2] = 0;
    } else {
        if (features[3f] <= 1.75f) {
apasanen commented 5 years ago

fix candidate for the issue available: https://github.com/apasanen/sklearn-porter/commit/43a403c45c7538876df5dbe3c2f79e4aca965d47

nok commented 5 years ago

Thanks @apasanen!