【问题标题】:AWS Sagemaker AttributeError: can't set attribute errorAWS Sagemaker AttributeError:无法设置属性错误
【发布时间】:2021-04-04 11:41:29
【问题描述】:

我是 python 编程的新手。遵循 AWS 学习路径:

https://aws.amazon.com/getting-started/hands-on/build-train-deploy-machine-learning-model-sagemaker/?trk=el_a134p000003yWILAA2&trkCampaign=DS_SageMaker_Tutorial&sc_channel=el&sc_campaign=Data_Scientist_Hands-on_Tutorial&sc_outcome=Product_Marketing&sc_geo=mult

执行以下块时出现错误(在 conda_python3 中):

test_data_array = test_data.drop(['y_no', 'y_yes'], axis=1).values #load the data into an array
xgb_predictor.content_type = 'text/csv' # set the data type for an inference
xgb_predictor.serializer = csv_serializer # set the serializer type
predictions = xgb_predictor.predict(test_data_array).decode('utf-8') # predict!
predictions_array = np.fromstring(predictions[1:], sep=',') # and turn the prediction into an 
array
print(predictions_array.shape)

AttributeError Traceback(最近一次调用最后一次) 在 1 test_data_array = test_data.drop(['y_no', 'y_yes'], axis=1).values #将数据加载到数组中 ----> 2 xgb_predictor.content_type = 'text/csv' # 设置推理的数据类型 3 xgb_predictor.serializer = csv_serializer #设置序列化器类型 4 个预测 = xgb_predictor.predict(test_data_array).decode('utf-8') # 预测! 5 predictions_array = np.fromstring(predictions[1:], sep=',') # 并将预测转为数组

AttributeError: 无法设置属性

我查看了几个先前的问题,但在创建数据类型时找不到与此错误相关的太多信息。

提前感谢您的帮助。

【问题讨论】:

    标签: python amazon-web-services amazon-s3 amazon-sagemaker


    【解决方案1】:

    如果您只是删除它,那么预测将起作用。因此,建议删除此代码行。 xgb_predictor.content_type = '文本/csv'

    【讨论】:

    • 有效!谢谢!!
    【解决方案2】:

    删除 xgb_predictor.content_type = 'text/csv' 即可。

    但最好的方法是先检查对象的属性:

    xgb_predictor.__dict__.keys()
    

    这样你就知道可以设置哪些属性了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-17
      • 1970-01-01
      • 2015-02-08
      • 2014-08-09
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多