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

Extend coverage for OneHotEncoder #188

Merged
merged 27 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
784d64b
Enables opset 9 for TextVectorizer
sdpython Apr 24, 2019
0047376
check random forest
sdpython May 10, 2019
d18b90c
fix spaces
sdpython Jun 10, 2019
249b19f
update converter for TfIdf after a change of spec in onnxruntime
sdpython Jun 11, 2019
1cae401
check random forest
sdpython May 10, 2019
98e45ef
Merge branch 'master' of https://github.com/onnx/sklearn-onnx
sdpython Jun 20, 2019
2e796a4
Delete test_SklearnGradientBoostingConverters.py
sdpython Jun 20, 2019
b0bb922
Extend coverage
sdpython Jun 20, 2019
02ed4e6
disable one test on 0.19
sdpython Jun 20, 2019
c39dc25
Update test_sklearn_one_hot_encoder_converter.py
sdpython Jun 20, 2019
f7eecdd
Merge branch 'master' of https://github.com/onnx/sklearn-onnx
sdpython Jun 25, 2019
e088a80
Merge branch 'master' into ohe
xadupre Jun 26, 2019
41e8145
rename ModuleFoundError into ImportError (not allowed in python3.5)
sdpython Jun 26, 2019
bbe958c
Update tests_helper.py
sdpython Jun 26, 2019
f4601b4
Update tests_helper.py
sdpython Jun 26, 2019
f79bfd2
pep8, CI
sdpython Jul 3, 2019
d9febca
CI, pep8
sdpython Jul 3, 2019
6aeca99
Update win32-conda-CI.yml
sdpython Jul 3, 2019
b638846
Update win32-conda-CI.yml
sdpython Jul 3, 2019
05fb4ce
Update win32-conda-CI.yml
sdpython Jul 3, 2019
10ee6c8
Update win32-conda-CI.yml
sdpython Jul 3, 2019
4b2f1d5
Update test_algebra_onnx_doc.py
sdpython Jul 3, 2019
7495ffb
shorten CI
sdpython Jul 3, 2019
f34c8d3
update CI
sdpython Jul 3, 2019
77f3e28
Merge branch 'importerror' of https://github.com/xadupre/sklearn-onnx…
sdpython Jul 3, 2019
6c3cac8
Merge branch 'master' of https://github.com/xadupre/sklearn-onnx into…
sdpython Jul 3, 2019
859fed9
Merge branch 'master' of https://github.com/onnx/sklearn-onnx into ohe
sdpython Jul 3, 2019
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
2 changes: 2 additions & 0 deletions skl2onnx/operator_converters/one_hot_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def convert_sklearn_one_hot_encoder(scope, operator, container):
raise TypeError("Categories must be int or strings "
"not {0}.".format(cat.dtype))
else:
# Relies on n_values: deprecated in 0.20,
# removed in 0.22.
if op.categorical_features == 'all':
categorical_feature_indices = [i for i in range(C)]
elif isinstance(op.categorical_features, collections.Iterable):
Expand Down
50 changes: 50 additions & 0 deletions tests/test_sklearn_one_hot_encoder_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,56 @@ def test_one_hot_encoder_one_string_one_int_cat(self):
basename="SklearnOneHotEncoderOneStringOneIntCat",
)

@unittest.skipIf(
not one_hot_encoder_supports_string(),
reason="OneHotEncoder does not support this in 0.19",
)
def test_model_one_hot_encoder_list_sparse(self):
model = OneHotEncoder(categories=[[0, 1, 4, 5],
[1, 2, 3, 5],
[0, 3, 4, 6]],
sparse=True)
prabhat00155 marked this conversation as resolved.
Show resolved Hide resolved
data = numpy.array([[1, 2, 3], [4, 3, 0], [0, 1, 4], [0, 5, 6]],
dtype=numpy.int64)
model.fit(data)
model_onnx = convert_sklearn(
model,
"scikit-learn one-hot encoder",
[("input", Int64TensorType([1, 3]))],
)
self.assertTrue(model_onnx is not None)
dump_data_and_model(
data,
model,
model_onnx,
basename="SklearnOneHotEncoderCatSparse-SkipDim1",
)

@unittest.skipIf(
not one_hot_encoder_supports_string(),
reason="OneHotEncoder does not support this in 0.19",
)
def test_model_one_hot_encoder_list_dense(self):
model = OneHotEncoder(categories=[[0, 1, 4, 5],
[1, 2, 3, 5],
[0, 3, 4, 6]],
sparse=False)
data = numpy.array([[1, 2, 3], [4, 3, 0], [0, 1, 4], [0, 5, 6]],
dtype=numpy.int64)
model.fit(data)
model_onnx = convert_sklearn(
model,
"scikit-learn one-hot encoder",
[("input", Int64TensorType([1, 3]))],
)
self.assertTrue(model_onnx is not None)
dump_data_and_model(
data,
model,
model_onnx,
basename="SklearnOneHotEncoderCatDense-SkipDim1",
)


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