def test_getattr(client): # Test getattr on local param kmeans_model = KMeans(client=client) # Test AttributeError with pytest.raises(AttributeError): kmeans_model.cluster_centers_ assert kmeans_model.client is not None # Test getattr on local_model param with a non-distributed model X, y = make_blobs(n_samples=5, n_features=5, centers=2, n_parts=2, cluster_std=0.01, random_state=10) kmeans_model.fit(X) assert kmeans_model.cluster_centers_ is not None assert isinstance(kmeans_model.cluster_centers_, cupy.core.ndarray) # Test getattr on trained distributed model X, y = load_text_corpus(client) nb_model = MultinomialNB(client=client) nb_model.fit(X, y) assert nb_model.feature_count_ is not None assert isinstance(nb_model.feature_count_, cupy.core.ndarray)
def test_basic_fit_predict(client): X, y = load_text_corpus(client) model = MultinomialNB() model.fit(X, y) y_hat = model.predict(X) y_hat = y_hat.compute() y = y.compute() assert(accuracy_score(y_hat.get(), y) > .97)
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_single_distributed_exact_results(client): X, y = load_text_corpus(client) sgX, sgy = (X.compute(), y.compute()) model = MultinomialNB() model.fit(X, y) sg_model = SGNB() sg_model.fit(sgX, sgy) y_hat = model.predict(X) sg_y_hat = sg_model.predict(sgX).get() y_hat = y_hat.compute().get() assert(accuracy_score(y_hat, sg_y_hat) == 1.0)
def test_getattr(cluster): client = Client(cluster) try: # Test getattr on local param kmeans_model = KMeans(client=client) assert kmeans_model.client is not None # Test getattr on local_model param with a non-distributed model X, y = make_blobs(n_samples=5, n_features=5, centers=2, n_parts=2, cluster_std=0.01, random_state=10) wait(X) kmeans_model.fit(X) assert kmeans_model.cluster_centers_ is not None assert isinstance(kmeans_model.cluster_centers_, cupy.core.ndarray) # Test getattr on trained distributed model X, y = load_text_corpus(client) print(str(X.compute())) nb_model = MultinomialNB(client=client) nb_model.fit(X, y) assert nb_model.feature_count_ is not None assert isinstance(nb_model.feature_count_, cupy.core.ndarray) finally: client.close()
def test_getattr(cluster): client = Client(cluster) # Test getattr on local param kmeans_model = KMeans(client=client) assert kmeans_model.client is not None # Test getattr on local_model param with a non-distributed model X_cudf, y = make_blobs(5, 5, 2, 2, cluster_std=0.01, verbose=False, random_state=10) wait(X_cudf) kmeans_model.fit(X_cudf) assert kmeans_model.cluster_centers_ is not None assert isinstance(kmeans_model.cluster_centers_, cudf.DataFrame) # Test getattr on trained distributed model X, y = load_text_corpus(client) print(str(X.compute())) nb_model = MultinomialNB(client=client) nb_model.fit(X, y) assert nb_model.feature_count_ is not None assert isinstance(nb_model.feature_count_, cupy.core.ndarray)