Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法打开酸洗Sagemaker XGBoost模型_Python_Pickle_Xgboost_Amazon Sagemaker - Fatal编程技术网

Python 无法打开酸洗Sagemaker XGBoost模型

Python 无法打开酸洗Sagemaker XGBoost模型,python,pickle,xgboost,amazon-sagemaker,Python,Pickle,Xgboost,Amazon Sagemaker,我试图打开我在AWS Sagemaker中创建的一个pickle XGBoost模型,以查看模型中的功能重要性。我正试着从中找出答案。但是,我得到一个错误提示,如下所示。当我尝试调用Booster.save\u model时,我得到一个错误,说估算器对象没有属性“save\u model”。我如何解决这个问题 # Build initial model sess = sagemaker.Session() s3_input_train = sagemaker.s3_input(s3_data='

我试图打开我在AWS Sagemaker中创建的一个pickle XGBoost模型,以查看模型中的功能重要性。我正试着从中找出答案。但是,我得到一个错误提示,如下所示。当我尝试调用
Booster.save\u model
时,我得到一个错误,说
估算器对象没有属性“save\u model”
。我如何解决这个问题

# Build initial model
sess = sagemaker.Session()
s3_input_train = sagemaker.s3_input(s3_data='s3://{}/{}/train/'.format(bucket, prefix), content_type='csv')
xgb_cont = get_image_uri(region, 'xgboost', repo_version='0.90-1')
xgb = sagemaker.estimator.Estimator(xgb_cont, role, train_instance_count=1, train_instance_type='ml.m4.4xlarge',
                                    output_path='s3://{}/{}'.format(bucket, prefix), sagemaker_session=sess)
xgb.set_hyperparameters(eval_metric='rmse', objective='reg:squarederror', num_round=100)
ts = strftime("%Y-%m-%d-%H-%M-%S", gmtime())
xgb_name = 'xgb-initial-' + ts
xgb.set_hyperparameters(eta=0.1, alpha=0.5, max_depth=10)
xgb.fit({'train': s3_input_train}, job_name=xgb_name)

# Load model to get feature importances
model_path = 's3://{}/{}//output/model.tar.gz'.format(bucket, prefix, xgb_name)
fs = s3fs.S3FileSystem()
with fs.open(model_path, 'rb') as f:
    with tarfile.open(fileobj=f, mode='r') as tar_f:
        with tar_f.extractfile('xgboost-model') as extracted_f:
            model = pickle.load(extracted_f)

XGBoostError: [19:16:42] /workspace/src/learner.cc:682: Check failed: header == serialisation_header_: 

  If you are loading a serialized model (like pickle in Python) generated by older
  XGBoost, please export the model by calling `Booster.save_model` from that version
  first, then load it back in current version.  There's a simple script for helping
  the process. See:

    https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html

  for reference to the script, and more details about differences between saving model and
  serializing.

您在笔记本中使用的是哪个版本的XGBoost?XGBoost 1.0中的模型格式已更改。看见简短版本:如果您在笔记本中使用1.0,则无法加载pickle模型

下面是一个在脚本模式下使用XGBoost的工作示例(它比内置的algo灵活得多):


太好了,很高兴你找到了答案:)我也面临同样的问题。你能详细说明一下你是怎么解决的吗?