XGBOOST inference prediction error with type

0

I am trying to make a prediction in Sagemaker:

#array is a nympy array variable

xgb_predictor.predict(array)

and I am getting this error:

ParamValidationError: Parameter validation failed: Invalid type for parameter Body, value: [[0.71028037 0.7866242 0.16398714 0.88787879 0. 0. 0. 1. 0. 0. 0. 0. 0. 1. 0. 1. 0. 0.

  1.     0.         0.         0.         0.         0.
    
  2.     0.         1.         0.         0.         0.
    
  3.     0.         0.         0.         1.         0.
    
  4.     0.         0.         0.         0.         0.
    
  5.     0.         0.         0.         0.         0.
    
  6.     0.         0.         0.         1.         0.
    
  7.     0.         0.         0.         0.         0.
    
  8.     0.         0.         0.        ]], type: <class 'numpy.ndarray'>, valid types: <class 'bytes'>, <class 'bytearray'>, file-like object
    

Please your help.

已提問 2 年前檢視次數 815 次
2 個答案
0

What is 'xgb_predictor'? Is this a SageMaker built-in? Or are you in script mode?

Consider using 'array.tobytes' to convert you numpy array to bytes

AWS
Dan_F
已回答 2 年前
0

Hello and happy new year!

Without seeing any of your code it is hard to be certain but judging from the error message it seems that you need to change the type/format of the data that you send through the request. The easiest way to do this can be by utilising one of the bult-in serialisers.

In this case, since you are using (I assume) an XGBoost model, you can serialise the input into csv format as one of the supported formats for the XGBoost container. To do so, before you call the predict method, set the serialiser to the CSVSerializer as per the below:

xgb_predictor.serializer = sagemaker.serializers.CSVSerializer()

then you can use the xgb_predictor.predict(array) which should then return the prediction.

*Please note that the array variable should not contain the variable you are trying to predict.

*Here is an example of training & deploying an XGBoost model that you can use as reference https://github.com/aws-samples/amazon-sagemaker-immersion-day/blob/master/xgboost_direct_marketing_sagemaker.ipynb

Let me know if this solves your issue. If not, could you please provide some more details as to the type of model you are training and how you reach to the point you are seeing the error?

AWS
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南