Skip to content

Commit

Permalink
Merge pull request #121 from antoinedemathelin/master
Browse files Browse the repository at this point in the history
fix: new sklearn version compatibility
  • Loading branch information
antoinedemathelin authored Jan 26, 2024
2 parents 5ce9f04 + 4befc04 commit 66ee31f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion adapt/instance_based/_iwc.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def fit_weights(self, Xs, Xt, warm_start=False, **kwargs):

if (not warm_start) or (not hasattr(self, "classifier_")):
if self.classifier is None:
self.classifier_ = LogisticRegression(penalty="none")
self.classifier_ = LogisticRegression()
else:
self.classifier_ = check_estimator(self.classifier,
copy=True,
Expand Down
5 changes: 4 additions & 1 deletion adapt/instance_based/_tradaboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ def _boost(self, iboost, Xs, ys, Xt, yt,

if not isinstance(self, TrAdaBoostR2):
if isinstance(estimator, BaseEstimator):
ohe = OneHotEncoder(sparse=False)
try:
ohe = OneHotEncoder(sparse=False)
except:
ohe = OneHotEncoder(sparse_output=False)
ohe.fit(y.reshape(-1, 1))
ys = ohe.transform(ys)
yt = ohe.transform(yt)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_regular.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_setup():
lr.fit(Xs, ys_reg)
assert np.abs(lr.coef_[0][0] - 10) < 1

lr = LogisticRegression(penalty='none', solver='lbfgs')
lr = LogisticRegression(penalty=None, solver='lbfgs')
lr.fit(Xs, ys_classif)
assert (lr.predict(Xt) == yt_classif.ravel()).sum() < 70

Expand Down Expand Up @@ -116,7 +116,7 @@ def test_regularlr_error():

def test_regularlc_fit():
np.random.seed(0)
lr = LogisticRegression(penalty='none', solver='lbfgs')
lr = LogisticRegression(penalty=None, solver='lbfgs')
lr.fit(Xs, ys_classif)
model = RegularTransferLC(lr, lambda_=0)
model.fit(Xt, yt_classif)
Expand All @@ -139,7 +139,7 @@ def test_regularlc_multiclass():
y = np.zeros(len(X))
y[X[:, :2].sum(1)<0] = 1
y[X[:, 3:].sum(1)>0] = 2
lr = LogisticRegression(penalty='none', solver='lbfgs')
lr = LogisticRegression(penalty=None, solver='lbfgs')
lr.fit(X, y)
model = RegularTransferLC(lr, lambda_=1.)
model.fit(X, y)
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_clone():
new_model.predict(Xs);
assert model is not new_model

lr = LogisticRegression(penalty='none', solver='lbfgs')
lr = LogisticRegression(penalty=None, solver='lbfgs')
lr.fit(Xs, ys)
model = RegularTransferLC(lr, lambda_=1.)
model.fit(Xs, ys)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_tradaboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

def test_tradaboost_fit():
np.random.seed(0)
model = TrAdaBoost(LogisticRegression(penalty='none',
model = TrAdaBoost(LogisticRegression(penalty=None,
solver='lbfgs'),
n_estimators=20)
model.fit(Xs, ys_classif, Xt=Xt[:10], yt=yt_classif[:10])
Expand Down Expand Up @@ -111,7 +111,7 @@ def test_twostagetradaboostr2_fit():

def test_tradaboost_deepcopy():
np.random.seed(0)
model = TrAdaBoost(LogisticRegression(penalty='none',
model = TrAdaBoost(LogisticRegression(penalty=None,
solver='lbfgs'),
n_estimators=20)
model.fit(Xs, ys_classif, Xt=Xt[:10], yt=yt_classif[:10])
Expand All @@ -124,7 +124,7 @@ def test_tradaboost_multiclass():
np.random.seed(0)
X = np.random.randn(10, 3)
y = np.random.choice(3, 10)
model = TrAdaBoost(LogisticRegression(penalty='none',
model = TrAdaBoost(LogisticRegression(penalty=None,
solver='lbfgs'), Xt=X, yt=y,
n_estimators=20)
model.fit(X, y)
Expand Down Expand Up @@ -177,13 +177,13 @@ def test_tradaboost_above_05():

def test_tradaboost_lr():
np.random.seed(0)
model = TrAdaBoost(LogisticRegression(penalty='none'),
model = TrAdaBoost(LogisticRegression(penalty=None),
Xt=Xt[:10], yt=yt_classif[:10],
n_estimators=20, lr=.1)
model.fit(Xs, ys_classif)
err1 = model.estimator_errors_

model = TrAdaBoost(LogisticRegression(penalty='none'),
model = TrAdaBoost(LogisticRegression(penalty=None),
Xt=Xt[:10], yt=yt_classif[:10],
n_estimators=20, lr=2.)
model.fit(Xs, ys_classif)
Expand Down

0 comments on commit 66ee31f

Please sign in to comment.