Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite4b0849

Browse files
authored
FIX Avoid fitting a pipeline without steps (#31723)
1 parent9b7a86f commite4b0849

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

‎sklearn/pipeline.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ def set_params(self, **kwargs):
320320
returnself
321321

322322
def_validate_steps(self):
323+
ifnotself.steps:
324+
raiseValueError("The pipeline is empty. Please add steps.")
323325
names,estimators=zip(*self.steps)
324326

325327
# validate names
@@ -1289,7 +1291,6 @@ def __sklearn_is_fitted__(self):
12891291
12901292
An empty pipeline is considered fitted.
12911293
"""
1292-
12931294
# First find the last step that is not 'passthrough'
12941295
last_step=None
12951296
for_,estimatorinreversed(self.steps):

‎sklearn/tests/test_pipeline.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ def test_pipeline_invalid_parameters():
282282
assertparams==params2
283283

284284

285+
deftest_empty_pipeline():
286+
X=iris.data
287+
y=iris.target
288+
289+
pipe=Pipeline([])
290+
msg="The pipeline is empty. Please add steps."
291+
withpytest.raises(ValueError,match=msg):
292+
pipe.fit(X,y)
293+
294+
285295
deftest_pipeline_init_tuple():
286296
# Pipeline accepts steps as tuple
287297
X=np.array([[1,2]])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp