def test_model_error_returns_nan(): with mock.patch('sklearn.base.clone', lambda x: x): mock_model = mock.MagicMock() def mock_fit(*args, **kwargs): raise ValueError() mock_model.fit = mock_fit with pytest.warns(ModelFitWarning): scores = cross_val_score(mock_model, y, scoring='mean_squared_error', cv=SlidingWindowForecastCV( window_size=100, step=24, h=1), verbose=0) assert np.isnan(scores).all() # if the error_score is 'raise', we will raise with pytest.raises(ValueError): cross_val_score(mock_model, y, scoring='mean_squared_error', cv=SlidingWindowForecastCV(window_size=100, step=24, h=1), verbose=0, error_score='raise')
def test_cv_scores(cv, est, verbose): scores = cross_val_score(est, y, scoring='mean_squared_error', cv=cv, verbose=verbose) assert isinstance(scores, np.ndarray)