Comments (5)
@ehoppmann As a workaround you can just try passing the XGBClassifier
instance instead of XGBRegressor
one to ensure that a sigmoid is being applied in the generated code.
from m2cgen.
Hey @ehoppmann! Thank you so much for reporting this issue and for your kind feedback!
When you say "transformed" do you mean a probability value between 0 and 1? If so then this is exactly what code generated by m2cgen
suppose to return.
The code generated by m2cgen
from XGBoost model applies a sigmoid function on a computed result before returning it (for binary:logistic
objective). This behavior is consistent with predict_proba
method of XGBClassifier
.
So the value shouldn't be "raw" unless you accidentally supplied XGBRegressor
instance instead of XGBClassifier
. If your input is correct then there is a possibility of a bug here.
Can you perhaps share the very last line of the score
function from the code generated by m2cgen
to make sure that the sigmoid was applied there (or not)?
from m2cgen.
Hey there. I am indeed passing an instance of type xgboost.sklearn.XGBRegressor
to m2cgen. If I call the .predict()
method on that instance I get back values between 0 and 1, so I had assumed that the code generated by m2cgen would do the same thing. Perhaps this is a misunderstanding of the intended usage patterns of xgb models on my part?
from m2cgen.
@ehoppmann I see, thank you for sharing!
The current logic in m2cgen
implies that the sigmoid should only be applied if XGBClassifier
was passed. Which is clearly wrong based on your example.
Apparently the decision whether to apply the sigmoid or not should be made based on an objective function instead.
I believe that the described issue is a bug and that it should be fixed. Thank you so much for reporting it!
from m2cgen.
Our xgboost models use the
binary:logistic'
objective function, however the m2cgen converted version of the models return raw scores instead of the transformed scores.This is fine as long as the user knows this is happening! I didn't, so it took a while to figure out what was going on. I'm wondering if perhaps a useful warning could be raised for users to alert them of this issue? A warning could include a note that they can transform these scores back to the expected probabilities [0, 1] by
prob = logistic.cdf(score - base_score)
wherebase_score
is an attribute of the xgboost model.In our case, I'd like to minimize unnecessary processing on the device, so I am actually happy with the current m2cgen output and will instead inverse transform our threshold when evaluating the model output from the transpiled model...but it did take me a bit before I figured out what was going on, which is why I'm suggesting that a user friendly message might be raised when an unsupported objective function is encountered.
Thanks for creating & sharing this great tool!
hi,in the xgb2c code,what does output in the parameter of the function score mean and how can i get the predicted prob [0, 1] , thanks
from m2cgen.
Related Issues (20)
- The converted C model compiles very slow,how can i fix it?
- Unable to export LGBM model that uses `categorical_feature` HOT 2
- Convert ML model to c# HOT 2
- Issue with xgboost export in python: not same values splits HOT 1
- Getting predict_prob when convert m2cgen to different languages
- Feature Request: support for multioutput regression HOT 1
- Process ended with exit code -1073741571 (0xC00000FD) HOT 1
- Results dont match
- Add Fortran
- LightGBM models
- Unable to export code from XGBoost 1.7.5 models HOT 6
- How to use model for jpg photo?
- Issue while Exporting a LightGBM Model to C#
- XGBoost exported to C generates wrong indices for input array
- Logitraw objective function ignored for xgb.Booster
- Cannot export XGBClassifier model: TypeError: unsupported operand type(s) for /: 'float' and 'NoneType' HOT 4
- Memory overflow in program run after compilation of C code transformed by the xgboost model HOT 1
- Cannot export XGBClassifier model: TypeError: unsupported operand type(s) for *: 'int' and 'NoneType' HOT 1
- XGBoost GCC Memory Allocation Error: cc1plus.exe: out of memory allocating 65536 bytes
- xgbmodel is larger than 500M, convert to c, always Segmentation fault
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from m2cgen.