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

OSError: Windows isn't supported yet #77

Open wbadry opened 4 years ago

wbadry commented 4 years ago

Hello, Is there a problem with integrity_score?

# Porting
porter = Porter(svc_model, language='c')

# Calculate Integrity Score
integrity = porter.integrity_score(standardized_features_frame)

# Print score
print(integrity)

# Export C code
output = porter.export()

# Print C code
print(output)

I receive the following error:

File "C:\Python37\lib\site-packages\sklearn_porter\utils\Environment.py", line 75, in _platform_is_windows
    raise OSError(error_msg)
OSError: Windows isn't supported yet

When I remove integrity_score, the code is generated with no problems (only few warnings about depreciated code)

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

double coefficients[20] = {0.1391771356565354, 1.828258932194222, -0.3831725164267214, -1.103367573526621, -0.604291863892225, 0.5723835669074493, -0.34479887417147226, -0.8434799759703641, 0.3676324195239303, 0.3447426771538185, 0.19490918797363005, -0.3170564194138528, -0.3170564194138528, 0.267201742046325, 0.8137154349144415, 0.15804220719981077, 0.1490377305630668, 0.9058368625295317, -0.6680424130685098, 0.2836290565184824};
double intercepts = -0.04981732672437096;

int predict (float features[]) {
    int i, l;
    double prob = 0.;
    for (i = 0, l = sizeof(coefficients) / sizeof (coefficients[0]); i < l; i++) {
        prob += coefficients[i] * features[i];
    }
    if (prob + intercepts > 0) {
        return 1;
    }
    return 0;
}

int main(int argc, const char * argv[]) {

    /* Features: */
    float features[argc-1];
    int i;
    for (i = 1; i < argc; i++) {
        features[i-1] = atof(argv[i]);
    }

    /* Prediction: */
    printf("%d", predict(features));
    return 0;

}

I don't understand what is the difference between Windows and Linux in getting this function to work 😄 .

Thanks

nithinreddyy commented 3 years ago

Hello, Is there a problem with integrity_score?

# Porting
porter = Porter(svc_model, language='c')

# Calculate Integrity Score
integrity = porter.integrity_score(standardized_features_frame)

# Print score
print(integrity)

# Export C code
output = porter.export()

# Print C code
print(output)

I receive the following error:

File "C:\Python37\lib\site-packages\sklearn_porter\utils\Environment.py", line 75, in _platform_is_windows
    raise OSError(error_msg)
OSError: Windows isn't supported yet

When I remove integrity_score, the code is generated with no problems (only few warnings about depreciated code)

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

double coefficients[20] = {0.1391771356565354, 1.828258932194222, -0.3831725164267214, -1.103367573526621, -0.604291863892225, 0.5723835669074493, -0.34479887417147226, -0.8434799759703641, 0.3676324195239303, 0.3447426771538185, 0.19490918797363005, -0.3170564194138528, -0.3170564194138528, 0.267201742046325, 0.8137154349144415, 0.15804220719981077, 0.1490377305630668, 0.9058368625295317, -0.6680424130685098, 0.2836290565184824};
double intercepts = -0.04981732672437096;

int predict (float features[]) {
    int i, l;
    double prob = 0.;
    for (i = 0, l = sizeof(coefficients) / sizeof (coefficients[0]); i < l; i++) {
        prob += coefficients[i] * features[i];
    }
    if (prob + intercepts > 0) {
        return 1;
    }
    return 0;
}

int main(int argc, const char * argv[]) {

    /* Features: */
    float features[argc-1];
    int i;
    for (i = 1; i < argc; i++) {
        features[i-1] = atof(argv[i]);
    }

    /* Prediction: */
    printf("%d", predict(features));
    return 0;

}

I don't understand what is the difference between Windows and Linux in getting this function to work 😄 .

Thanks

Did it work on windows dude?

wbadry commented 3 years ago

@nithinreddyy it does without any problem. I only suspect that the error message is shown with any exception even if platform is not the reason 😄

nok commented 2 years ago

Hello @wbadry ,

thanks for your question and hint. Until now it's not supported, because I couldn't cover it with unit tests. My plan is to replace the excpetion with a simple warning.

Kind regards, Darius