Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

error when trying to run sample request in python

Hiya! I deployed a customed trained model on google cloud and im currently trying to run it on python. When I deployed the model it said I could "use a simple Python script to get predictions from your active endpoint." Here are the instructions I followed:

Screenshot 2023-12-09 at 11.26.12 pm.png

I changed the values of the instances to the following (this is the format when doing a JSON request so i believe it should work properly): 

instances={ "instances": [[False, 1, 0, 0, 1, 0, 2, 2018, 1, 16, 0, 0, 0.0, 1, 1, 1, 3],[True, 1, 0, 0, 2, 0, 0, 2018, 1, 13, 0, 13, 0.0, 2, 1, 1, 3]]}

did everything required but I kept getting the error :

google.api_core.exceptions.FailedPrecondition: 400 "Prediction failed: Exception during sklearn prediction: Expected 2D array, got 1D array instead:\narray=[{'instances': [[False, 1, 0, 0, 1, 0, 2, 2018, 1, 16, 0, 0, 0, 1, 1, 1, 3], [True, 1, 0, 0, 2, 0, 0, 2018, 1, 13, 0, 13, 0, 2, 1, 1, 3]]}].\nReshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample." 

any clues on how i can fix this?

1 REPLY 1