@ignore_warnings
def check_estimators_pickle(name, Estimator):
 check_methods = ['predict', 'transform', 'decision_function', 'predict_proba']
 (X, y) = make_blobs(n_samples=30, centers=[[0, 0, 0], [1, 1, 1]], random_state=0, n_features=2, cluster_std=0.1)
 X -= X.min()
 y = multioutput_estimator_convert_y_2d(name, y)
 estimator = Estimator()
 set_random_state(estimator)
 set_testing_parameters(estimator)
 estimator.fit(X, y)
 result = dict()
 for method in check_methods:
  if hasattr(estimator, method):
   result[method] = getattr(estimator, method)(X)
 pickled_estimator = pickle.dumps(estimator)
 if Estimator.__module__.startswith('sklearn.'):
  assert_true(('version' in pickled_estimator))
 unpickled_estimator = pickle.loads(pickled_estimator)
 for method in result:
  unpickled_result = getattr(unpickled_estimator, method)(X)
  assert_array_almost_equal(result[method], unpickled_result)

@ ignore_warnings def check_estimators_pickle ( name , Estimator ) : check_methods = [ 'predict' , 'transform' , 'decision_function' , 'predict_proba' ] ( X , y ) = make_blobs ( n_samples = 30 , centers = [ [ 0 , 0 , 0 ] , [ 1 , 1 , 1 ] ] , random_state = 0 , n_features = 2 , cluster_std = 0.1 ) X -= X . min ( ) y = multioutput_estimator_convert_y_2d ( name , y ) estimator = Estimator ( ) set_random_state ( estimator ) set_testing_parameters ( estimator ) estimator . fit ( X , y ) result = dict ( ) for method in check_methods : if hasattr ( estimator , method ) : result [ method ] = getattr ( estimator , method ) ( X ) pickled_estimator = pickle . dumps ( estimator ) if Estimator . __module__ . startswith ( 'sklearn.' ) : assert_true ( ( 'version' in pickled_estimator ) ) unpickled_estimator = pickle . loads ( pickled_estimator ) for method in result : unpickled_result = getattr ( unpickled_estimator , method ) ( X ) assert_array_almost_equal ( result [ method ] , unpickled_result )
test that we can pickle all estimators .