def test_space_net_alpha_grid_pure_spatial(): rng = check_random_state(42) X = rng.randn(10, 100) y = np.arange(X.shape[0]) for is_classif in [True, False]: assert_false(np.any(np.isnan(_space_net_alpha_grid( X, y, l1_ratio=0., logistic=is_classif))))
def test_space_net_alpha_grid(n_samples=4, n_features=3): rng = check_random_state(42) X = rng.randn(n_samples, n_features) y = np.arange(n_samples) for l1_ratio, is_classif in itertools.product([.5, 1.], [True, False]): alpha_max = np.max(np.abs(np.dot(X.T, y))) / l1_ratio np.testing.assert_almost_equal(_space_net_alpha_grid( X, y, n_alphas=1, l1_ratio=l1_ratio, logistic=is_classif), alpha_max) for l1_ratio, is_classif in itertools.product([.5, 1.], [True, False]): alpha_max = np.max(np.abs(np.dot(X.T, y))) / l1_ratio for n_alphas in range(1, 10): alphas = _space_net_alpha_grid( X, y, n_alphas=n_alphas, l1_ratio=l1_ratio, logistic=is_classif) np.testing.assert_almost_equal(alphas.max(), alpha_max) np.testing.assert_almost_equal(n_alphas, len(alphas))
def test_space_net_alpha_grid_same_as_sk(): try: from sklearn.linear_model.coordinate_descent import _alpha_grid iris = load_iris() X = iris.data y = iris.target np.testing.assert_almost_equal( _space_net_alpha_grid(X, y, n_alphas=5), X.shape[0] * _alpha_grid(X, y, n_alphas=5, fit_intercept=False)) except ImportError: raise SkipTest
def test_space_net_alpha_grid_same_as_sk(): try: from sklearn.linear_model.coordinate_descent import _alpha_grid iris = load_iris() X = iris.data y = iris.target np.testing.assert_almost_equal(_space_net_alpha_grid( X, y, n_alphas=5), X.shape[0] * _alpha_grid(X, y, n_alphas=5, fit_intercept=False)) except ImportError: raise SkipTest