def test_score(client): X, y = load_text_corpus(client) model = MultinomialNB() model.fit(X, y) y_hat = model.predict(X) score = model.score(X, y) y_hat_local = y_hat.compute() y_local = y.compute() assert (accuracy_score(y_hat_local.get(), y_local) == score)
def test_model_multiple_chunks(client, dtype): # tests naive_bayes with n_chunks being greater than one, related to issue # https://github.com/rapidsai/cuml/issues/3150 X = cp.array([[0, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 0]]) X = dask.array.from_array(X, chunks=((1, 1, 1), -1)).astype(dtype) y = dask.array.from_array([1, 0, 0], asarray=False, fancy=False, chunks=(1)).astype(cp.int32) model = MultinomialNB() model.fit(X, y) # this test is a code coverage test, it is too small to be a numeric test, # but we call score here to exercise the whole model. assert(0 <= model.score(X, y) <= 1)