Bird
0
0

What will be the output of the following code snippet?

medium📝 Predict Output Q13 of 15
SciPy - Integration with Scientific Ecosystem
What will be the output of the following code snippet?
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import FunctionTransformer
import numpy as np

def add_one(X):
    return X + 1

pipe = Pipeline([
    ('add', FunctionTransformer(add_one)),
])

X = np.array([1, 2, 3])
result = pipe.transform(X)
print(result)
AError: Pipeline has no transform method
B[1 2 3]
C[0 1 2]
D[2 3 4]
Step-by-Step Solution
Solution:
  1. Step 1: Understand FunctionTransformer behavior

    FunctionTransformer applies the function add_one to input data during transform.
  2. Step 2: Apply the function to input array

    Input array [1, 2, 3] plus 1 becomes [2, 3, 4].
  3. Final Answer:

    [2 3 4] -> Option D
  4. Quick Check:

    Input + 1 = Output [OK]
Quick Trick: FunctionTransformer applies function on transform call [OK]
Common Mistakes:
  • Assuming pipeline has no transform method
  • Forgetting function adds 1
  • Confusing fit and transform methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes