def test_parallel_fit(): """The goal of this test is to check that results of _parallel_fit is the same for different controlled param_grid """ X, y = make_regression(n_samples=100, n_features=20, n_informative=5, noise=0.2, random_state=42) train = range(80) test = range(80, len(y_classification)) outputs = [] estimator = svr svr_params = [[1e-1, 1e0, 1e1], [1e-1, 1e0, 5e0, 1e1]] scorer = check_scoring(estimator, 'r2') # define a scorer # Define a screening selector selector = check_feature_screening(screening_percentile=None, mask_img=None, is_classification=False) for params in svr_params: param_grid = {} param_grid['C'] = np.array(params) outputs.append(list(_parallel_fit(estimator=estimator, X=X, y=y, train=train, test=test, param_grid=param_grid, is_classification=False, scorer=scorer, mask_img=None, class_index=1, selector=selector, clustering_percentile=100))) # check that every element of the output tuple is the same for both tries for a, b in zip(outputs[0], outputs[1]): if isinstance(a, np.ndarray): np.testing.assert_array_almost_equal(a, b) else: assert a == b
def test_feature_screening(): # dummy mask_img_data = np.zeros((182, 218, 182)) mask_img_data[30:-30, 30:-30, 30:-30] = 1 affine = np.eye(4) mask_img = nibabel.Nifti1Image(mask_img_data, affine=affine) for is_classif in [True, False]: for screening_percentile in [100, None, 20, 101, -1, 10]: if screening_percentile == 100 or screening_percentile is None: assert check_feature_screening(screening_percentile, mask_img, is_classif) == None elif screening_percentile == 101 or screening_percentile == -1: pytest.raises(ValueError, check_feature_screening, screening_percentile, mask_img, is_classif) elif screening_percentile == 20: assert isinstance( check_feature_screening(screening_percentile, mask_img, is_classif), BaseEstimator)
def test_feature_screening(): # dummy mask_img_data = np.zeros((182, 218, 182)) mask_img_data[30:-30, 30:-30, 30:-30] = 1 affine = np.eye(4) mask_img = nibabel.Nifti1Image(mask_img_data, affine=affine) for is_classif in [True, False]: for screening_percentile in [100, None, 20, 101, -1, 10]: if screening_percentile == 100 or screening_percentile is None: assert_equal(check_feature_screening( screening_percentile, mask_img, is_classif), None) elif screening_percentile == 101 or screening_percentile == -1: assert_raises(ValueError, check_feature_screening, screening_percentile, mask_img, is_classif) elif screening_percentile == 20: assert_true(isinstance(check_feature_screening( screening_percentile, mask_img, is_classif), BaseEstimator))