Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Adaboost converter's incorrect results with non-default LR #223

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions skl2onnx/operator_converters/ada_boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def convert_sklearn_ada_boost_classifier(scope, operator, container):
attrs['classlabels_strings'] = classes

add_tree_to_attribute_pairs(attrs, True, op.estimators_[tree_id].tree_,
0, op.learning_rate, 0, True)
0, 1, 0, True)
container.add_node(
op_type, operator.input_full_names,
[label_name, proba_name],
Expand Down Expand Up @@ -234,7 +234,7 @@ def _get_estimators_label(scope, operator, container, model):
attrs['n_targets'] = int(model.estimators_[tree_id].n_outputs_)
add_tree_to_attribute_pairs(attrs, False,
model.estimators_[tree_id].tree_,
0, model.learning_rate, 0, False)
0, 1, 0, False)

container.add_node(op_type, input_name,
estimator_label_name, op_domain='ai.onnx.ml',
Expand Down
47 changes: 47 additions & 0 deletions tests/test_sklearn_adaboost_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ def test_ada_boost_classifier_samme(self):
"<= StrictVersion('0.2.1')",
)

@unittest.skipIf(not onnx_built_with_ml(),
reason="Requires ONNX-ML extension.")
def test_ada_boost_classifier_lr(self):
data = load_digits()
X, y = data.data, data.target
X = X.astype('int64')
X_train, X_test, y_train, y_test = train_test_split(X,
y,
test_size=0.2,
random_state=42)
model = AdaBoostClassifier(learning_rate=0.3, random_state=42)
model.fit(X_train, y_train)
model_onnx = convert_sklearn(
model,
"AdaBoost classification",
[("input", Int64TensorType(X_test.shape))],
)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X_test,
model,
model_onnx,
basename="SklearnAdaBoostClassifierLR",
allow_failure="StrictVersion("
"onnxruntime.__version__)"
"<= StrictVersion('0.2.1')",
)

def test_ada_boost_regressor(self):
model, X = fit_regression_model(
AdaBoostRegressor(n_estimators=5))
Expand Down Expand Up @@ -107,6 +135,25 @@ def test_ada_boost_regressor_int(self):
"== StrictVersion('1.4.1')",
)

def test_ada_boost_regressor_lr(self):
model, X = fit_regression_model(
AdaBoostRegressor(learning_rate=0.5, random_state=42))
model_onnx = convert_sklearn(
model, "AdaBoost regression",
[("input", FloatTensorType([1, X.shape[1]]))])
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
basename="SklearnAdaBoostRegressorLR-OneOffArray-Dec4",
allow_failure="StrictVersion("
"onnxruntime.__version__) "
"<= StrictVersion('0.2.1') or "
"StrictVersion(onnx.__version__) "
"== StrictVersion('1.4.1')",
)


if __name__ == "__main__":
unittest.main()