Guest User

Untitled

a guest
Nov 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. @app.route('/predict-iris')
  2. def predict_iris():
  3.  
  4. # Load data
  5. iris = load_iris()
  6.  
  7. # print("Loaded iris", iris)
  8.  
  9. # Fit our model
  10. logreg = LogisticRegression()
  11. model = logreg.fit(iris['data'], iris['target'])
  12. model.predict_proba(iris['data'])
  13.  
  14. # Parameters from GET request
  15. sepal_length = request.args.get("sepal_length")
  16. sepal_width = request.args.get("sepal_width")
  17. petal_length = request.args.get("petal_length")
  18. petal_width = request.args.get("petal_width")
  19.  
  20. # To predict
  21. to_predict = np.array([
  22. float(sepal_length),
  23. float(sepal_width),
  24. float(petal_length),
  25. float(petal_width)
  26. ])
  27.  
  28. print(
  29. "My input parameters are:",
  30. sepal_length, sepal_width,
  31. petal_length, petal_width
  32. )
  33.  
  34. if all([sepal_length, sepal_width, petal_length, petal_width]):
  35. result = {
  36. "message": "OK",
  37. "predict": model.predict(to_predict).tolist(),
  38. "probas": model.predict_proba(to_predict).tolist()
  39. }
  40. else:
  41. result = {
  42. "message": "Please set input!"
  43. }
  44.  
  45. return jsonify(result)
Add Comment
Please, Sign In to add comment