BayesWitnesses / m2cgen

Transform ML models into a native code (Java, C, Python, Go, JavaScript, Visual Basic, C#, R, PowerShell, PHP, Dart, Haskell, Ruby, F#, Rust) with zero dependencies
MIT License
2.8k stars 241 forks source link

Results dont match #574

Open ghost opened 1 year ago

ghost commented 1 year ago

I have a problem, that my results in c (using export_to_c) do not match with the model.predict_proba. I checked the gxbooster if-else dump and realized, that m2cgen is not using all depth levels.

Exported tree:

  if (input[1] >= 0.9447428) {
      var0 = 0.22857143; // this looks like a summarized value
  } else {
      var0 = -0.23809524;
  }

xgboost tree:

6:[f1<0.944742799] yes=13,no=14,missing=13
    13:[f3<0.963606358] yes=25,no=26,missing=25
        25:[f4<0.260004044] yes=43,no=44,missing=43
            43:leaf=-0.636363626
            44:leaf=-0
        26:[f3<1.04691052] yes=45,no=46,missing=45
            45:leaf=0.333333343
            46:leaf=-0.230769232
    14:[f4<-0.134770975] yes=27,no=28,missing=27 //<---------- this whole branch is summarized in the export as -0.238
        27:leaf=-0.5
        28:[f3<0.865021944] yes=47,no=48,missing=47
            47:leaf=-0
            48:leaf=0.416666657

Maybe I misunderstand something - -but this does not look right. :)

Can anyone advice please?

Thanks alot!