DSX score URL says "Expected 2D array, got 1D array instead" when POSTing

时间:2018-02-26 17:59:55

标签: python-3.x watson data-science-experience watson-ml

I'm having an issue from DsX Python notebook,

I've implemented a very simple linear regression (Single Polynomial), for one single predictor variable and a target variable.

The model works fine for predicting from python code in the notebook, but as soon as I deploy it on cloud to publish it through web services in my WML service, I make the post and the following happens:

print(diabetes_X_train.shape)

payload_scoring = {"values":diabetes_X_train.tolist()}

print(payload_scoring)

Output:

(422, 1) {'values': [[0.0616962065186885], [-0.0514740612388061], [0.0444512133365941], [-0.0115950145052127], [-0.0363846922044735], [-0.0406959404999971], [-0.0471628129432825], [-0.00189470584028465], [0.0616962065186885], [0.0390621529671896], [-0.0838084234552331], [0.0175059114895716], [-0.0288400076873072], [-0.00189470584028465], [-0.0256065714656645], [-0.0180618869484982], [0.0422955891888323], [0.0121168511201671], [-0.0105172024313319], [-0.0180618869484982], [-0.0568631216082106], [-0.0223731352440218], [-0.00405032998804645], [0.0606183944448076], [0.0358287167455469], [-0.0126728265790937], [-0.0773415510119477], [0.0595405823709267], [-0.0212953231701409], [-0.00620595413580824], [0.0444512133365941], [-0.0654856181992578], [0.125287118877662], [-0.0503962491649252], [-0.063329994051496], [-0.030995631835069], [0.0228949718589761], [0.0110390390462862], [0.0713965151836166], [0.0142724752679289], [-0.00836157828357004], [-0.0676412423470196],...

Next cell:

response_scoring = requests.post(scoring_url, json=payload_scoring, headers=header) print(response_scoring.text)

Output:

{"trace": "6nrs0HsEE1HerigSZ", "errors": [{"code": "invalid_input_data", "message": "Expected 2D array, got 1D array instead:\narray=[ 0.06169621 -0.05147406  0.04445121 -0.01159501 -0.03638469 -0.04069594\n -0.04716281 -0.00189471  0.06169621  0.03906215 -0.08380842  0.01750591\n -0.02884001 -0.00189471 -0.02560657 -0.01806189  0.04229559  0.01211685\n -0.0105172  -0.01806189 -0.05686312 -0.02237314 -0.00405033  0.06061839\n  0.03582872 -0.01267283 -0.07734155  0.05954058 -0.02129532 -0.00620595\n  0.04445121 -0.06548562  0.12528712 -0.05039625 -0.06332999 -0.03099563\n  0.02289497  0.01103904  0.07139652  0.01427248 -0.00836158 -0.06764124\n -0.0105172  -0.02345095  0.06816308 -0.03530688 -0.01159501 -0.0730303\n

But If I increase one dimension in my input data, the following happens: it seems that this is not able to extract the 2D. Some conversion is made server side, from the 2D jsonize to a 1D numpy array, which does not march the dimensionality of the used trained data...

payload_scoring = {"values":[diabetes_X_train.tolist()]}

output:

{"trace": "tbODFulFy7cAIMXZq", "errors": [{"code": "invalid_input_data", "message": "Found array with dim 3. Estimator expected <= 2.", "target": {"name": "values", "type": "field"}}], "status_code": 400}

I think it may be related to the fact that I have a 2D array as X input which turns to be a Vector in reality, I've tried other models like SVM classification with multidimensional input, and this same publishing code works.

Is someone in the same situation? I'm not able to make it work.

I've also tried SoapUI to reach with same results. it seems there's some problem with the deployment.

thanks

0 个答案:

没有答案
相关问题