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년 전818회 조회
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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠