cuml icon indicating copy to clipboard operation
cuml copied to clipboard

AttributeError: 'cupy._core.core.ndarray' object has no attribute 'nnz'

Open kyledufrane opened this issue 2 years ago • 3 comments

I'm trying to run a pipeline seen below to encode categorical features and scale numerics. The data is being loaded using cudf and all associated libraries (train_test_split, standardscaler) are being used from the cuml library.

Steps/Code to reproduce bug

train_df = cudf.read_parquet('data/ml_training.parquet')

X = train_df.drop(['status_group'], axis=1)
y = train_df['status_group']

le = LabelEncoder()
y = le.fit_transform(y)

X = X[columns_]

X_train, X_test, y_train, y_test = train_test_split(X,y, random_state=42, stratify=y)

num_feats = X.select_dtypes(['int', 'float']).columns.tolist()
int_feats = X.select_dtypes('int').columns.tolist()
float_feats = X.select_dtypes('float').columns.tolist()
cat_feats = X.select_dtypes('object').columns.tolist()

X[int_feats] = X[int_feats].astype('int32')
X[float_feats] = X[float_feats].astype('float32')
X[cat_feats] = X[cat_feats].astype('category')

numeric_pipe = StandardScaler()

cat_pipe = OneHotEncoder(handle_unknown='ignore')

preprocessor = ColumnTransformer(
transformers=[
    (
        'numeric', numeric_pipe, num_feats
    ),
    (
        'categorical', cat_pipe, cat_feats
    )
]
)

model_pipe = Pipeline(
steps=[
    (
        'preprocessor', preprocessor
    ),
    (
        'classifier', RandomForestClassifier()
    )
]
)

model_pipe.fit(X_train, y_train)
  • Environment location: [Bare-metal, Docker, Cloud(specify cloud provider)]
  • Linux Distro/Architecture: [Ubuntu 20.04 amd64]
  • GPU Model/Driver: RTX-3090 510.73.08
  • CUDA: 11.6
  • Method of cuDF & cuML install: conda

kyledufrane avatar Jul 29 '22 00:07 kyledufrane

I found the issue to be in the OneHotEncoder. The default argument for sparse is set to True but the docs show this is not support by cupy yet. Is there a reason why the default argument is set to True?

kyledufrane avatar Jul 29 '22 19:07 kyledufrane

The default argument is set to True to follow sklearn's behavior. The CuPy issue was apparently resolved on cuSparse side. Its mention should be removed from the doc.

The code provided didn't allowed me to know where the AttributeError was raised. Could you provide a minimal reproducer?

viclafargue avatar Aug 11 '22 12:08 viclafargue

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

github-actions[bot] avatar Sep 10 '22 13:09 github-actions[bot]