Bird
0
0

You want to build a pipeline that first applies a SciPy function to normalize data, then fits a logistic regression model. Which of the following code snippets correctly implements this?

hard📝 Application Q15 of 15
SciPy - Integration with Scientific Ecosystem
You want to build a pipeline that first applies a SciPy function to normalize data, then fits a logistic regression model. Which of the following code snippets correctly implements this?
Afrom sklearn.pipeline import Pipeline from sklearn.preprocessing import FunctionTransformer from sklearn.linear_model import LogisticRegression import scipy.stats as stats pipe = Pipeline([ ('normalize', FunctionTransformer(stats.zscore)), ('model', LogisticRegression()) ])
Bfrom sklearn.pipeline import Pipeline from sklearn.preprocessing import FunctionTransformer from sklearn.linear_model import LogisticRegression import scipy.stats as stats pipe = Pipeline([ ('normalize', stats.zscore()), ('model', LogisticRegression()) ])
Cfrom sklearn.pipeline import Pipeline from sklearn.preprocessing import FunctionTransformer from sklearn.linear_model import LogisticRegression import scipy.stats as stats pipe = Pipeline([ ('normalize', FunctionTransformer(stats.zscore())), ('model', LogisticRegression()) ])
Dfrom sklearn.pipeline import Pipeline from sklearn.preprocessing import FunctionTransformer from sklearn.linear_model import LogisticRegression import scipy.stats as stats pipe = Pipeline([ ('normalize', FunctionTransformer(stats.zscore)), ('model', LogisticRegression) ])
Step-by-Step Solution
Solution:
  1. Step 1: Use FunctionTransformer correctly with SciPy function

    Pass the function stats.zscore without calling it, wrapped by FunctionTransformer.
  2. Step 2: Ensure LogisticRegression is instantiated

    Use LogisticRegression() with parentheses to create the model instance.
  3. Final Answer:

    Code snippet with FunctionTransformer(stats.zscore) and LogisticRegression() -> Option A
  4. Quick Check:

    FunctionTransformer(function) + model instance [OK]
Quick Trick: Wrap function, instantiate model with parentheses [OK]
Common Mistakes:
  • Calling SciPy function instead of passing it
  • Not instantiating LogisticRegression
  • Passing function call to FunctionTransformer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes