@@ -109,24 +109,10 @@ def test_xgb_classifier_reglog(self):
109109 x_test , xgb , conv_model ,
110110 basename = "SklearnXGBClassifierRegLog" )
111111
112- def test_xgb_classifier_multi_str_labels (self ):
113- xgb , x_test = _fit_classification_model (
114- XGBClassifier (n_estimators = 4 ), 5 , is_str = True )
115- conv_model = convert_xgboost (
116- xgb , initial_types = [('input' , FloatTensorType (shape = [None , None ]))],
117- target_opset = TARGET_OPSET )
118- self .assertTrue (conv_model is not None )
119- dump_data_and_model (
120- x_test , xgb , conv_model ,
121- basename = "SklearnXGBClassifierMultiStrLabels" )
122-
123112 def test_xgb_classifier_multi_discrete_int_labels (self ):
124113 iris = load_iris ()
125114 x = iris .data [:, :2 ]
126115 y = iris .target
127- y [y == 0 ] = 10
128- y [y == 1 ] = 20
129- y [y == 2 ] = - 30
130116 x_train , x_test , y_train , _ = train_test_split (x ,
131117 y ,
132118 test_size = 0.5 ,
@@ -241,7 +227,7 @@ def test_xgboost_10(self):
241227 X_test .astype (np .float32 ), regressor , model_onnx ,
242228 basename = "XGBBoosterRegBug" )
243229
244- def test_xgboost_classifier_i5450 (self ):
230+ def test_xgboost_classifier_i5450_softmax (self ):
245231 iris = load_iris ()
246232 X , y = iris .data , iris .target
247233 X_train , X_test , y_train , y_test = train_test_split (X , y , random_state = 10 )
@@ -255,6 +241,26 @@ def test_xgboost_classifier_i5450(self):
255241 predict_list = [1. , 20. , 466. , 0. ]
256242 predict_array = np .array (predict_list ).reshape ((1 ,- 1 )).astype (np .float32 )
257243 pred_onx = sess .run ([label_name ], {input_name : predict_array })[0 ]
244+ bst = clr .get_booster ()
245+ bst .dump_model ('dump.raw.txt' )
246+ dump_data_and_model (
247+ X_test .astype (np .float32 ) + 1e-5 , clr , onx ,
248+ basename = "XGBClassifierIris-Out0" )
249+
250+ def test_xgboost_classifier_i5450 (self ):
251+ iris = load_iris ()
252+ X , y = iris .data , iris .target
253+ X_train , X_test , y_train , y_test = train_test_split (X , y , random_state = 10 )
254+ clr = XGBClassifier (objective = "multi:softprob" , max_depth = 1 , n_estimators = 2 )
255+ clr .fit (X_train , y_train , eval_set = [(X_test , y_test )], early_stopping_rounds = 40 )
256+ initial_type = [('float_input' , FloatTensorType ([None , 4 ]))]
257+ onx = convert_xgboost (clr , initial_types = initial_type , target_opset = TARGET_OPSET )
258+ sess = InferenceSession (onx .SerializeToString ())
259+ input_name = sess .get_inputs ()[0 ].name
260+ label_name = sess .get_outputs ()[1 ].name
261+ predict_list = [1. , 20. , 466. , 0. ]
262+ predict_array = np .array (predict_list ).reshape ((1 ,- 1 )).astype (np .float32 )
263+ pred_onx = sess .run ([label_name ], {input_name : predict_array })[0 ]
258264 pred_xgboost = sessresults = clr .predict_proba (predict_array )
259265 bst = clr .get_booster ()
260266 bst .dump_model ('dump.raw.txt' )
@@ -364,4 +370,5 @@ def test_onnxrt_python_xgbclassifier(self):
364370
365371
366372if __name__ == "__main__" :
373+ # TestXGBoostModels().test_xgboost_booster_classifier_multiclass_softprob()
367374 unittest .main ()
0 commit comments