批量预测的实现方式和最佳实践?

中等

答题要点

# Spark批量预测
from pyspark.ml import PipelineModel

model = PipelineModel.load("model_path")
predictions = model.transform(df)
predictions.write.parquet("output/")

# Pandas + 多进程
from multiprocessing import Pool

def predict_batch(batch):
    return model.predict(batch)

batches = np.array_split(data, n_workers)
with Pool(n_workers) as pool:
    results = pool.map(predict_batch, batches)

# 定时任务调度
# Airflow DAG
from airflow import DAG
from airflow.operators.python import PythonOperator

def batch_predict():
    data = load_data()
    predictions = model.predict(data)
    save_results(predictions)

dag = DAG('daily_prediction', schedule_interval='0 2 * * *')
task = PythonOperator(task_id='predict', python_callable=batch_predict, dag=dag)

完整解析在题库里看

核心知识点、易错点和面试官想听到什么;练过的题会进入记录,答错的进错题本。

去练这道题