module mlmodel.sklearn_testing
¶
Short summary¶
module mlinsights.mlmodel.sklearn_testing
Helpers to test a model which follows scikit-learn API.
Functions¶
function |
truncated documentation |
---|---|
Checks that two models are equal. |
|
Clones an estimator with the fitted results. |
|
Tests that a cloned model is similar to the original one. |
|
Creates a model, checks that a grid search works with it. |
|
Creates a model, fit, predict and check the prediction are similar after the model was pickled, unpickled. |
|
Splits into train and test data even if they are None. |
Documentation¶
Helpers to test a model which follows scikit-learn API.
-
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.
-
mlinsights.mlmodel.sklearn_testing.
clone_with_fitted_parameters
(est)[source]¶ Clones an estimator with the fitted results.
- Parameters
est – estimator
- Returns
cloned object
-
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
-
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
-
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
-
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`.