美文网首页
手把手教你用Python开发机器学习用户交互应用

手把手教你用Python开发机器学习用户交互应用

作者: 统计学家 | 来源:发表于2019-11-19 15:15 被阅读0次

    <section id="layout" class="layout" style="font-size: 16px; color: black; padding: 10px; line-height: 1.6; word-spacing: 0px; letter-spacing: 0px; word-break: break-word; word-wrap: break-word; text-align: left; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;"><p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">向大家推荐一款机器学习用户交互工具开发框架——Streamlit,可以使机器学习工程师能更轻松地创建自定义应用程序已在他们的模型中与数据进行交互。
    废话不多说,先来看看它有多神奇~</p>
    <figure style="margin: 0; margin-top: 10px; margin-bottom: 10px;"><img src="https://my-wechat.oss-cn-beijing.aliyuncs.com/image_20191031151559.png?Expires=1572511057&OSSAccessKeyId=TMP.hgDJN3skAQsibGL4kLr8bRPzGHUAyDhc7FUu6dJmM3PneKZcNG14K4aXtXBmeiFi17hMhjmYJR7EK7JACi9x1LPVkZkoNwgwBrEVDDFDstdhcrC7o5ZBsE3Yymq9Da.tmp&Signature=VWJkkEhiMCSZKlZSAVJPsR5kW44%3D" alt="image" style="display: block; margin: 0 auto; width: 100%;"><figcaption style="margin-top: 5px; text-align: center; color: #888; font-size: 14px;">image</figcaption></figure>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">这是用streamlit开发的Uber数据集交互式仪表板,运行这个Demo前需要先安装streamlit</p>
    <pre class="custom" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch; overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box !important;">pip install --upgrade streamlit
    streamlit run https://raw.githubusercontent.com/streamlit/demo-uber-nyc-pickups/master/app.py
    </code></pre>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">然后浏览器打开http://localhost:8501,即可实现上面视频中的效果!</p>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">再看看一个更牛的应用,通过Udacity自动驾驶车辆照片数据集,进行语义化搜索,可视化人工标注,并且可以实时运行一个YOLO 目标检测器:</p>
    <figure style="margin: 0; margin-top: 10px; margin-bottom: 10px;"><img src="https://my-wechat.oss-cn-beijing.aliyuncs.com/image_20191031151611.png?Expires=1572511021&OSSAccessKeyId=TMP.hgDJN3skAQsibGL4kLr8bRPzGHUAyDhc7FUu6dJmM3PneKZcNG14K4aXtXBmeiFi17hMhjmYJR7EK7JACi9x1LPVkZkoNwgwBrEVDDFDstdhcrC7o5ZBsE3Yymq9Da.tmp&Signature=rIBQlemikEFd%2B5ydTQRyq07oIsg%3D" alt="image" style="display: block; margin: 0 auto; width: 100%;"><figcaption style="margin-top: 5px; text-align: center; color: #888; font-size: 14px;">image</figcaption></figure>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">整个应用只有300行Python代码,绝大多数是机器学习代码。实际上其中只有23个Streamlit调用。具体代码不贴, 大家可以尝试通过github直接运行:</p>
    <pre class="custom" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch; overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box !important;">pip install --upgrade streamlit opencv-python streamlit run https://raw.githubusercontent.com/streamlit/demo-self-driving/master/app.py
    </code></pre>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">是不是很酷炫,其实实现起来一点都不复杂,需要什么功能,直接调用API即可,看个Slider、Checkbox、SelectBox实例。</p>
    <pre class="custom" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch; overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box !important;">#Slider
    streamlit.slider(label, min_value=None, max_value=None, value=None, step=None, format=None)

    Text Input

    url = st.text_input('Enter URL')
    st.write('The Entered URL is', url)

    Checkbox

    df = pd.read_csv("football_data.csv")
    if st.checkbox('Show dataframe'):
    st.write(df)

    SelectBox

    option = st.selectbox(
    'Which Club do you like best?',
    df['Club'].unique())'You selected: ', option

    MultiSelect

    options = st.multiselect(
    'What are your favorite clubs?', df['Club'].unique())st.write('You selected:', options)
    </code></pre>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">最终效果</p>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">手痒吗?赶紧试试吧</p>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">更多用法请移步:</p>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">https://github.com/streamlit/streamlit</p>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">API reference:</p>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">https://streamlit.io/docs/api.html</p>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">分割线</p>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">觉得不错,还请点个在看,非常感谢~~~</p>
    <p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">机器学习微信群已开放,请在公众号后台回复「入群」</p>
    </section>

    首发于微信公众号:机器学习与统计学

    相关文章

      网友评论

          本文标题:手把手教你用Python开发机器学习用户交互应用

          本文链接:https://www.haomeiwen.com/subject/xpowictx.html