-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
Different behaviour on python-exported model and C++ API predictor
Catboost version: 1.2.2
CPU: Intel Core i5-8550U
OS: Ubuntu [20.04]
I have the trained catboost model (see multi_class.py
in attachment) and saved it as
model.cbm
and model.py
. Besides,
I have saved the input and the answer for one row in input.1.json
.
In C++ I have the following code:
auto wrapper = ModelCalcerWrapper("model.cbm");
// parse input.1.json
for (const InputRow &row : in.input) {
auto pred = wrapper.CalcMulti(row.vector_float_features, row.vector_categorial_features);
// check that difference (pred - expected) is small enough
}
and the answer matches.
If I look at the python-exported file, then the error is immediately visible there:
current_tree_leaf_values_index += (1 << current_tree_depth) * model.dimension
* model.dimension
shouldn't be there (as it is in cpp-exported version, for now it raises index out of bound
exception).
I fixed it in model.fixed.py
file and add some code to predict a model:
if __name__ == "__main__":
input_file = "input.1.json"
data = open(input_file)
item = json.load(data)[0]
ans = item['ans']
float_feats = item['float_features']
cat_feats = item['cat_features']
resp = apply_catboost_model_multi(float_feats, cat_feats)
print("expected = {}".format(ans))
print("real = {}".format(resp))
# expected = [-0.4315705250918395, -0.07602514583990287, 0.5075956709317426]
# real = [-0.012774193043495252, -0.048760865913935775, 0.38847943878388946]
but the answer doesn't match. I suppose it's a problem. Or am I doing something wrong?
Attachment
https://gist.github.com/mkornaukhov03/5c5d9e394f17141cac4fa63d2b09e026
Danil42Russia, mkornaukhov03, Hidanio, MBkkt, unterumarmung and 8 moreavrylov, mkornaukhov03, unterumarmung and troy4eg