8000 Allow scikit-learn 1.3 by markotoplak · Pull Request #6585 · biolab/orange3 · GitHub
[go: up one dir, main page]

Skip to content
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
Prev Previous commit
Next Next commit
deprecate SklLearner.support_weights
  • Loading branch information
noahnovsak authored and markotoplak committed Sep 29, 2023
commit e9b2a16654a706aea4823325e03629cd2f2fdf2b
4 changes: 4 additions & 0 deletions Orange/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from Orange.util import Reprable, OrangeDeprecationWarning, wrap_callback, \
dummy_callback


__all__ = ["Learner", "Model", "SklLearner", "SklModel",
"ReprableWithPreprocessors"]

Expand Down Expand Up @@ -596,6 +597,9 @@ def fit(self, X, Y, W=None):
def supports_weights(self):
"""Indicates whether this learner supports weighted instances.
"""
warnings.warn('SklLearner.supports_weights property is deprecated. All '
'subclasses should redefine the supports_weights attribute.',
OrangeDeprecationWarning)
varnames = self.__wraps__.fit.__code__.co_varnames
# scikit-learn often uses decorators on fit()
if hasattr(self.__wraps__.fit, "__wrapped__"):
Expand Down
1 change: 1 addition & 0 deletions Orange/classification/gb.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def score(self, data: Table) -> Tuple[np.ndarray, Tuple[Variable]]:
class GBClassifier(SklLearner, _FeatureScorerMixin):
__wraps__ = skl_ensemble.GradientBoostingClassifier
__returns__ = SklModel
supports_weights = True

def __init__(self,
loss="log_loss",
Expand Down
1 change: 1 addition & 0 deletions Orange/classification/knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

class KNNLearner(KNNBase, SklLearner):
__wraps__ = skl_neighbors.KNeighborsClassifier
supports_weights = False
1 change: 1 addition & 0 deletions Orange/classification/logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LogisticRegressionLearner(SklLearner, _FeatureScorerMixin):
__wraps__ = skl_linear_model.LogisticRegression
__returns__ = LogisticRegressionClassifier
preprocessors = SklLearner.preprocessors
supports_weights = True

def __init__(self, penalty="l2", dual=False, tol=0.0001, C=1.0,
fit_intercept=True, intercept_scaling=1, class_weight=None,
Expand Down
1 change: 1 addition & 0 deletions Orange/classification/neural_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MLPClassifierWCallback(skl_nn.MLPClassifier, NIterCallbackMixin):

class NNClassificationLearner(NNBase, SklLearner):
__wraps__ = MLPClassifierWCallback
supports_weights = False

def _initialize_wrapped(self):
clf = SklLearner._initialize_wrapped(self)
Expand Down
4 changes: 4 additions & 0 deletions Orange/classification/outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class OneClassSVMLearner(_OutlierLearner):
name = "One class SVM"
__wraps__ = OneClassSVM
preprocessors = SklLearner.preprocessors + [AdaptiveNormalize()]
supports_weights = True

def __init__(self, kernel='rbf', degree=3, gamma="auto", coef0=0.0,
tol=0.001, nu=0.5, shrinking=True, cache_size=200,
Expand All @@ -100,6 +101,7 @@ def __init__(self, kernel='rbf', degree=3, gamma="auto", coef0=0.0,
class LocalOutlierFactorLearner(_OutlierLearner):
__wraps__ = LocalOutlierFactor
name = "Local Outlier Factor"
supports_weights = False

def __init__(self, n_neighbors=20, algorithm="auto", leaf_size=30,
metric="minkowski", p=2, metric_params=None,
Expand All @@ -112,6 +114,7 @@ def __init__(self, n_neighbors=20, algorithm="auto", leaf_size=30,
class IsolationForestLearner(_OutlierLearner):
__wraps__ = IsolationForest
name = "Isolation Forest"
supports_weights = True

def __init__(self, n_estimators=100, max_samples='auto',
contamination='auto', max_features=1.0, bootstrap=False,
Expand Down Expand Up @@ -156,6 +159,7 @@ class EllipticEnvelopeLearner(_OutlierLearner):
__wraps__ = EllipticEnvelope
__returns__ = EllipticEnvelopeClassifier
name = "Covariance Estimator"
supports_weights = False

def __init__(self, store_precision=True, assume_centered=False,
support_fraction=None, contamination=0.1,
Expand Down
1 change: 1 addition & 0 deletions Orange/classification/random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def wrap(tree, i):
class RandomForestLearner(SklLearner, _FeatureScorerMixin):
__wraps__ = skl_ensemble.RandomForestClassifier
__returns__ = RandomForestClassifier
supports_weights = True

def __init__(self,
n_estimators=10,
Expand Down
1 change: 1 addition & 0 deletions Orange/classification/sgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SGDClassificationLearner(SklLearner):
__wraps__ = SGDClassifier
__returns__ = LinearModel
preprocessors = SklLearner.preprocessors + [Normalize()]
supports_weights = True

def __init__(self, loss='hinge', penalty='l2', alpha=0.0001,
l1_ratio=0.15, fit_intercept=True, max_iter=5,
Expand Down
1 change: 1 addition & 0 deletions Orange/classification/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class SklTreeLearner(SklLearner):
__wraps__ = skl_tree.DecisionTreeClassifier
__returns__ = SklTreeClassifier
name = 'tree'
supports_weights = True

def __init__(self, criterion="gini", splitter="best", max_depth=None,
min_samples_split=2, min_samples_leaf=1,
Expand Down
2 changes: 2 additions & 0 deletions Orange/classification/xgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def score(self, data: Table) -> Tuple[np.ndarray, Tuple[Variable]]:
class XGBClassifier(XGBBase, Learner, _FeatureScorerMixin):
__wraps__ = xgboost.XGBClassifier
__returns__ = SklModel
supports_weights = True

def __init__(self,
max_depth=None,
Expand Down Expand Up @@ -88,6 +89,7 @@ def __init__(self,
class XGBRFClassifier(XGBBase, Learner, _FeatureScorerMixin):
__wraps__ = xgboost.XGBRFClassifier
__returns__ = SklModel
supports_weights = True

def __init__(self,
max_depth=None,
Expand Down
2 changes: 2 additions & 0 deletions Orange/ensembles/ada_boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SklAdaBoostClassifier(SklModelClassification):
class SklAdaBoostClassificationLearner(SklLearnerClassification):
__wraps__ = skl_ensemble.AdaBoostClassifier
__returns__ = SklAdaBoostClassifier
supports_weights = True

def __init__(self, base_estimator=None, n_estimators=50, learning_rate=1.,
algorithm='SAMME.R', random_state=None, preprocessors=None):
Expand All @@ -40,6 +41,7 @@ class SklAdaBoostRegressor(SklModelRegression):
class SklAdaBoostRegressionLearner(SklLearnerRegression):
__wraps__ = skl_ensemble.AdaBoostRegressor
__returns__ = SklAdaBoostRegressor
supports_weights = True

def __init__(self, base_estimator=None, n_estimators=50, learning_rate=1.,
loss='linear', random_state=None, preprocessors=None):
Expand Down
1 change: 1 addition & 0 deletions Orange/regression/gb.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def score(self, data: Table) -> Tuple[np.ndarray, Tuple[Variable]]:
class GBRegressor(SklLearner, _FeatureScorerMixin):
__wraps__ = skl_ensemble.GradientBoostingRegressor
__returns__ = SklModel
supports_weights = True

def __init__(self,
loss="squared_error",
Expand Down
1 change: 1 addition & 0 deletions Orange/regression/knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

class KNNRegressionLearner(KNNBase, SklLearner):
__wraps__ = skl_neighbors.KNeighborsRegressor
supports_weights = False
6 changes: 6 additions & 0 deletions Orange/regression/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def score(self, data):

class LinearRegressionLearner(SklLearner, _FeatureScorerMixin):
__wraps__ = skl_linear_model.LinearRegression
supports_weights = True

# Arguments are needed for signatures, pylint: disable=unused-argument
def __init__(self, preprocessors=None, fit_intercept=True):
Expand All @@ -40,6 +41,7 @@ def fit(self, X, Y, W=None):

class RidgeRegressionLearner(LinearRegressionLearner):
__wraps__ = skl_linear_model.Ridge
supports_weights = True

# Arguments are needed for signatures, pylint: disable=unused-argument
def __init__(self, alpha=1.0, fit_intercept=True, copy_X=True,
Expand All @@ -50,6 +52,7 @@ def __init__(self, alpha=1.0, fit_intercept=True, copy_X=True,

class LassoRegressionLearner(LinearRegressionLearner):
__wraps__ = skl_linear_model.Lasso
supports_weights = True

# Arguments are needed for signatures, pylint: disable=unused-argument
def __init__(self, alpha=1.0, fit_intercept=True, precompute=False,
Expand All @@ -61,6 +64,7 @@ def __init__(self, alpha=1.0, fit_intercept=True, precompute=False,

class ElasticNetLearner(LinearRegressionLearner):
__wraps__ = skl_linear_model.ElasticNet
supports_weights = True

# Arguments are needed for signatures, pylint: disable=unused-argument
def __init__(self, alpha=1.0, l1_ratio=0.5, fit_intercept=True,
Expand All @@ -72,6 +76,7 @@ def __init__(self, alpha=1.0, l1_ratio=0.5, fit_intercept=True,

class ElasticNetCVLearner(LinearRegressionLearner):
__wraps__ = skl_linear_model.ElasticNetCV
supports_weights = True

# Arguments are needed for signatures, pylint: disable=unused-argument
def __init__(self, l1_ratio=0.5, eps=0.001, n_alphas=100, alphas=None,
Expand All @@ -85,6 +90,7 @@ def __init__(self, l1_ratio=0.5, eps=0.001, n_alphas=100, alphas=None,
class SGDRegressionLearner(LinearRegressionLearner):
__wraps__ = skl_linear_model.SGDRegressor
preprocessors = SklLearner.preprocessors + [Normalize()]
supports_weights = True

# Arguments are needed for signatures, pylint: disable=unused-argument
def __init__(self, loss='squared_error', penalty='l2', alpha=0.0001,
Expand Down
1 change: 1 addition & 0 deletions Orange/regression/neural_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MLPRegressorWCallback(skl_nn.MLPRegressor, NIterCallbackMixin):

class NNRegressionLearner(NNBase, SklLearner):
55F6 __wraps__ = MLPRegressorWCallback
supports_weights = False

def _initialize_wrapped(self):
clf = SklLearner._initialize_wrapped(self)
Expand Down
1 change: 1 addition & 0 deletions Orange/regression/random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def wrap(tree, i):
class RandomForestRegressionLearner(SklLearner, _FeatureScorerMixin):
__wraps__ = skl_ensemble.RandomForestRegressor
__returns__ = RandomForestRegressor
supports_weights = True

def __init__(self,
n_estimators=10,
Expand Down
1 change: 1 addition & 0 deletions Orange/regression/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class SklTreeRegressionLearner(SklLearner):
__wraps__ = skl_tree.DecisionTreeRegressor
__returns__ = SklTreeRegressor
name = 'regression tree'
supports_weights = True

def __init__(self, criterion="squared_error", splitter="best", max_depth=None,
min_samples_split=2, min_samples_leaf=1,
Expand Down
2 changes: 2 additions & 0 deletions Orange/regression/xgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def score(self, data: Table) -> Tuple[np.ndarray, Tuple[Variable]]:

class XGBRegressor(XGBBase, Learner, _FeatureScorerMixin):
__wraps__ = xgboost.XGBRegressor
supports_weights = True

def __init__(self,
max_depth=None,
Expand Down Expand Up @@ -75,6 +76,7 @@ def __init__(self,

class XGBRFRegressor(XGBBase, Learner, _FeatureScorerMixin):
__wraps__ = xgboost.XGBRFRegressor
supports_weights = True

def __init__(self,
max_depth=None,
Expand Down
7 changes: 5 additions & 2 deletions Orange/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Orange.data import Domain, Table
from Orange.preprocess import Discretize, Randomize, Continuize
from Orange.regression import LinearRegressionLearner
from Orange.util import OrangeDeprecationWarning


class DummyLearner(Learner):
Expand Down Expand Up @@ -102,7 +103,8 @@ def fit(self, X, y, sample_weight=None):
class DummyLearner(SklLearner):
__wraps__ = DummySklLearner

self.assertTrue(DummyLearner().supports_weights)
with self.assertWarns(OrangeDeprecationWarning):
self.assertTrue(DummyLearner().supports_weights)

class DummySklLearner:
def fit(self, X, y):
Expand All @@ -111,7 +113,8 @@ def fit(self, X, y):
class DummyLearner(SklLearner):
__wraps__ = DummySklLearner

self.assertFalse(DummyLearner().supports_weights)
with self.assertWarns(OrangeDeprecationWarning):
self.assertFalse(DummyLearner().supports_weights)

def test_linreg(self):
self.assertTrue(
Expand Down
0