def test_model_multinomial_nb_binary_classification(self):
     model, X = fit_classification_model(
         MultinomialNB(), 2, pos_features=True)
     model_onnx = convert_sklearn(
         model,
         "multinomial naive bayes",
         [("input", FloatTensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X.astype(np.float32),
         model,
         model_onnx,
         basename="SklearnBinMultinomialNB-Dec4",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
 def test_gradient_boosting_int(self):
     model, X = fit_classification_model(
         GradientBoostingClassifier(n_estimators=4), 5, is_int=True)
     model_onnx = convert_sklearn(
         model,
         "gradient boosting classifier",
         [("input", Int64TensorType([None, X.shape[1]]))],
         dtype=np.float32,
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnGradientBoostingInt",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
Example #3
0
 def test_model_ridge_classifier_cv_bool(self):
     model, X = fit_classification_model(linear_model.RidgeClassifierCV(),
                                         2,
                                         is_bool=True)
     model_onnx = convert_sklearn(
         model,
         "binary ridge classifier cv",
         [("input", BooleanTensorType([None, X.shape[1]]))],
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnRidgeClassifierCVBool",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.2.1')",
     )
Example #4
0
 def test_model_logistic_regression_binary_class(self):
     model, X = fit_classification_model(
         linear_model.LogisticRegression(max_iter=10000), 2)
     model_onnx = convert_sklearn(
         model, "logistic regression",
         [("input", FloatTensorType([None, X.shape[1]]))])
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnLogitisticRegressionBinary",
         # Operator cast-1 is not implemented in onnxruntime
         allow_failure="StrictVersion(onnx.__version__)"
                       " < StrictVersion('1.3') or "
                       "StrictVersion(onnxruntime.__version__)"
                       " <= StrictVersion('0.2.1')",
     )
Example #5
0
 def test_model_logistic_regression_binary_class_decision_function(self):
     model, X = fit_classification_model(
         linear_model.LogisticRegression(max_iter=10000), 2)
     model_onnx = convert_sklearn(
         model,
         "logistic regression",
         [("input", FloatTensorType([None, X.shape[1]]))],
         options={linear_model.LogisticRegression: {
             'raw_scores': True
         }},
         target_opset=TARGET_OPSET)
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X[:5],
         model,
         model_onnx,
         basename="SklearnLogitisticRegressionBinaryRawScore",
         methods=['predict', 'decision_function_binary'])
Example #6
0
 def test_bagging_classifier_gradient_boosting_multiclass(self):
     model, X = fit_classification_model(
         BaggingClassifier(GradientBoostingClassifier(n_estimators=10)), 3)
     model_onnx = convert_sklearn(
         model,
         "bagging classifier",
         [("input", FloatTensorType([None, X.shape[1]]))],
         dtype=np.float32,
         target_opset=TARGET_OPSET)
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnBaggingClassifierGradientBoostingMulticlass",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
 def test_sklearn_nca_double(self):
     model, X_test = fit_classification_model(
         NeighborhoodComponentsAnalysis(n_components=2,
                                        max_iter=4,
                                        random_state=42), 3)
     X_test = X_test.astype(numpy.float64)
     model_onnx = convert_sklearn(
         model,
         "NCA",
         [("input", DoubleTensorType((None, X_test.shape[1])))],
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X_test,
         model,
         model_onnx,
         basename="SklearnNCADouble",
     )
Example #8
0
 def test_ovr_classification_int_binary_mlp(self):
     model, X = fit_classification_model(
         OneVsRestClassifier(MLPClassifier()), 2, is_int=True)
     model_onnx = convert_sklearn(
         model,
         "ovr classification",
         [("input", Int64TensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnOVRClassificationIntBinMLP",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
Example #9
0
 def test_ovr_regression_float_mlp(self):
     model, X = fit_classification_model(
         OneVsRestClassifier(MLPRegressor()), 7)
     model_onnx = convert_sklearn(
         model,
         "ovr regression",
         [("input", FloatTensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnOVRRegressionFloatMLP-Out0",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
 def test_model_bernoulli_nb_binary_classification(self):
     model, X = fit_classification_model(
         BernoulliNB(), 2)
     model_onnx = convert_sklearn(
         model,
         "bernoulli naive bayes",
         [("input", FloatTensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnBinBernoulliNB",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
Example #11
0
 def test_ovr_classification_float_binary_ensemble(self):
     model, X = fit_classification_model(
         OneVsRestClassifier(GradientBoostingClassifier()), 2)
     model_onnx = convert_sklearn(
         model,
         "ovr classification",
         [("input", FloatTensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnOVRClassificationFloatBinEnsemble",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
 def test_model_categorical_nb(self):
     model, X = fit_classification_model(
         CategoricalNB(), 3, is_int=True, pos_features=True)
     model_onnx = convert_sklearn(
         model,
         "categorical naive bayes",
         [("input", Int64TensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X[10:13],
         model,
         model_onnx,
         basename="SklearnCategoricalNB",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
 def test_model_complement_nb_binary_classification_int(self):
     model, X = fit_classification_model(
         ComplementNB(), 2, is_int=True, pos_features=True)
     model_onnx = convert_sklearn(
         model,
         "complement naive bayes",
         [("input", Int64TensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnBinComplementNBInt-Dec4",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')"
     )
 def test_model_gaussian_nb_multiclass_bool(self):
     model, X = fit_classification_model(
         GaussianNB(), 5, is_bool=True)
     model_onnx = convert_sklearn(
         model,
         "gaussian naive bayes",
         [("input", BooleanTensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET,
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnMclGaussianNBBool-Dec4",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
Example #15
0
 def test_bagging_classifier_sgd_multiclass_decision_function(self):
     model, X = fit_classification_model(
         BaggingClassifier(
             GradientBoostingClassifier(random_state=42, n_estimators=10),
             random_state=42), 4, n_features=40)
     options = {id(model): {'raw_scores': True}}
     model_onnx = convert_sklearn(
         model, "bagging classifier",
         [("input", FloatTensorType([None, X.shape[1]]))],
         options=options,
         target_opset=TARGET_OPSET)
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X[:15], model, model_onnx,
         basename="SklearnBaggingClassifierSGDMultiDecisionFunction-Dec3",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
         methods=['predict', 'decision_function'])
Example #16
0
 def test_ovr_regression_int_ensemble(self):
     model, X = fit_classification_model(
         OneVsRestClassifier(GradientBoostingRegressor()), 4, is_int=True)
     model_onnx = convert_sklearn(
         model,
         "ovr regression",
         [("input", Int64TensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnOVRRegressionIntEnsemble-Out0",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
Example #17
0
 def test_bagging_classifier_default_binary(self):
     model, X = fit_classification_model(
         BaggingClassifier(), 2)
     model_onnx = convert_sklearn(
         model,
         "bagging classifier",
         [("input", FloatTensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnBaggingClassifierDefaultBinary",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
Example #18
0
 def test_ovr_classification_float(self):
     model, X = fit_classification_model(
         OneVsRestClassifier(LogisticRegression(solver='liblinear')), 3)
     model_onnx = convert_sklearn(
         model,
         "ovr classification",
         [("input", FloatTensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnOVRClassificationFloat",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
 def test_grid_search_multiclass_int(self):
     tuned_parameters = [{'C': np.logspace(-1, 0, 4)}]
     clf = GridSearchCV(LogisticRegression(random_state=42,
                                           max_iter=100,
                                           solver='lbfgs',
                                           multi_class='multinomial'),
                        tuned_parameters,
                        cv=5)
     model, X = fit_classification_model(clf, n_classes=4, is_int=True)
     model_onnx = convert_sklearn(
         model,
         "GridSearchCV", [("input", Int64TensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET)
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(X,
                         model,
                         model_onnx,
                         basename="SklearnGridSearchMulticlassInt-Dec4")
 def test_model_multinomial_nb_multiclass(self):
     model, X = fit_classification_model(MultinomialNB(),
                                         5,
                                         pos_features=True)
     model_onnx = convert_sklearn(
         model,
         "multinomial naive bayes",
         [("input", FloatTensorType(X.shape))],
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnMclMultinomialNB-Dec4",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
 def test_model_stacking_classifier(self):
     model, X = fit_classification_model(
         model_to_test_cl(), n_classes=2)
     model_onnx = convert_sklearn(
         model, "stacking classifier",
         [("input", FloatTensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET)
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnStackingClassifier",
         allow_failure="StrictVersion("
         "onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
         comparable_outputs=[0]
     )
Example #22
0
 def test_model_linear_svc_bool(self):
     model, X = fit_classification_model(LinearSVC(max_iter=100),
                                         5,
                                         is_bool=True)
     model_onnx = convert_sklearn(
         model,
         "multi-class linear SVC",
         [("input", BooleanTensorType([None, X.shape[1]]))],
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnLinearSVCBool",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.2.1')",
     )
Example #23
0
 def test_model_mlp_classifier_multiclass_default(self):
     model, X_test = fit_classification_model(
         MLPClassifier(random_state=42), 4)
     model_onnx = convert_sklearn(
         model,
         "scikit-learn MLPClassifier",
         [("input", FloatTensorType([None, X_test.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertTrue(model_onnx is not None)
     dump_data_and_model(
         X_test,
         model,
         model_onnx,
         basename="SklearnMLPClassifierMultiClass",
         allow_failure="StrictVersion("
         "onnxruntime.__version__)<= StrictVersion('0.2.1')",
     )
Example #24
0
 def test_model_ridge_classifier_int(self):
     model, X = fit_classification_model(linear_model.RidgeClassifier(),
                                         5,
                                         is_int=True)
     model_onnx = convert_sklearn(
         model,
         "multi-class ridge classifier",
         [("input", Int64TensorType([None, X.shape[1]]))],
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnRidgeClassifierInt",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         " <= StrictVersion('0.2.1')",
     )
 def test_gradient_boosting_binary_classification_init_zero(self):
     model, X = fit_classification_model(
         GradientBoostingClassifier(n_estimators=4, init='zero'), 2)
     model_onnx = convert_sklearn(
         model,
         "gradient boosting classifier",
         [("input", FloatTensorType([None, X.shape[1]]))],
         dtype=np.float32,
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnGradientBoostingBinaryClassifierInitZero",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
 def test_model_bernoulli_nb_multiclass_params(self):
     model, X = fit_classification_model(
         BernoulliNB(alpha=0, binarize=1.0, fit_prior=False), 4)
     model_onnx = convert_sklearn(
         model,
         "bernoulli naive bayes",
         [("input", FloatTensorType([None, X.shape[1]]))],
         dtype=np.float32,
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnMclBernoulliNBParams",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
 def test_model_bernoulli_nb_multiclass_int(self):
     model, X = fit_classification_model(
         BernoulliNB(), 4, is_int=True)
     model_onnx = convert_sklearn(
         model,
         "bernoulli naive bayes",
         [("input", Int64TensorType([None, X.shape[1]]))],
         target_opset=TARGET_OPSET
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X,
         model,
         model_onnx,
         basename="SklearnMclBernoulliNBInt-Dec4",
         allow_failure="StrictVersion(onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
 def test_model_sgd_binary_class_log(self):
     model, X = fit_classification_model(
         SGDClassifier(loss='log', random_state=42), 2)
     model_onnx = convert_sklearn(
         model,
         "scikit-learn SGD binary classifier",
         [("input", FloatTensorType([None, X.shape[1]]))],
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X.astype(np.float32),
         model,
         model_onnx,
         basename="SklearnSGDClassifierBinaryLog-Dec4",
         allow_failure="StrictVersion(onnx.__version__)"
                       " < StrictVersion('1.2') or "
                       "StrictVersion(onnxruntime.__version__)"
                       " <= StrictVersion('0.2.1')",
     )
Example #29
0
 def test_ada_boost_classifier_bool(self):
     model, X_test = fit_classification_model(
         AdaBoostClassifier(random_state=42), 3, is_bool=True)
     model_onnx = convert_sklearn(
         model,
         "AdaBoost classification",
         [("input", BooleanTensorType((None, X_test.shape[1])))],
         target_opset=10,
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X_test,
         model,
         model_onnx,
         basename="SklearnAdaBoostClassifierBool",
         allow_failure="StrictVersion("
         "onnxruntime.__version__)"
         "<= StrictVersion('0.2.1')",
     )
 def test_model_sgd_multi_class_hinge(self):
     model, X = fit_classification_model(
         SGDClassifier(loss='hinge', random_state=42), 5)
     model_onnx = convert_sklearn(
         model,
         "scikit-learn SGD multi-class classifier",
         [("input", FloatTensorType([None, X.shape[1]]))],
     )
     self.assertIsNotNone(model_onnx)
     dump_data_and_model(
         X.astype(np.float32),
         model,
         model_onnx,
         basename="SklearnSGDClassifierMultiHinge-Out0",
         allow_failure="StrictVersion(onnx.__version__)"
                       " < StrictVersion('1.2') or "
                       "StrictVersion(onnxruntime.__version__)"
                       " <= StrictVersion('0.2.1')",
     )