1. Home
  2. Data Science
  3. Scikit-learn
  4. A Pipeline is built as Pipeline([('scale'…

Added 30 Nov -0001

A Pipeline is built as Pipeline([('scale', StandardScaler()), ('model', LogisticRegression())]). How is C changed through set_params?

  1. pipeline.set_params(model.C=0.1), using dotted attribute notation for the step
  2. pipeline.set_params('model__C'=0.1), passing the parameter name as a quoted string
  3. pipeline.set_params(model__C=0.1), using the step name and a double underscore Correct answer
  4. pipeline.set_params(C=0.1), because parameters are flattened onto the pipeline itself

Correct answer

C. pipeline.set_params(model__C=0.1), using the step name and a double underscore

15 views

MCQSEXAM

Explanation

set_params addresses nested estimator parameters with the step name, two underscores and the parameter, so model__C reaches LogisticRegression's C. A single underscore or dotted notation raises because the pipeline looks for a top-level parameter of that name. get_params follows the same convention and is what makes cloning and pipeline grid searches work.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Scikit-learn MCQs

Practise all Scikit-learn MCQs

Similar MCQs