nyoka support for xgboost>=1.0.0
Robert-Christensen-visa opened this issue · 6 comments
I have been able to successfully export xgboost models using nyoka when I was using xgboost<1.0.0. When I upgrade to xgboost>=1.0.0, exporting the xgboost model fails.
The following is from xgboost example 1 I get an error when doing the export.
import pandas as pd
from sklearn import datasets
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from xgboost import XGBRegressor,XGBClassifier
iris = datasets.load_iris()
irisd = pd.DataFrame(iris.data,columns=iris.feature_names)
irisd['Species'] = iris.target
features = irisd.columns.drop('Species')
target = 'Species'
pipeline_obj = Pipeline([
('Xgbc',XGBClassifier())
])
pipeline_obj.fit(irisd[features],irisd[target])
from nyoka import xgboost_to_pmml
xgboost_to_pmml(pipeline_obj,features,target,"xgbc_pmml.pmml")
The stack trace thrown from running to the last line:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-2-5a7704b3a862> in <module>
1 from nyoka import xgboost_to_pmml
2
----> 3 xgboost_to_pmml(pipeline_obj,features,target,"xgbc_pmml.pmml")
~/condapv/envs/new_python/lib/python3.6/site-packages/nyoka/xgboost/xgboost_to_pmml.py in xgboost_to_pmml(pipeline, col_names, target_name, pmml_f_name, model_name, description)
61 mining_imp_val,
62 categoric_values,
---> 63 model_name)
64 pmml = pml.PMML(
65 version=PMML_SCHEMA.VERSION.value,
~/condapv/envs/new_python/lib/python3.6/site-packages/nyoka/xgboost/xgboost_to_pmml.py in get_PMML_kwargs(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)
103 mining_imp_val,
104 categoric_values,
--> 105 model_name)}
106 return algo_kwargs
107
~/condapv/envs/new_python/lib/python3.6/site-packages/nyoka/xgboost/xgboost_to_pmml.py in get_ensemble_models(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)
138 mining_models.append(pml.MiningModel(
139 modelName=model_name if model_name else "XGBoostModel",
--> 140 Segmentation=get_outer_segmentation(model, derived_col_names, col_names, target_name, mining_imp_val,categoric_values,model_name),
141 **model_kwargs
142 ))
~/condapv/envs/new_python/lib/python3.6/site-packages/nyoka/xgboost/xgboost_to_pmml.py in get_outer_segmentation(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)
178 segmentation = pml.Segmentation(
179 multipleModelMethod=get_multiple_model_method(model),
--> 180 Segment=get_segments(model, derived_col_names, col_names, target_name, mining_imp_val,categoric_values,model_name)
181 )
182 return segmentation
~/condapv/envs/new_python/lib/python3.6/site-packages/nyoka/xgboost/xgboost_to_pmml.py in get_segments(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)
211 segments = None
212 if 'XGBClassifier' in str(model.__class__):
--> 213 segments=get_segments_for_xgbc(model, derived_col_names, col_names, target_name, mining_imp_val,categoric_values,model_name)
214 elif 'XGBRegressor' in str(model.__class__):
215 segments=get_segments_for_xgbr(model, derived_col_names, col_names, target_name, mining_imp_val,categoric_values)
~/condapv/envs/new_python/lib/python3.6/site-packages/nyoka/xgboost/xgboost_to_pmml.py in get_segments_for_xgbc(model, derived_col_names, feature_names, target_name, mining_imp_val, categoric_values, model_name)
479 mining_schema_for_1st_segment, out, index)
480 segments.append(segments_equal_to_class)
--> 481 reg_model=sklToPmml.get_regrs_models(model,oField,oField,target_name,mining_imp_val,categoric_values,model_name)[0]
482 reg_model.normalizationMethod=REGRESSION_NORMALIZATION_METHOD.SOFTMAX.value
483 last_segment = pml.Segment(True_=pml.True_(), id=model.n_classes_ + 1,
~/condapv/envs/new_python/lib/python3.6/site-packages/nyoka/skl/skl_to_pmml.py in get_regrs_models(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)
1685 regrs_models.append(pml.RegressionModel(
1686 modelName=model_name if model_name else model.__class__.__name__,
-> 1687 RegressionTable=get_regrs_tabl(model, derived_col_names, target_name, categoric_values),
1688 **model_kwargs
1689 ))
~/condapv/envs/new_python/lib/python3.6/site-packages/nyoka/skl/skl_to_pmml.py in get_regrs_tabl(model, feature_names, target_name, categoric_values)
1714 """
1715 merge = list()
-> 1716 if hasattr(model, 'intercept_'):
1717 import numpy as np
1718 func_name = get_mining_func(model)
~/condapv/envs/new_python/lib/python3.6/site-packages/xgboost/sklearn.py in intercept_(self)
743 .format(self.booster))
744 b = self.get_booster()
--> 745 return np.array(json.loads(b.get_dump(dump_format='json')[0])['bias'])
746
747
KeyError: 'bias'
I am using nyoka 4.2.0 and xgboost 1.0.0.
Hi @Robert-Christensen-visa, Nyoka supports xgboost <= 0.90. We will be adding support for latest release very soon. To know about the supported libraries along with version, please refer to Libraries Supported by Nyoka
Hi @Nirmal-Neel, any news about supporting recent xgboost and sklearn? Cheers
Hi @victornoel, we are still not there yet. But that is not so far.
Very nice, thank you for the feedback!
Hi @victornoel, nyoka release 5.2.0 adds support for xgboost 1.x.x.
@Nirmal-Neel really cool, thx for the heads-up!
While I have you here, any plan for sklearn 1.x? With both xgboost 1.x and sklearn 1.x supported, we could have a suite of stabilized tools!