ONNX export of Extra Trees

ONNX export of Extra Trees 1:

Download Python samples

A Zip archive containing all samples can be found here: Samples of ONNX export

Extra Trees Regressor with Scikit-learn

from sklearn.ensemble import ExtraTreesRegressor
from sklearn.datasets import make_regression
from skl2onnx import convert_sklearn
from skl2onnx.common.data_types import FloatTensorType
# import onnx

# # Generate data for regression
X, y =  make_regression(n_samples=300, n_features=10, n_informative=10, n_targets=1)
# # Construct the model
model = ExtraTreesRegressor(max_depth=None, n_estimators=100)
model.fit(X,y)

# # Convert model to ONNX
onnxfile = 'extratrees-regressor.onnx'
initial_type = [('float_input', FloatTensorType([None, X.shape[1]]))]
onnx_model = convert_sklearn(model, initial_types=initial_type, target_opset=12)
# # Export to ONNX file
# onnx.checker.check_model(onnx_model)
with open(onnxfile, "wb") as f:
    f.write( onnx_model.SerializeToString())
f.close()
exit()
ONNX export of Extra Trees 2:

Extra Trees Classifier with Scikit-learn

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import ExtraTreesClassifier
from skl2onnx import convert_sklearn
from skl2onnx.common.data_types import FloatTensorType

# # Load data for classification
X, y = load_iris(return_X_y = True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.1)
# # Construct ExtraTrees-Model
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.1)
model = ExtraTreesClassifier(criterion ='entropy', n_estimators=100, max_features=None)
model.fit(X_train,y_train)
# # Export model into ONNX format
onnxfile = 'extratrees-classifier.onnx'
initial_type = [('float_input', FloatTensorType([None, X.shape[1]]))]
# # Zipmap should be always turned off as it's not implemented in TF3800
onnx_model = convert_sklearn(model, initial_types=initial_type, options={type(model): {'zipmap':False}})
# # Export to ONNX file
with open(onnxfile, "wb") as f:
    f.write( onnx_model.SerializeToString())
f.close()
exit()
ONNX export of Extra Trees 3: