sklearnflask icon indicating copy to clipboard operation
sklearnflask copied to clipboard

Error predict

Open alinakhay opened this issue 7 years ago • 15 comments

Hi thanks for this repository, for some reason I have the following error:

{ "error": "No objects to concatenate", "trace": "Traceback (most recent call last):\n File "main.py", line 32, in predict\n query = pd.get_dummies(pd.DataFrame(json_))\n File "C:\Users\AlinaK\Desktop\sklearnflask-master\venv\lib\site-packages\pandas\core\reshape.py", line 1071, in get_dummies\n result = concat(with_dummies, axis=1)\n File "C:\Users\AlinaK\Desktop\sklearnflask-master\venv\lib\site-packages\pandas\tools\merge.py", line 812, in concat\n copy=copy)\n File "C:\Users\AlinaK\Desktop\sklearnflask-master\venv\lib\site-packages\pandas\tools\merge.py", line 845, in init\n raise ValueError('No objects to concatenate')\nValueError: No objects to concatenate\n" }

Do you know what might it be?

alinakhay avatar Nov 12 '17 18:11 alinakhay

@AlinaKay are you using the example provided in the blog post? If not can you share the object that you're posting? Also what's version of Python are you using?

amirziai avatar Nov 12 '17 19:11 amirziai

I have pulled this repository, installed virtual environment inside with Python 2.7

alinakhay avatar Nov 13 '17 08:11 alinakhay

@AlinaKay can you please share what command you ran or what object you posted to the API to get this error?

amirziai avatar Nov 13 '17 21:11 amirziai

@amirziai i am getting following error while fitting the classifier with values of x & y. Kindly help me with same.

ValueError Traceback (most recent call last) in () ----> 1 clf.fit(x, y)

/predix/anaconda3/lib/python3.5/site-packages/sklearn/ensemble/forest.py in fit(self, X, y, sample_weight) 210 """ 211 # Validate or convert input data --> 212 X = check_array(X, dtype=DTYPE, accept_sparse="csc") 213 if issparse(X): 214 # Pre-sort indices to avoid that each individual tree of the

/predix/anaconda3/lib/python3.5/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator) 371 force_all_finite) 372 else: --> 373 array = np.array(array, dtype=dtype, order=order, copy=copy) 374 375 if ensure_2d:

ValueError: could not convert string to float: 'W./C. 6607'

Nimitkothari avatar Nov 27 '17 06:11 Nimitkothari

@Nimitkothari seems like you have strings in your x. Convert those to ints, floats or booleans before you proceed.

amirziai avatar Jan 31 '18 18:01 amirziai

When i run the URL ''/predict" i get the error "Method not allowed" The method is not allowed for the requested URL.

It worked fine with "/train". Please help me with the issue.

Shubhammix avatar Feb 07 '18 16:02 Shubhammix

@Shubhammix you can only POST to /predict. Please see #2

amirziai avatar Feb 08 '18 05:02 amirziai

I am using Postman and running from localhost:8000/predict with POST method but i get below issue: { "error": "No objects to concatenate", "trace": "Traceback (most recent call last):\n File "main.py", line 35, in predict\n query = pd.get_dummies(pd.DataFrame(json_))\n File "E:\sklearnflask-master\env\lib\site-packages\pandas\core\reshape\reshape.py", line 1212, in get_dummies\n result = concat(with_dummies, axis=1)\n File "E:\sklearnflask-master\env\lib\site-packages\pandas\core\reshape\concat.py", line 212, in concat\n copy=copy)\n File "E:\sklearnflask-master\env\lib\site-packages\pandas\core\reshape\concat.py", line 245, in init\n raise ValueError('No objects to concatenate')\nValueError: No objects to concatenate\n" }

Shubhammix avatar Feb 08 '18 06:02 Shubhammix

Can I share a sample of the JSON data you're posting to the endpoint? What is the output of pd.DataFrame(json_) and the output of pd.get_dummies(pd.DataFrame(json_))?

amirziai avatar Feb 08 '18 06:02 amirziai

payload = [ {'Age': 85, 'Sex': 'male', 'Embarked': 'S'}, {'Age': 24, 'Sex': 'female', 'Embarked': 'C'}, {'Age': 3, 'Sex': 'male', 'Embarked': 'C'}, {'Age': 21, 'Sex': 'male', 'Embarked': 'S'} ]

I am adding this data

Shubhammix avatar Feb 08 '18 10:02 Shubhammix

@Shubhammix add print statements for pd.DataFrame(json_) and pd.get_dummies(pd.DataFrame(json_)) and share the output.

amirziai avatar Feb 08 '18 18:02 amirziai

thnak you for reply and yes i have added the print statements . image

Shubhammix avatar Feb 09 '18 04:02 Shubhammix

But in Postman it gives error: { "error": "0 is not JSON serializable", "trace": "Traceback (most recent call last):\n File "main.py", line 47, in predict\n return jsonify({'prediction': prediction})\n File "E:\sklearnflask-master\env\lib\site-packages\flask\json.py", line 263, in jsonify\n (dumps(data, indent=indent, separators=separators), '\n'),\n File "E:\sklearnflask-master\env\lib\site-packages\flask\json.py", line 123, in dumps\n rv = _json.dumps(obj, **kwargs)\n File "c:\python27\Lib\json\init.py", line 251, in dumps\n sort_keys=sort_keys, **kw).encode(obj)\n File "c:\python27\Lib\json\encoder.py", line 209, in encode\n chunks = list(chunks)\n File "c:\python27\Lib\json\encoder.py", line 434, in _iterencode\n for chunk in _iterencode_dict(o, _current_indent_level):\n File "c:\python27\Lib\json\encoder.py", line 408, in _iterencode_dict\n for chunk in chunks:\n File "c:\python27\Lib\json\encoder.py", line 332, in _iterencode_list\n for chunk in chunks:\n File "c:\python27\Lib\json\encoder.py", line 442, in _iterencode\n o = _default(o)\n File "E:\sklearnflask-master\env\lib\site-packages\flask\json.py", line 80, in default\n return _json.JSONEncoder.default(self, o)\n File "c:\python27\Lib\json\encoder.py", line 184, in default\n raise TypeError(repr(o) + " is not JSON serializable")\nTypeError: 0 is not JSON serializable\n" }

Shubhammix avatar Feb 09 '18 04:02 Shubhammix

Hie Amir thank you for you response on the previous post. I have doubt , What if I want the prediction values from the 2 columns eg. "Embarked " and "Survived"? For now we are getting prediction values from Survived only i need to get from more then 1 column. THank you

Shubhammix avatar Feb 23 '18 07:02 Shubhammix

Hello @amirziai I am facing the same issue.

query = pd.get_dummies(pd.DataFrame(json_)) this line is causing the issue. I am trying to make my own API and facing the same issue. error

How is it working in your code?

devanshee26 avatar Feb 16 '21 13:02 devanshee26