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年前829ビュー
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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ