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

Remove direct Scikit-learn imports #4431

Merged
merged 4 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import cuml
from cuml.internals.global_settings import _global_settings_data
from cuml.common.array_sparse import SparseCumlArray
from cuml.common.import_utils import has_sklearn
from cuml.internals import _deprecate_pos_args
from ..utils.skl_dependencies import TransformerMixin, BaseComposition, \
BaseEstimator
Expand Down Expand Up @@ -549,6 +550,9 @@ def __init__(self,
n_jobs=None,
transformer_weights=None,
verbose=False):
if not has_sklearn():
raise ImportError("Scikit-learn is needed to use the "
"Column Transformer")
if not transformers:
warnings.warn('Transformers are required')
self.transformers = transformers
Expand Down
5 changes: 4 additions & 1 deletion python/cuml/model_selection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
#

from cuml.model_selection._split import train_test_split
from sklearn.model_selection import GridSearchCV
from cuml.common.import_utils import has_sklearn

if has_sklearn():
from sklearn.model_selection import GridSearchCV


GridSearchCV.__doc__ = """
Expand Down
6 changes: 5 additions & 1 deletion python/cuml/multiclass/multiclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#

import cuml.internals
import sklearn.multiclass

from cuml.common.array import CumlArray
from cuml.common.base import Base
from cuml.common.import_utils import has_sklearn
from cuml.common.mixins import ClassifierMixin
from cuml.common.doc_utils import generate_docstring
from cuml.common import input_to_host_array
Expand Down Expand Up @@ -112,6 +112,10 @@ def fit(self, X, y) -> 'MulticlassClassifier':
"""
Fit a multiclass classifier.
"""
if not has_sklearn():
raise ImportError("Scikit-learn is needed to use "
"MulticlassClassifier derived classes.")
import sklearn.multiclass
if self.strategy == 'ovr':
self.multiclass_estimator = sklearn.multiclass.\
OneVsRestClassifier(self.estimator, n_jobs=None)
Expand Down
5 changes: 4 additions & 1 deletion python/cuml/pipeline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
# limitations under the License.
#

from sklearn.pipeline import Pipeline, make_pipeline
from cuml.common.import_utils import has_sklearn

if has_sklearn():
from sklearn.pipeline import Pipeline, make_pipeline

disclaimer = """
This code is developed and maintained by scikit-learn and imported
Expand Down