Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@unittest.skipIf(StrictVersion(ort_version) <= StrictVersion("0.4.0"),
reason="issues with shapes")
@unittest.skipIf(
not one_hot_encoder_supports_string(),
reason="OneHotEncoder did not have categories_ before 0.20",
)
def test_model_one_hot_encoder(self):
model = OneHotEncoder(categories='auto')
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([None, 3]))],
)
self.assertTrue(model_onnx is not None)
@unittest.skipIf(StrictVersion(ort_version) <= StrictVersion("0.4.0"),
reason="issues with shapes")
@unittest.skipIf(
not one_hot_encoder_supports_string(),
reason="OneHotEncoder does not support strings in 0.19",
)
def test_one_hot_encoder_twocats(self):
data = [["cat2"], ["cat1"]]
model = OneHotEncoder(categories="auto")
model.fit(data)
inputs = [("input1", StringTensorType([None, 1]))]
model_onnx = convert_sklearn(model, "one-hot encoder two string cats",
inputs)
self.assertTrue(model_onnx is not None)
dump_data_and_model(
data,
model,
StrictVersion(__version__) <= StrictVersion(THRESHOLD),
reason="Depends on PR #1015 onnxruntime.")
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)})
def _get_backend_version(self):
version = None
if self.backend == "onnxruntime":
import onnxruntime as ort
version = ort.__version__
elif self.backend == "caffe2":
# TODO: get caffe2 version
pass
if version:
version = LooseVersion(version)
return version
StrictVersion(ort_version) <= StrictVersion("0.4.0"),
reason="old onnxruntime does not support double")
def test_model_linear_regression64(self):
model, X = fit_regression_model(linear_model.LinearRegression())
model_onnx = convert_sklearn(model, "linear regression",
[("input", DoubleTensorType(X.shape))],
dtype=numpy.float64)
self.assertIsNotNone(model_onnx)
self.assertIn("elem_type: 11", str(model_onnx))
compare_objects(skl_outputs['predict_proba'], onnx_outputs[1])
print("benchmark", step['model'].__class__)
print("scikit-learn")
print(timeit("step['model'].predict_proba(X_digits[:1])",
number=10000, globals=globals()))
print("onnxruntime")
print(timeit("sess.run(None, {'input': X_digits[:1].astype(np.float32)})",
number=10000, globals=globals()))
#################################
# **Versions used for this example**
print("numpy:", numpy.__version__)
print("scikit-learn:", sklearn.__version__)
print("onnx: ", onnx.__version__)
print("onnxruntime: ", onnxruntime.__version__)
print("skl2onnx: ", skl2onnx.__version__)
os.system('dot -O -Gdpi=300 -Tpng pipeline_transpose2x.dot')
image = plt.imread("pipeline_transpose2x.dot.png")
fig, ax = plt.subplots(figsize=(40, 20))
ax.imshow(image)
ax.axis('off')
#################################
# **Versions used for this example**
import numpy, sklearn # noqa
print("numpy:", numpy.__version__)
print("scikit-learn:", sklearn.__version__)
import onnx, onnxruntime, skl2onnx # noqa
print("onnx: ", onnx.__version__)
print("onnxruntime: ", onnxruntime.__version__)
print("skl2onnx: ", skl2onnx.__version__)
def version(self):
return rt.__version__
pydot_graph.write_dot("pipeline.dot")
os.system('dot -O -Gdpi=300 -Tpng pipeline.dot')
image = plt.imread("pipeline.dot.png")
fig, ax = plt.subplots(figsize=(40, 20))
ax.imshow(image)
ax.axis('off')
#################################
# **Versions used for this example**
print("numpy:", numpy.__version__)
print("scikit-learn:", sklearn.__version__)
print("onnx: ", onnx.__version__)
print("onnxruntime: ", onnxruntime.__version__)
print("skl2onnx: ", skl2onnx.__version__)
print("onnxmltools: ", onnxmltools.__version__)
print("lightgbm: ", lightgbm.__version__)
label, proba = rep.run(x)
print("label={}".format(label))
print("probabilities={}".format(proba))
#######################################
# The backend API is implemented by other frameworks
# and makes it easier to switch between multiple runtimes
# with the same API.
#################################
# **Versions used for this example**
print("numpy:", numpy.__version__)
print("scikit-learn:", sklearn.__version__)
print("onnx: ", onnx.__version__)
print("onnxruntime: ", onnxruntime.__version__)
print("skl2onnx: ", skl2onnx.__version__)