Beispiel #1
0
 def test_extra_trees_classifier(self):
     model = ExtraTreesClassifier(n_estimators=3)
     dump_one_class_classification(
         model,
         allow_failure="StrictVersion(onnx.__version__)"
                       " < StrictVersion('1.2') or "
                       "StrictVersion(onnxruntime.__version__)"
                       " <= StrictVersion('0.2.1')",
     )
     dump_binary_classification(
         model,
         allow_failure=(
             "StrictVersion(onnx.__version__) < StrictVersion('1.2') or "
             "StrictVersion(onnxruntime.__version__)"
             " <= StrictVersion('0.2.1')"
         ),
     )
     dump_multiple_classification(
         model,
         # Operator cast-1 is not implemented in onnxruntime
         allow_failure=(
             "StrictVersion(onnx.__version__) < StrictVersion('1.2') or "
             "StrictVersion(onnxruntime.__version__)"
             " <= StrictVersion('0.2.1')"
         ),
     )
Beispiel #2
0
 def test_decision_tree_classifier(self):
     model = DecisionTreeClassifier()
     dump_one_class_classification(model)
     dump_binary_classification(model)
     dump_multiple_classification(model)
     dump_multiple_classification(model, label_uint8=True)
     dump_multiple_classification(model, label_string=True)
Beispiel #3
0
    def test_gradient_boosting_classifier1Deviance(self):
        model = GradientBoostingClassifier(n_estimators=1, max_depth=2)
        X, y = make_classification(10, n_features=4, random_state=42)
        X = X[:, :2]
        model.fit(X, y)

        for cl in [None, 0.231, 1e-6, 0.9]:
            if cl is not None:
                model.init_.class_prior_ = np.array([cl, cl])
            initial_types = [('input', FloatTensorType((None, X.shape[1])))]
            model_onnx = convert_sklearn(model, initial_types=initial_types)
            if "Regressor" in str(model_onnx):
                raise AssertionError(str(model_onnx))
            sess = InferenceSession(model_onnx.SerializeToString())
            res = sess.run(None, {'input': X.astype(np.float32)})
            pred = model.predict_proba(X)
            delta = abs(res[1][0][0] - pred[0, 0])
            if delta > 1e-5:
                rows = ["diff", str(delta),
                        "X", str(X),
                        "base_values_", str(model.init_.class_prior_),
                        "predicted_label", str(model.predict(X)),
                        "expected", str(pred),
                        "onnxruntime", str(DataFrame(res[1])),
                        "model", str(model_onnx)]
                raise AssertionError("\n---\n".join(rows))
        dump_binary_classification(
            model, suffix="1Deviance",
            allow_failure="StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('%s')" % THRESHOLD)
 def test_gradient_boosting_classifier3(self):
     model = GradientBoostingClassifier(n_estimators=3)
     dump_binary_classification(
         model,
         suffix="3",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.5.0')")
Beispiel #5
0
 def test_random_forest_classifier(self):
     model = RandomForestClassifier(n_estimators=3)
     dump_one_class_classification(model,
                                   allow_failure="StrictVersion(onnx.__version__) < StrictVersion('1.2')")
     dump_binary_classification(model,
                                allow_failure="StrictVersion(onnx.__version__) < StrictVersion('1.2')")
     dump_multiple_classification(model,
                                  allow_failure="StrictVersion(onnx.__version__) < StrictVersion('1.2')")
 def test_lightgbm_classifier(self):
     model = LGBMClassifier(n_estimators=3, min_child_samples=1)
     dump_binary_classification(
         model, allow_failure="StrictVersion(onnx.__version__) < "
                              "StrictVersion('1.3.0')")
     dump_multiple_classification(
         model,
         allow_failure="StrictVersion(onnx.__version__) < "
                       "StrictVersion('1.3.0')")
Beispiel #7
0
 def test_lightgbm_classifier(self):
     model = LGBMClassifier(n_estimators=3, min_child_samples=1)
     dump_binary_classification(model,
                                target_opset={
                                    '': TARGET_OPSET,
                                    'ai.onnx.ml': TARGET_OPSET_ML
                                })
     dump_multiple_classification(model,
                                  target_opset={
                                      '': TARGET_OPSET,
                                      'ai.onnx.ml': TARGET_OPSET_ML
                                  })
Beispiel #8
0
    def test_xgb_classifier(self):
        iris = load_iris()
        X = iris.data[:, :2]
        y = iris.target
        y[y == 2] = 0

        xgb = XGBClassifier(n_estimators=3)
        xgb.fit(X, y)
        conv_model = convert_sklearn(
            xgb, initial_types=[
                ('input', FloatTensorType(shape=[None, X.shape[1]]))])
        self.assertTrue(conv_model is not None)
        dump_binary_classification(xgb, label_string=False)
 def test_voting_soft_binary(self):
     model = VotingClassifier(
         voting="soft",
         flatten_transform=False,
         estimators=[
             ("lr", LogisticRegression()),
             ("lr2", LogisticRegression(fit_intercept=False)),
         ],
     )
     dump_binary_classification(model,
                                suffix="Soft",
                                comparable_outputs=[0, 1],
                                target_opset=TARGET_OPSET)
Beispiel #10
0
    def test_xgb_classifier_reglog(self):
        iris = load_iris()
        X = iris.data[:, :2]
        y = iris.target
        y[y == 2] = 0

        xgb = XGBClassifier(objective='reg:logistic')
        xgb.fit(X, y)
        conv_model = convert_sklearn(
            xgb, initial_types=[
                ('input', FloatTensorType(shape=[None, X.shape[1]]))])
        self.assertTrue(conv_model is not None)
        dump_binary_classification(xgb, suffix="RegLog", label_string=False)
 def test_voting_soft_binary_weighted(self):
     model = VotingClassifier(
         voting="soft",
         flatten_transform=False,
         weights=numpy.array([1.8, 0.2]),
         estimators=[
             ("lr", LogisticRegression()),
             ("lr2", LogisticRegression(fit_intercept=False)),
         ],
     )
     dump_binary_classification(model,
                                suffix="WeightedSoft",
                                target_opset=TARGET_OPSET)
 def test_voting_hard_binary(self):
     model = VotingClassifier(
         voting="hard",
         flatten_transform=False,
         estimators=[
             ("lr", LogisticRegression()),
             ("lr2", LogisticRegression(fit_intercept=False)),
         ],
     )
     # predict_proba is not defined when voting is hard.
     dump_binary_classification(model,
                                suffix="Hard",
                                comparable_outputs=[0],
                                target_opset=TARGET_OPSET)
Beispiel #13
0
 def test_voting_soft_binary(self):
     model = VotingClassifier(voting='soft',
                              flatten_transform=False,
                              estimators=[
                                  ('lr', LogisticRegression()),
                                  ('lr2',
                                   LogisticRegression(fit_intercept=False))
                              ])
     dump_binary_classification(
         model,
         suffix='Soft-OneOffArray',
         comparable_outputs=[0, 1],
         allow_failure=
         "StrictVersion(onnxruntime.__version__) <= StrictVersion('0.2.1')")
Beispiel #14
0
 def test_voting_soft_binary_weighted(self):
     model = VotingClassifier(voting='soft',
                              flatten_transform=False,
                              weights=numpy.array([1.8, 0.2]),
                              estimators=[
                                  ('lr', LogisticRegression()),
                                  ('lr2',
                                   LogisticRegression(fit_intercept=False))
                              ])
     dump_binary_classification(
         model,
         suffix='WeightedSoft-OneOffArray',
         allow_failure=
         "StrictVersion(onnxruntime.__version__) <= StrictVersion('0.2.1')")
Beispiel #15
0
 def test_voting_hard_binary(self):
     model = VotingClassifier(voting='hard',
                              flatten_transform=False,
                              estimators=[
                                  ('lr', LogisticRegression()),
                                  ('lr2',
                                   LogisticRegression(fit_intercept=False))
                              ])
     # predict_proba is not defined when voting is hard.
     dump_binary_classification(
         model,
         suffix='Hard-OneOffArray',
         comparable_outputs=[0],
         allow_failure=
         "StrictVersion(onnxruntime.__version__) <= StrictVersion('0.2.1')")
 def test_decision_tree_classifier(self):
     model = DecisionTreeClassifier()
     dump_one_class_classification(
         model,
         # Operator cast-1 is not implemented in onnxruntime
         allow_failure=
         "StrictVersion(onnx.__version__) < StrictVersion('1.2')")
     dump_binary_classification(
         model,
         allow_failure=
         "StrictVersion(onnx.__version__) < StrictVersion('1.2')")
     dump_multiple_classification(
         model,
         allow_failure=
         "StrictVersion(onnx.__version__) < StrictVersion('1.2')")
 def test_voting_soft_binary_weighted(self):
     model = VotingClassifier(
         voting="soft",
         flatten_transform=False,
         weights=numpy.array([1.8, 0.2]),
         estimators=[
             ("lr", LogisticRegression()),
             ("lr2", LogisticRegression(fit_intercept=False)),
         ],
     )
     dump_binary_classification(
         model,
         suffix="WeightedSoft",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.2.1')",
     )
 def test_voting_soft_binary(self):
     model = VotingClassifier(
         voting="soft",
         flatten_transform=False,
         estimators=[
             ("lr", LogisticRegression()),
             ("lr2", LogisticRegression(fit_intercept=False)),
         ],
     )
     dump_binary_classification(
         model,
         suffix="Soft",
         comparable_outputs=[0, 1],
         allow_failure="StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.2.1')",
     )
 def test_voting_hard_binary(self):
     model = VotingClassifier(
         voting="hard",
         flatten_transform=False,
         estimators=[
             ("lr", LogisticRegression()),
             ("lr2", LogisticRegression(fit_intercept=False)),
         ],
     )
     # predict_proba is not defined when voting is hard.
     dump_binary_classification(
         model,
         suffix="Hard",
         comparable_outputs=[0],
         allow_failure="StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.5.0')",
     )
Beispiel #20
0
 def test_decision_tree_classifier(self):
     model = DecisionTreeClassifier()
     dump_one_class_classification(
         model,
         # Operator cast-1 is not implemented in onnxruntime
         allow_failure="StrictVersion(onnx.__version__)"
         " < StrictVersion('1.3') or "
         "StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.2.1')",
     )
     dump_binary_classification(
         model,
         allow_failure="StrictVersion(onnx.__version__)"
         " < StrictVersion('1.3') or "
         "StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.2.1')",
     )
     dump_multiple_classification(
         model,
         allow_failure="StrictVersion(onnx.__version__)"
         " < StrictVersion('1.3') or "
         "StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.2.1')")
     dump_multiple_classification(
         model,
         label_uint8=True,
         allow_failure="StrictVersion(onnx.__version__)"
         " < StrictVersion('1.3') or "
         "StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.2.1')")
     dump_multiple_classification(
         model,
         label_string=True,
         allow_failure="StrictVersion(onnx.__version__)"
         " < StrictVersion('1.3') or "
         "StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.2.1')")
 def test_gradient_boosting_classifier(self):
     model = GradientBoostingClassifier(n_estimators=3)
     dump_binary_classification(model)
 def test_extra_trees_classifier(self):
     model = ExtraTreesClassifier(n_estimators=3)
     dump_one_class_classification(model)
     dump_binary_classification(model)
     dump_multiple_classification(model)
 def test_random_forest_classifier(self):
     model = RandomForestClassifier(n_estimators=3)
     dump_one_class_classification(model)
     dump_binary_classification(model)
     dump_multiple_classification(model)
Beispiel #24
0
 def test_extra_tree_classifier(self):
     model = ExtraTreeClassifier()
     dump_one_class_classification(model)
     dump_binary_classification(model)
     dump_multiple_classification(model)