新建File导入数据
选择一个csv文件
将目标设置为target并应用
绘制散点图
查看数据的最大最小值,四分位数,以及正常值的允许区间
这是一个模型组件,因此需要查看预测结果。另引入一个test and score组件,一头连接数据,一头连接模型。
另外还有tree, svm等许多组件。
最后以.ows格式保存。
2. 前后端交互 前端html将index.html放入templates文件夹中。
如下代码
DBS Share Price Prediction
The predict price for DBS share using regression is {{result1}}
The predict price for DBS share using tree is {{result2}}
效果
save model,使用joblib
便会指定目录生成一个相应文件
将模型文件移动至app.py相同路径下
实现前后端交互。前端在form中post数据。
from flask import Flask, request, render_template
import joblib
app = Flask(__name__)
@app.route("/", methods = ['GET', 'POST'])
def index():
if request.method == 'POST':
rates = float(request.form.get("rates")) # 从form组件中接收数据
model1 = joblib.load("linear")
r1 = model1.predict([[rates]])
model2 = joblib.load("tree")
r2 = model2.predict([[rates]])
return render_template("index.html", result1=r1, result2=r2)
else:
# 未收到
return render_template("index.html", result1='waiting', result2='waiting')
if __name__ == '__main__':
app.run()
运行会产生一个本地链接,打开就是前端界面。
3. 使用云存储模型为了便于他人使用自己训练好的模型,需要将模型上传至云。
3.1 Procfile首先创建Procfile,Procfile是一种机制,用于声明Heroku平台上应用程序的dynos运行的命令。
新建notepad,键入
web: gunicorn app:app
注意, Procfile无后缀
新建一个requirements.txt文件
absl-py==1.0.0 astunparse==1.6.3 cachetools==5.0.0 certifi==2021.10.8 charset-normalizer==2.0.11 click==8.0.3 colorama==0.4.4 Flask==2.0.2 flatbuffers==2.0 gast==0.5.3 google-auth==2.6.0 google-auth-oauthlib==0.4.6 google-pasta==0.2.0 grpcio==1.43.0 gunicorn==20.1.0 h5py==3.6.0 idna==3.3 importlib-metadata==4.10.1 itsdangerous==2.0.1 Jinja2==3.0.3 joblib==1.1.0 keras==2.8.0 Keras-Preprocessing==1.1.2 libclang==13.0.0 Markdown==3.3.6 MarkupSafe==2.0.1 numpy==1.22.2 oauthlib==3.2.0 opt-einsum==3.3.0 protobuf==3.19.4 pyasn1==0.4.8 pyasn1-modules==0.2.8 requests==2.27.1 requests-oauthlib==1.3.1 rsa==4.8 scikit-learn==1.0.2 scipy==1.8.0 six==1.16.0 sklearn==0.0 tensorboard==2.8.0 tensorboard-data-server==0.6.1 tensorboard-plugin-wit==1.8.1 tensorflow-io-gcs-filesystem==0.24.0 termcolor==1.1.0 tf-estimator-nightly==2.8.0.dev2021122109 threadpoolctl==3.1.0 typing_extensions==4.0.1 urllib3==1.26.8 Werkzeug==2.0.3 wrapt==1.13.3 zipp==3.7.03.3 Github创建库
创建后
3.4 herokuheroku官网
注册一个账号。
新建app
连接github
连接项目文件夹
Deploy Branch部署
点击View生成链接



