Beispiel #1
0
 def test_decisiontreeregressor_decision_path(self):
     model = DecisionTreeRegressor(max_depth=2)
     X, y = make_classification(10, n_features=4, random_state=42)
     X = X[:, :2].astype(numpy.float32)
     model.fit(X, y)
     model_onnx = to_onnx(model,
                          X,
                          options={id(model): {
                                       'decision_path': True
                                   }})
     sess = OnnxInference(model_onnx)
     res = sess.run({'X': X})
     pred = model.predict(X)
     self.assertEqualArray(pred, res['variable'].ravel())
     dec = model.decision_path(X)
     exp = binary_array_to_string(dec.todense())
     self.assertEqual(exp, res['decision_path'].ravel().tolist())
Beispiel #2
0
 def test_randomforestregressor_decision_path(self):
     model = RandomForestRegressor(max_depth=2, n_estimators=2)
     X, y = make_classification(10, n_features=4, random_state=42)
     X = X[:, :2].astype(numpy.float32)
     model.fit(X, y)
     model_onnx = to_onnx(model,
                          X,
                          options={id(model): {
                                       'decision_path': True
                                   }})
     sess = OnnxInference(model_onnx)
     res = sess.run({'X': X})
     pred = model.predict(X)
     self.assertEqualArray(pred, res['variable'].ravel())
     dec = model.decision_path(X)
     exp = binary_array_to_string(dec[0].todense())
     got = numpy.array([''.join(row) for row in res['decision_path']])
     self.assertEqual(exp, got.tolist())