sklearnflask
sklearnflask copied to clipboard
Error predict
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?
@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?
I have pulled this repository, installed virtual environment inside with Python 2.7
@AlinaKay can you please share what command you ran or what object you posted to the API to get this error?
@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)
/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 seems like you have strings in your x
. Convert those to ints, floats or booleans before you proceed.
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 you can only POST to /predict
. Please see #2
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" }
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_))
?
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 add print statements for pd.DataFrame(json_)
and pd.get_dummies(pd.DataFrame(json_))
and share the output.
thnak you for reply and yes i have added the print statements .
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" }
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
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.
How is it working in your code?