Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REVIEW] Refactor kmeans sampling code #4190

Merged
merged 3 commits into from
Sep 14, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions python/cuml/explainer/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import cudf
import cupy as cp
import numpy as np
import pandas as pd
from numba import cuda
from scipy.sparse import issparse

import cuml
Expand Down Expand Up @@ -65,24 +61,19 @@ def kmeans_sampling(X, k, round_values=True, detailed=False, random_state=0):
dtypes: cuDF DataFrame, cuDF Series, cupy, numba,\
numpy, pandas DataFrame, pandas Series")

if output_dtype == cudf.DataFrame:
if "DataFrame" in str(output_dtype):
group_names = X.columns
X = X.values
elif output_dtype == cudf.Series:
if "pd" in str(output_dtype):
X = cp.array(X.values)
Nanthini10 marked this conversation as resolved.
Show resolved Hide resolved
if "Series" in str(output_dtype):
group_names = X.name
X = X.values.reshape(-1, 1)
elif output_dtype == pd.DataFrame:
group_names = X.columns
X = cp.array(X.values)
elif output_dtype == pd.Series:
group_names = X.name
X = cp.array(X.values.reshape(-1, 1))
if "pd" in str(output_dtype):
X = cp.array(X)
else:
# it's either numpy, cupy or numba
if output_dtype == cuda.devicearray.DeviceNDArrayBase:
X = cp.array(X)
elif output_dtype == np.ndarray:
X = cp.array(X)
X = cp.array(X)
try:
# more than one column
group_names = [str(i) for i in range(X.shape[1])]
Expand Down