Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @app.route('/predict-iris')
- def predict_iris():
- # Load data
- iris = load_iris()
- # print("Loaded iris", iris)
- # Fit our model
- logreg = LogisticRegression()
- model = logreg.fit(iris['data'], iris['target'])
- model.predict_proba(iris['data'])
- # Parameters from GET request
- sepal_length = request.args.get("sepal_length")
- sepal_width = request.args.get("sepal_width")
- petal_length = request.args.get("petal_length")
- petal_width = request.args.get("petal_width")
- # To predict
- to_predict = np.array([
- float(sepal_length),
- float(sepal_width),
- float(petal_length),
- float(petal_width)
- ])
- print(
- "My input parameters are:",
- sepal_length, sepal_width,
- petal_length, petal_width
- )
- if all([sepal_length, sepal_width, petal_length, petal_width]):
- result = {
- "message": "OK",
- "predict": model.predict(to_predict).tolist(),
- "probas": model.predict_proba(to_predict).tolist()
- }
- else:
- result = {
- "message": "Please set input!"
- }
- return jsonify(result)
Add Comment
Please, Sign In to add comment