Skip to content

Instantly share code, notes, and snippets.

View dantegd's full-sized avatar

Dante Gama Dessavre dantegd

View GitHub Profile
import cupy as cp
import cuml
ary = cp.array([[1.0, 4.0, 4.0], [2.0, 2.0, 2.0], [5.0, 1.0, 1.0]])
kmeams = cuml.KMeans(n_clusters=2, output_type='numpy')
kmeans.fit(ary)
print(type(kmeans.labels_))
# <class 'numpy.ndarray'>
@dantegd
dantegd / cuml_cudf.py
Created April 28, 2020 15:29
Default input format type mirroring behavior of cuML
import cuml
import cudf
df = cudf.DataFrame()
df[1] = [1.0, 2.0, 5.0]
df[2] = [4.0, 2.0. 1.0]
df[3] = [4.0, 2.0. 1.0]
kmeans = cuml.KMeans(n_clusters=2)
kmeans.fit(df)
@dantegd
dantegd / cuml_output_type_context_mgr.py
Created April 28, 2020 14:58
Usage of cuML's context manager `using_output_type`
import cuml
import cupy as cp
ary = [[1.0, 4.0, 4.0], [2.0, 2.0, 2.0], [5.0, 1.0, 1.0]]
ary = cp.asarray(ary)
with cuml.using_output_type('cudf'):
dbscan = cuml.DBSCAN(eps=1.0, min_samples=1)
dbscan.fit(ary)
print(type(dbscan_float.labels_))
@dantegd
dantegd / cuml_global_output_type.py
Created April 28, 2020 14:54
Usage of cuML's set_global_output_type
import cupy as cp
import numpy as np
import cuml
cuml.set_global_output_type('numpy')
ary = cp.array([[1.0, 4.0, 4.0], [2.0, 2.0, 2.0], [5.0, 1.0, 1.0]])
kmeans = cuml.KMeans(n_clusters=2)
kmeans.fit(ary)
@dantegd
dantegd / cuml_numpy_example.py
Created April 28, 2020 14:47
Default input format type mirroring behavior of cuML mirroring NumPy arrays
import cuml
import numpy as np
ary = np.array([[1.0, 4.0, 4.0], [2.0, 2.0, 2.0], [5.0, 1.0, 1.0]])
kmeans = cuml.KMeans(n_clusters=2)
kmeans.fit(ary)
print(type(kmeans.labels_))
# <class ‘numpy.ndarray’>