def test_ridge_dtype(): x, y = datasets.make_regression(n_features=3, n_targets=7, n_samples=6, random_state=1) x = np.asarray(x, dtype="float32") y = np.asarray(y, dtype="float32") reg = ridge.RidgeGCV(alphas=ALPHAS).fit(x, y) assert reg.coef_.dtype == "float32" y = np.asarray(y, dtype="float64") reg = ridge.RidgeGCV(alphas=ALPHAS).fit(x, y) assert reg.coef_.dtype == "float64"
def test_simple_encoder(): x, y, voc = _dataset_and_voc() vect = tokenization.TextVectorizer.from_vocabulary(voc) ridge_reg = ridge.RidgeGCV().fit(x, y) reg = ridge.FittedLinearModel(ridge_reg.coef_, ridge_reg.intercept_) encoder = encoding.SimpleEncoder(vect, reg, mask_img=_mask_img(y.shape[1])) text = "feature0 and feature8" res = encoder(text) with tempfile.TemporaryDirectory() as tmp_dir: encoder.to_data_dir(tmp_dir) loaded = encoding.SimpleEncoder.from_data_dir(tmp_dir) encoded = image.get_data(loaded(text)["brain_map"]) assert np.allclose(encoded, image.get_data(res["brain_map"])) assert len(encoder.full_vocabulary()) == 91
def test_ridge(noise, n_samples): x, y = datasets.make_regression( n_features=100, n_targets=33, effective_rank=4, bias=100, n_informative=7, shuffle=False, noise=noise, n_samples=n_samples, random_state=1, ) x += 71 y -= 370 xx, yy = x.copy(), y.copy() sk_ridge = RidgeCV(alphas=ALPHAS).fit(x, y) reg = ridge.RidgeGCV(alphas=ALPHAS).fit(x, y) assert sk_ridge.alpha_ == reg.alpha_ assert np.allclose(reg.coef_, sk_ridge.coef_, atol=1e-7) assert np.allclose(reg.intercept_, sk_ridge.intercept_) assert (x == xx).all() assert (y == yy).all()