Ejemplo n.º 1
0
def test_get_dtype_from_model_func():
    X, y = make_regression(n_samples=81, n_features=10, noise=0.1,
                           random_state=42, dtype=np.float32)

    # checking model with float32 dtype
    model_f32 = reg().fit(X, y)

    assert get_dtype_from_model_func(model_f32.predict) == np.float32

    # checking model with float64 dtype
    X = X.astype(np.float64)
    y = y.astype(np.float64)

    model_f64 = reg().fit(X, y)

    assert get_dtype_from_model_func(model_f64.predict) == np.float64

    # checking model that has not been fitted yet
    model_not_fit = reg()

    assert(get_dtype_from_model_func(model_not_fit.predict) is None)

    # checking arbitrary function
    def dummy_func(x):
        return x + x

    assert get_dtype_from_model_func(dummy_func) is None
Ejemplo n.º 2
0
def test_model_func_call_gpu():
    X, y = make_regression(n_samples=81, n_features=10, noise=0.1,
                           random_state=42, dtype=np.float32)

    model = reg().fit(X, y)

    z = model_func_call(X=X,
                        model_func=model.predict,
                        gpu_model=True)

    assert isinstance(z, cp.ndarray)

    z = model_func_call(X=cp.asnumpy(X),
                        model_func=dummy_func,
                        gpu_model=False)

    assert isinstance(z, cp.ndarray)

    with pytest.raises(TypeError):
        z = model_func_call(X=X,
                            model_func=dummy_func,
                            gpu_model=True)

    model = PCA(n_components=10).fit(X)

    z = model_func_call(X=X,
                        model_func=model.transform,
                        gpu_model=True)

    assert isinstance(z, cp.ndarray)
Ejemplo n.º 3
0
def make_regression_dataset(datatype, nrows, ncols):
    ninformative = max(min(ncols, 5), int(math.ceil(ncols / 5)))
    X, y = data.make_regression(dtype=datatype,
                                n_samples=nrows + 1000,
                                n_features=ncols,
                                random_state=SEED,
                                n_informative=ninformative)
    return dsel.train_test_split(X, y, random_state=SEED, train_size=nrows)
Ejemplo n.º 4
0
def test_typeerror_input():
    X, y = make_regression(n_samples=100, n_features=10, random_state=10)
    clf = Lasso()
    clf.fit(X, y)
    exp = KernelExplainer(model=clf.predict, data=X, nsamples=10)
    try:
        _ = exp.shap_values(X)
        assert True
    except TypeError:
        assert False
Ejemplo n.º 5
0
def make_dataset(request):
    nrows, ncols, n_info, datatype = request.param
    X, y = make_regression(n_samples=nrows,
                           n_informative=n_info,
                           n_features=ncols,
                           random_state=0)
    X = cp.array(X).astype(datatype)
    y = cp.array(y).astype(datatype)
    X_train, X_test, y_train, y_test = train_test_split(X,
                                                        y,
                                                        train_size=0.8,
                                                        random_state=10)

    return nrows, datatype, X_train, X_test, y_train, y_test
Ejemplo n.º 6
0
def make_dataset(request):
    nrows, ncols, n_info, datatype = request.param
    if nrows == 500000 and datatype == np.float64 and \
            pytest.max_gpu_memory < 32:
        if pytest.adapt_stress_test:
            nrows = nrows * pytest.max_gpu_memory // 32
        else:
            pytest.skip("Insufficient GPU memory for this test."
                        "Re-run with 'CUML_ADAPT_STRESS_TESTS=True'")
    X, y = make_regression(n_samples=nrows,
                           n_informative=n_info,
                           n_features=ncols,
                           random_state=0)
    X = cp.array(X).astype(datatype)
    y = cp.array(y).astype(datatype)
    X_train, X_test, y_train, y_test = train_test_split(X,
                                                        y,
                                                        train_size=0.8,
                                                        random_state=10)

    return nrows, datatype, X_train, X_test, y_train, y_test
Ejemplo n.º 7
0
def regression_dataset(request):
    X, y = make_regression(n_samples=10, n_features=5, random_state=0)
    return train_test_split(X, y, random_state=0)