
Answer-first summary for fast verification
Answer: df.select("customer_id", model(*columns).alias("predictions"))
The correct approach involves using the loaded MLflow model as a Spark UDF within a select statement. Option B correctly applies the model to the feature columns using `model(*columns)`, which generates a new column of predictions. Aliasing this column as 'predictions' and selecting 'customer_id' along with it produces the desired schema. Other options either use incorrect methods (map, apply), incorrect UDF handling (pandas_udf), or invalid syntax (model.predict).
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Which code block will produce a DataFrame with the schema containing "customer_id" as LONG type and "predictions" as DOUBLE type, given that:
A
df.map(lambda x:model(x[columns])).select("customer_id, predictions")
B
df.select("customer_id", model(*columns).alias("predictions"))
C
model.predict(df, columns)
D
df.select("customer_id", pandas_udf(model, columns).alias("predictions"))
E
df.apply(model, columns).select("customer_id, predictions")
No comments yet.