Bird
0
0

Consider the pipeline below. What will pipe.predict([[3]]) return?

medium📝 Predict Output Q5 of 15
SciPy - Integration with Scientific Ecosystem
Consider the pipeline below. What will pipe.predict([[3]]) return?
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import FunctionTransformer
from sklearn.linear_model import LinearRegression
import numpy as np

def cube(x):
    return x ** 3

pipe = Pipeline([
    ('cube', FunctionTransformer(cube)),
    ('lr', LinearRegression())
])

X_train = np.array([[1], [2], [3], [4]])
y_train = np.array([1, 8, 27, 64])
pipe.fit(X_train, y_train)

print(pipe.predict([[3]]))
A[9.]
B[27.]
C[3.]
DError due to incorrect pipeline setup
Step-by-Step Solution
Solution:
  1. Step 1: Understand Transformation

    Input is cubed before regression.
  2. Step 2: Training Data

    y_train matches cube of X_train values.
  3. Step 3: Prediction

    Input 3 is cubed to 27, linear regression predicts 27.
  4. Final Answer:

    [27.] -> Option B
  5. Quick Check:

    Pipeline applies cube then regression [OK]
Quick Trick: Pipeline transforms input before prediction [OK]
Common Mistakes:
  • Forgetting transformation before prediction
  • Expecting linear output without transformation
  • Assuming pipeline fit is incomplete

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes