From e4754807b089d1effb36185407cc0336b5c7b47a Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 20 Aug 2019 11:32:50 -0500 Subject: [PATCH 1/3] Adjst SVC patches to pass with 0.22.dev0 --- daal4py/sklearn/svm/svm.py | 45 +++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/daal4py/sklearn/svm/svm.py b/daal4py/sklearn/svm/svm.py index 0745c822b6..5fdc1ca604 100644 --- a/daal4py/sklearn/svm/svm.py +++ b/daal4py/sklearn/svm/svm.py @@ -21,6 +21,7 @@ from scipy import sparse as sp from sklearn.utils import check_random_state, check_X_y +from sklearn.utils.validation import check_is_fitted import sklearn.svm.classes import sklearn.svm.base import warnings @@ -278,7 +279,7 @@ def _daal_var(X): return ssc[0, 0] / X.size -def __compute_gamma__(gamma, kernel, X, sparse, use_var=True): +def __compute_gamma__(gamma, kernel, X, sparse, use_var=True, deprecation=True): """ Computes actual value of 'gamma' parameter of RBF kernel corresponding to SVC keyword values `gamma` and `kernel`, and feature @@ -290,7 +291,11 @@ def __compute_gamma__(gamma, kernel, X, sparse, use_var=True): See: https://github.com/scikit-learn/scikit-learn/pull/13221 """ - if gamma in ('scale', 'auto_deprecated'): + if deprecation: + _gamma_is_scale = gamma in ('scale', 'auto_deprecated') + else: + _gamma_is_scale = (gamma == 'scale') + if _gamma_is_scale: kernel_uses_gamma = (not callable(kernel) and kernel not in ('linear', 'precomputed')) if kernel_uses_gamma: @@ -309,7 +314,7 @@ def __compute_gamma__(gamma, kernel, X, sparse, use_var=True): else: _gamma = 1.0 else: - if kernel_uses_gamma and not np.isclose(X_sc, 1.0): + if kernel_uses_gamma and deprecation and not np.isclose(X_sc, 1.0): # NOTE: when deprecation ends we need to remove explicitly # setting `gamma` in examples (also in tests). See # https://github.com/scikit-learn/scikit-learn/pull/10331 @@ -322,18 +327,27 @@ def __compute_gamma__(gamma, kernel, X, sparse, use_var=True): _gamma = 1.0 / X.shape[1] elif gamma == 'auto': _gamma = 1.0 / X.shape[1] + elif isinstance(gamma, str) and not deprecation: + raise ValueError( + "When 'gamma' is a string, it should be either 'scale' or " + "'auto'. Got '{}' instead.".format(gamma) + ) else: _gamma = gamma return _gamma no_older_than_0_20_3 = None +no_older_than_0_22 = None def _compute_gamma(*args): global no_older_than_0_20_3 + global no_older_than_0_22 if no_older_than_0_20_3 is None: no_older_than_0_20_3 = (LooseVersion(sklearn_version) >= LooseVersion("0.20.3")) - return __compute_gamma__(*args, use_var=no_older_than_0_20_3) + if no_older_than_0_22 is None: + no_older_than_0_22 = (LooseVersion(sklearn_version) < LooseVersion("0.22")) + return __compute_gamma__(*args, use_var=no_older_than_0_20_3, deprecation=no_older_than_0_22) def fit(self, X, y, sample_weight=None): @@ -496,12 +510,23 @@ def predict(self, X): ------- y_pred : array, shape (n_samples,) """ - X = self._validate_for_predict(X) - if getattr(self, '_daal_fit', False) and hasattr(self, 'daal_model_'): - y = _daal4py_predict(self, X) + check_is_fitted(self) + _break_ties = getattr(self, 'break_ties', False) + if _break_ties and self.decision_function_shape == 'ovo': + raise ValueError("break_ties must be False when " + "decision_function_shape is 'ovo'") + + if (_break_ties + and self.decision_function_shape == 'ovr' + and len(self.classes_) > 2): + y = np.argmax(self.decision_function(X), axis=1) else: - predict = self._sparse_predict if self._sparse else self._dense_predict - y = predict(X) + X = self._validate_for_predict(X) + if getattr(self, '_daal_fit', False) and hasattr(self, 'daal_model_'): + y = _daal4py_predict(self, X) + else: + predict_func = self._sparse_predict if self._sparse else self._dense_predict + y = predict_func(X) return self.classes_.take(np.asarray(y, dtype=np.intp)) @@ -526,7 +551,7 @@ def predict(self, X): class SVC(sklearn.svm.base.BaseSVC): _impl = 'c_svc' - def __init__(self, C=1.0, kernel='rbf', degree=3, gamma='auto_deprecated', + def __init__(self, C=1.0, kernel='rbf', degree=3, gamma='scale', coef0=0.0, shrinking=True, probability=False, tol=1e-3, cache_size=200, class_weight=None, verbose=False, max_iter=-1, decision_function_shape='ovr', From 9b230b56ff9a2f4f91c266a1f1a7ee394b101124 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 20 Aug 2019 14:57:08 -0500 Subject: [PATCH 2/3] check_is_fitted requires attributes in 0.21.3 --- daal4py/sklearn/svm/svm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daal4py/sklearn/svm/svm.py b/daal4py/sklearn/svm/svm.py index 5fdc1ca604..1f324aa8c0 100644 --- a/daal4py/sklearn/svm/svm.py +++ b/daal4py/sklearn/svm/svm.py @@ -510,7 +510,7 @@ def predict(self, X): ------- y_pred : array, shape (n_samples,) """ - check_is_fitted(self) + check_is_fitted(self, 'support_') _break_ties = getattr(self, 'break_ties', False) if _break_ties and self.decision_function_shape == 'ovo': raise ValueError("break_ties must be False when " From 9e0249ee207c828ff55b65423d85b2f400903352 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 21 Aug 2019 09:36:12 -0500 Subject: [PATCH 3/3] updated copyright years --- daal4py/__main__.py | 2 +- daal4py/sklearn/__init__.py | 2 +- daal4py/sklearn/cluster/k_means.py | 2 +- daal4py/sklearn/decomposition/pca.py | 2 +- daal4py/sklearn/ensemble/decision_forest.py | 2 +- daal4py/sklearn/linear_model/linear.py | 2 +- daal4py/sklearn/linear_model/logistic_loss.py | 2 +- daal4py/sklearn/linear_model/logistic_path.py | 2 +- daal4py/sklearn/linear_model/ridge.py | 2 +- daal4py/sklearn/monkeypatch/pairwise.py | 2 +- daal4py/sklearn/svm/svm.py | 2 +- daal4py/sklearn/utils.py | 2 +- setup.py | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/daal4py/__main__.py b/daal4py/__main__.py index 0a2522346c..370c3a3cc7 100644 --- a/daal4py/__main__.py +++ b/daal4py/__main__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/daal4py/sklearn/__init__.py b/daal4py/sklearn/__init__.py index 2a64656e4c..b0eba9d6af 100644 --- a/daal4py/sklearn/__init__.py +++ b/daal4py/sklearn/__init__.py @@ -1,6 +1,6 @@ # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/daal4py/sklearn/cluster/k_means.py b/daal4py/sklearn/cluster/k_means.py index 7f943af1f3..859aad2aaf 100644 --- a/daal4py/sklearn/cluster/k_means.py +++ b/daal4py/sklearn/cluster/k_means.py @@ -1,6 +1,6 @@ # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/daal4py/sklearn/decomposition/pca.py b/daal4py/sklearn/decomposition/pca.py index 2adff8700f..1f98a09143 100644 --- a/daal4py/sklearn/decomposition/pca.py +++ b/daal4py/sklearn/decomposition/pca.py @@ -1,6 +1,6 @@ # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/daal4py/sklearn/ensemble/decision_forest.py b/daal4py/sklearn/ensemble/decision_forest.py index a6e4792977..c307491033 100644 --- a/daal4py/sklearn/ensemble/decision_forest.py +++ b/daal4py/sklearn/ensemble/decision_forest.py @@ -1,6 +1,6 @@ # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/daal4py/sklearn/linear_model/linear.py b/daal4py/sklearn/linear_model/linear.py index de546d3406..1d8f5eec24 100644 --- a/daal4py/sklearn/linear_model/linear.py +++ b/daal4py/sklearn/linear_model/linear.py @@ -1,6 +1,6 @@ # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/daal4py/sklearn/linear_model/logistic_loss.py b/daal4py/sklearn/linear_model/logistic_loss.py index 5b8cbaa594..9753af937d 100644 --- a/daal4py/sklearn/linear_model/logistic_loss.py +++ b/daal4py/sklearn/linear_model/logistic_loss.py @@ -1,6 +1,6 @@ # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/daal4py/sklearn/linear_model/logistic_path.py b/daal4py/sklearn/linear_model/logistic_path.py index 58742b5c00..a4b2bc9e65 100644 --- a/daal4py/sklearn/linear_model/logistic_path.py +++ b/daal4py/sklearn/linear_model/logistic_path.py @@ -1,6 +1,6 @@ # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/daal4py/sklearn/linear_model/ridge.py b/daal4py/sklearn/linear_model/ridge.py index c1d4a55578..4f5d8af99e 100644 --- a/daal4py/sklearn/linear_model/ridge.py +++ b/daal4py/sklearn/linear_model/ridge.py @@ -1,6 +1,6 @@ # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/daal4py/sklearn/monkeypatch/pairwise.py b/daal4py/sklearn/monkeypatch/pairwise.py index bc77c166b4..6b8edbd274 100644 --- a/daal4py/sklearn/monkeypatch/pairwise.py +++ b/daal4py/sklearn/monkeypatch/pairwise.py @@ -1,6 +1,6 @@ # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/daal4py/sklearn/svm/svm.py b/daal4py/sklearn/svm/svm.py index 1f324aa8c0..16b97d5262 100644 --- a/daal4py/sklearn/svm/svm.py +++ b/daal4py/sklearn/svm/svm.py @@ -1,6 +1,6 @@ # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/daal4py/sklearn/utils.py b/daal4py/sklearn/utils.py index 3b02a8646e..3454a51d31 100644 --- a/daal4py/sklearn/utils.py +++ b/daal4py/sklearn/utils.py @@ -1,6 +1,6 @@ # #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/setup.py b/setup.py index 69cccfbec6..66d4965464 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #! /usr/bin/env python #******************************************************************************* -# Copyright 2014-2017 Intel Corporation +# Copyright 2014-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.