So we get all the features for predicting the Iris type. As you can see in the /predict route, we are collecting all the form values. In the index file, we will have to give a form to input the sepal and petal length and width for the model to classify it into type of Iris. import os import pandas as pd import numpy as np import flask import pickle from flask import Flask, render_template, request app=Flask(_name_) def index(): return flask.render_template(‘index.html’) def ValuePredictor(to_predict_list): to_predict = np.array(to_predict_list).reshape(1,4) loaded_model = pickle.load(open(“model.pkl”,”rb”)) result = loaded_model.predict(to_predict) return result = ) def result(): if thod = ‘POST’: to_predict_list = _dict() to_predict_list=list(to_predict_list.values()) to_predict_list = list(map(float, to_predict_list)) result = ValuePredictor(to_predict_list) prediction = str(result) return render_template(“predict.html”,prediction=prediction) if _name_ = “_main_”: app.run(debug=True) ![]() Then, in the app.py file insert these code. We have to take the model.pkl file that we got from the notebook output to the project directory so that we can use that. Then create a file app.py, where we will be doing our python script, a folder named ‘templates’, in which we create a file named index.html. Now, we have to create a directory for the project. ![]() import pickle filename='model.pkl' pickle.dump(knn, open(filename, 'wb') The idea is that this character stream contains all the information necessary to reconstruct the object in another python script. ![]() We can convert the model which is in the form of a python object into a character stream using pickling.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |