2
votes

I am new to python programming. Following the AWS learning path:

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

I am getting an error when excuting the following block (in 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 (most recent call last) in 1 test_data_array = test_data.drop(['y_no', 'y_yes'], axis=1).values #load the data into an array ----> 2 xgb_predictor.content_type = 'text/csv' # set the data type for an inference 3 xgb_predictor.serializer = csv_serializer # set the serializer type 4 predictions = xgb_predictor.predict(test_data_array).decode('utf-8') # predict! 5 predictions_array = np.fromstring(predictions[1:], sep=',') # and turn the prediction into an array

AttributeError: can't set attribute

I have looked at several prior questions but couldn't find much information related to this error when it comes to creating data types.

Thanks in advance for any help.

2

2 Answers

7
votes

If you just remove it then the prediction will work. Therefore, recommend removing this code line. xgb_predictor.content_type = 'text/csv'

0
votes

Removing xgb_predictor.content_type = 'text/csv' will work.

But best way is that you first check the attributes of the object:

xgb_predictor.__dict__.keys()

This way, you will know that which attributes can be set.