如何解决在 azure databricks 中保存 xgboost 模型时出现的错误?

问题描述

我正在尝试将模型保存在 azure 数据块中,但出现错误 - “您似乎正在尝试从广播变量、操作或转换中引用 SparkContext。SparkContext 只能在驱动程序上使用,而不能在它的代码中使用在 worker 上运行。有关更多信息,请参阅 SPARK-5063。"

以下是我正在使用的代码:-

import dill as dill
with open('model.sav',"wb") as f:
    dill.dump(model,f)

或者有没有其他方法可以在不使用 mleap 或 mlflow 的情况下将模型下载到本地?

我正在使用此代码来训练模型。

pipe = Pipeline(steps=[
    ('imputer',SimpleImputer(strategy='median')),('scaler',StandardScaler())])

pipe_xgb = make_pipeline(pipe,DataFrameScaler(),xgb.XGBClassifier(objective='binary:logistic'))
param_grid_classifier = {
                        'xgbclassifier__n_estimators':[100,200],'xgbclassifier__learning_rate' :[0.1,0.01],'xgbclassifier__colsample_bytree':[0.3,0.5],'xgbclassifier__max_depth': [4],'xgbclassifier__reg_lambda':[0.01,0.1],'xgbclassifier__n_jobs':[4]
                        }
metric = 'average_precision'
grid_search1 = gridsearchcv(pipe_xgb,param_grid=param_grid_classifier,scoring=metric,cv=2)

gridmodel1 = grid_search1.fit(X_train,y_train_label)
model = gridmodel1.best_estimator_

预先感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)