def test_random_forest_classifier_mismatched_estimator_counts(self): model = RandomForestClassifier(n_estimators=3) X = [[0, 1], [1, 1], [2, 0]] X = numpy.array(X, dtype=numpy.float32) y = ['A', 'B', 'A'] model.fit(X, y) # Training code can manipulate n_estimators causing # n_estimators != len(estimators_). So simulate that here. model.n_estimators += 1 model_onnx, prefix = convert_model(model, 'binary classifier', [('input', FloatTensorType([None, 2]))]) dump_data_and_model(X, model, model_onnx, basename=prefix + "Bin" + model.__class__.__name__ + '_mismatched_estimator_counts')
def test_random_forest_regressor_mismatches(self): iris = load_iris() X, y = iris.data, iris.target X_train, X_test, y_train, _ = train_test_split(X, y, random_state=13) X_test = X_test.astype(numpy.float32) clr = RandomForestRegressor(n_jobs=1, n_estimators=100) clr.fit(X_train, y_train) clr.fit(X, y) model_onnx, prefix = convert_model( clr, 'reg', [('input', FloatTensorType([None, 4]))]) dump_data_and_model(X_test, clr, model_onnx, basename=prefix + "RegMis" + clr.__class__.__name__ + '_mismatched_estimator_counts')
def test_random_forest_regressor_mismatched_estimator_counts(self): model = RandomForestRegressor(n_estimators=3) X = [[0, 1], [1, 1], [2, 0]] X = numpy.array(X, dtype=numpy.float32) y = numpy.array([100, -10, 50], dtype=numpy.float32) model.fit(X, y) # Training code can manipulate n_estimators causing # n_estimators != len(estimators_). So simulate that here. model.n_estimators += 1 model_onnx, prefix = convert_model(model, 'single regressor', [('input', FloatTensorType([None, 2]))]) dump_data_and_model(X, model, model_onnx, basename=prefix + "Reg" + model.__class__.__name__ + "_mismatched_estimator_counts")