module mlmodel.sklearn_testing

Short summary

module mlinsights.mlmodel.sklearn_testing

Helpers to test a model which follows scikit-learn API.

source on GitHub

Functions

function

truncated documentation

_assert_dict_equal

_assert_list_equal

_assert_tuple_equal

assert_estimator_equal

Checks that two models are equal.

clone_with_fitted_parameters

Clones an estimator with the fitted results.

test_sklearn_clone

Tests that a cloned model is similar to the original one.

test_sklearn_grid_search_cv

Creates a model, checks that a grid search works with it.

test_sklearn_pickle

Creates a model, fit, predict and check the prediction are similar after the model was pickled, unpickled.

train_test_split_with_none

Splits into train and test data even if they are None.

Documentation

Helpers to test a model which follows scikit-learn API.

source on GitHub

mlinsights.mlmodel.sklearn_testing._assert_dict_equal(a, b, ext)[source]
mlinsights.mlmodel.sklearn_testing._assert_list_equal(l1, l2, ext)[source]
mlinsights.mlmodel.sklearn_testing._assert_tuple_equal(t1, t2, ext)[source]
mlinsights.mlmodel.sklearn_testing.assert_estimator_equal(esta, estb, ext=None)[source]

Checks that two models are equal.

Parameters
  • esta – first estimator

  • estb – second estimator

  • ext – unit test class

The function raises an exception if the comparison fails.

source on GitHub

mlinsights.mlmodel.sklearn_testing.clone_with_fitted_parameters(est)[source]

Clones an estimator with the fitted results.

Parameters

est – estimator

Returns

cloned object

source on GitHub

mlinsights.mlmodel.sklearn_testing.test_sklearn_clone(fct_model, ext=None, copy_fitted=False)[source]

Tests that a cloned model is similar to the original one.

Parameters
  • fct_model – function which creates the model

  • ext – unit test class instance

  • copy_fitted – copy fitted parameters as well

Returns

model, cloned model

Raises

AssertionError

source on GitHub

mlinsights.mlmodel.sklearn_testing.test_sklearn_grid_search_cv(fct_model, X, y=None, sample_weight=None, **grid_params)[source]

Creates a model, checks that a grid search works with it.

Parameters
  • fct_model – function which creates the model

  • X – X

  • y – y

  • sample_weight – sample weight

  • grid_params – parameter to use to run the grid search.

Returns

dictionary with results

Raises

AssertionError

source on GitHub

mlinsights.mlmodel.sklearn_testing.test_sklearn_pickle(fct_model, X, y=None, sample_weight=None, **kwargs)[source]

Creates a model, fit, predict and check the prediction are similar after the model was pickled, unpickled.

Parameters
  • fct_model – function which creates the model

  • X – X

  • y – y

  • sample_weight – sample weight

  • kwargs – additional parameters for numpy.testing.assert_almost_equal

Returns

model, unpickled model

Raises

AssertionError

source on GitHub

mlinsights.mlmodel.sklearn_testing.train_test_split_with_none(X, y=None, sample_weight=None, random_state=0)[source]

Splits into train and test data even if they are None.

Parameters
  • X – X

  • y – y

  • sample_weight – sample weight

  • random_state – random state

Returns

similar to :epkg:`scikit-learn:model_selection:train_test_split`.

source on GitHub