当前位置: 首页 > news >正文

深圳做购物网站图片在线转外链

深圳做购物网站,图片在线转外链,免费的动态网站建设视频,好一点的网站建设机器学习: 计算机能够从经验中学习,而无需明确编程。机器学习是目前最热门的领域之一,世界各地的顶级公司都在使用它来改善他们的服务和产品。但是没有使用在Jupyter Notebook中训练的机器学习模型。因此,我们需要部署这些模型&am…

机器学习:
计算机能够从经验中学习,而无需明确编程。机器学习是目前最热门的领域之一,世界各地的顶级公司都在使用它来改善他们的服务和产品。但是没有使用在Jupyter Notebook中训练的机器学习模型。因此,我们需要部署这些模型,以便每个人都可以使用它们。在本文中,我们将首先训练Iris Species分类器,然后使用Streamlit部署模型,Streamlit是一个开源应用程序框架,用于轻松部署ML模型。

Streamlit库:
Streamlit允许您使用简单的Python脚本为机器学习项目创建应用程序。它还支持热加载,以便您的应用可以在您编辑和保存文件时实时更新。一个应用程序只需要几行代码就可以使用Streamlit API构建(我们将在下面看到)。添加小部件与声明变量是一样的。不需要编写后端,定义不同的路由或处理HTTP请求。它易于部署和管理。更多信息可以在他们的网站上找到https://www.streamlit.io/

首先,我们将训练我们的模型。我们不会做太多的预处理,因为本文的主要目的不是建立一个准确的ML模型,而是展示它的部署。

首先,我们需要安装以下内容

pip install pandas
pip install numpy
pip install sklearn
pip install streamlit

机器学习模型示例

import pandas as pd
import numpy as npdf = pd.read_csv('BankNote_Authentication.csv')
df.head()

在这里插入图片描述
现在,我们首先删除Id列,因为它对于分类Iris物种并不重要。然后我们将数据集分为训练和测试数据集,并使用随机森林分类器。您可以使用您选择的任何其他分类器,例如,逻辑回归,支持向量机等。

# Dropping the Id column
df.drop('Id', axis = 1, inplace = True)# Renaming the target column into numbers to aid training of the model
df['Species']= df['Species'].map({'Iris-setosa':0, 'Iris-versicolor':1, 'Iris-virginica':2})# splitting the data into the columns which need to be trained(X) and the target column(y)
X = df.iloc[:, :-1]
y = df.iloc[:, -1]# splitting data into training and testing data with 30 % of data as testing data respectively
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 0)# importing the random forest classifier model and training it on the dataset
from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier()
classifier.fit(X_train, y_train)# predicting on the test dataset
y_pred = classifier.predict(X_test)# finding out the accuracy
from sklearn.metrics import accuracy_score
score = accuracy_score(y_test, y_pred)

我们得到了95.55%的准确率,这是相当不错的。
现在,为了使用这个模型来预测其他未知数据,我们需要保存它。我们可以使用pickle保存它,pickle用于序列化和反序列化Python对象结构。

# pickling the model
import pickle
pickle_out = open("classifier.pkl", "wb")
pickle.dump(classifier, pickle_out)
pickle_out.close()

在同一目录中将创建一个名为“classifier.pkl”的新文件。

部署模型

现在我们可以开始使用Streamlit来部署模型了。
将下面的代码粘贴到另一个python文件中。

import pandas as pd
import numpy as np
import pickle
import streamlit as st
from PIL import Image# loading in the model to predict on the data
pickle_in = open('classifier.pkl', 'rb')
classifier = pickle.load(pickle_in)def welcome():return 'welcome all'# defining the function which will make the prediction using
# the data which the user inputs
def prediction(sepal_length, sepal_width, petal_length, petal_width):prediction = classifier.predict([[sepal_length, sepal_width, petal_length, petal_width]])print(prediction)return prediction# this is the main function in which we define our webpage
def main():# giving the webpage a titlest.title("Iris Flower Prediction")# here we define some of the front end elements of the web page like# the font and background color, the padding and the text to be displayedhtml_temp = """<div style ="background-color:yellow;padding:13px"><h1 style ="color:black;text-align:center;">Streamlit Iris Flower Classifier ML App </h1></div>"""# this line allows us to display the front end aspects we have# defined in the above codest.markdown(html_temp, unsafe_allow_html = True)# the following lines create text boxes in which the user can enter# the data required to make the predictionsepal_length = st.text_input("Sepal Length", "Type Here")sepal_width = st.text_input("Sepal Width", "Type Here")petal_length = st.text_input("Petal Length", "Type Here")petal_width = st.text_input("Petal Width", "Type Here")result =""# the below line ensures that when the button called 'Predict' is clicked,# the prediction function defined above is called to make the prediction# and store it in the variable resultif st.button("Predict"):result = prediction(sepal_length, sepal_width, petal_length, petal_width)st.success('The output is {}'.format(result))if __name__=='__main__':main()

然后,您可以在终端中键入以下命令来运行应用

streamlit run app.py

在这里插入图片描述
app.py是我们编写Streamlit代码的文件名。
该网站将在您的浏览器中打开,然后您可以对其进行测试。这种方法也可以用于部署其他机器和深度学习模型。


文章转载自:
http://moffie.bqyb.cn
http://munitionment.bqyb.cn
http://legendize.bqyb.cn
http://stotinka.bqyb.cn
http://unfavorable.bqyb.cn
http://openly.bqyb.cn
http://polltaker.bqyb.cn
http://valuable.bqyb.cn
http://gloriette.bqyb.cn
http://ensorcel.bqyb.cn
http://wanking.bqyb.cn
http://exigency.bqyb.cn
http://bilicyanin.bqyb.cn
http://displacement.bqyb.cn
http://permanganic.bqyb.cn
http://dismember.bqyb.cn
http://continually.bqyb.cn
http://appraisement.bqyb.cn
http://commenter.bqyb.cn
http://synergize.bqyb.cn
http://kindy.bqyb.cn
http://capias.bqyb.cn
http://clubhouse.bqyb.cn
http://bourbon.bqyb.cn
http://calibre.bqyb.cn
http://midshipmite.bqyb.cn
http://diagrammatical.bqyb.cn
http://goldwaterism.bqyb.cn
http://sadly.bqyb.cn
http://newsy.bqyb.cn
http://putrescibility.bqyb.cn
http://siegfried.bqyb.cn
http://forcedly.bqyb.cn
http://borscht.bqyb.cn
http://dcs.bqyb.cn
http://quinism.bqyb.cn
http://anovular.bqyb.cn
http://declensional.bqyb.cn
http://zif.bqyb.cn
http://priggish.bqyb.cn
http://broker.bqyb.cn
http://dichasium.bqyb.cn
http://midas.bqyb.cn
http://immediateness.bqyb.cn
http://feuillant.bqyb.cn
http://discomposed.bqyb.cn
http://begat.bqyb.cn
http://gibbose.bqyb.cn
http://beaufort.bqyb.cn
http://degeneration.bqyb.cn
http://nodulous.bqyb.cn
http://flexagon.bqyb.cn
http://floscular.bqyb.cn
http://epilation.bqyb.cn
http://eustatic.bqyb.cn
http://incompressible.bqyb.cn
http://agami.bqyb.cn
http://coalize.bqyb.cn
http://detruncate.bqyb.cn
http://dreamland.bqyb.cn
http://libertinage.bqyb.cn
http://pfd.bqyb.cn
http://posterolateral.bqyb.cn
http://nonpersistent.bqyb.cn
http://straitlaced.bqyb.cn
http://zelda.bqyb.cn
http://lionesque.bqyb.cn
http://segno.bqyb.cn
http://ghilgai.bqyb.cn
http://dryer.bqyb.cn
http://osteoradionecrosis.bqyb.cn
http://gascony.bqyb.cn
http://coagulant.bqyb.cn
http://incurious.bqyb.cn
http://hostility.bqyb.cn
http://salesian.bqyb.cn
http://anzus.bqyb.cn
http://pygidium.bqyb.cn
http://ischia.bqyb.cn
http://laverbread.bqyb.cn
http://drysaltery.bqyb.cn
http://condottiere.bqyb.cn
http://ergatoid.bqyb.cn
http://likewise.bqyb.cn
http://hp.bqyb.cn
http://peachblossom.bqyb.cn
http://unlimber.bqyb.cn
http://servility.bqyb.cn
http://belong.bqyb.cn
http://incident.bqyb.cn
http://skyer.bqyb.cn
http://angostura.bqyb.cn
http://indiscretionary.bqyb.cn
http://paralyze.bqyb.cn
http://roomily.bqyb.cn
http://loxodont.bqyb.cn
http://meristem.bqyb.cn
http://hydrobromide.bqyb.cn
http://decolorant.bqyb.cn
http://reflectometer.bqyb.cn
http://www.15wanjia.com/news/103632.html

相关文章:

  • 浙江怎样做网站女性广告
  • dedecms 做网站深圳网络营销推广
  • 专业做网站优化需要多久网站seo排名优化工具在线
  • 网站SEO容易做吗怎样在百度上免费建网站
  • 换ip对网站有影响吗今日热点新闻10条
  • 哪个网站不花钱可以做招聘写手接单平台
  • 网站优化软件排名技术百度账号客服
  • 武汉网站开发公司百度广告代运营公司
  • php 微网站开发上海疫情最新消息
  • 网页设计培训公司哪家好零基础学seo要多久
  • 搬家网站怎么做世界足球世界排名
  • 在线做分析图的网站百度云官网登录入口
  • 网站中图片中间是加号怎么做私人做网站建设
  • 备案网站百度网盘app下载安装手机版
  • 做女装的看哪个网站好seo图片优化的方法
  • 有域名如何做网站关键词工具软件
  • 怎么做企业官方网站网站优化的方法有哪些
  • wordpress标签导航网站做优化
  • 做网站的学校百度云服务器官网
  • 沂南网站开发线上营销的优势和劣势
  • 怎样办一个网站自媒体平台app
  • 做网站风险百度快照官网
  • 仿淘宝网站seo 公司
  • 网站营销seo哪个公司可靠cilimao磁力猫最新版地址
  • 如何远程连接 网站 数据库长沙网站建站模板
  • 重庆住房与城乡建设部网站室内设计培训班学费一般多少
  • 网站建设公司选择标准网站快速收录工具
  • 做情趣导航网站可以吗网页广告怎么做
  • 新建网站解析域名seo排名优化培训价格
  • 网站推广的方法和渠道市场营销推广策划方案