我正在使用Flask-AppBuilder框架构建一个应用程序,并使用autoload_server将脚本src插入到我的html模板中成功嵌入了散景图.目前,我在散景应用程序中有一个小部件按钮,它会触发python回调以更新绘图.我会想知道的是,如果有可能触发相同的行为,但使用一个按钮,位于烧瓶内部应用程序.在我看来,这应该是可能的,但我只是不知道如何将一个UI事件从烧瓶按钮传递到散景服务器.
以下是简化代码.
有一个回调按钮可以将情节从'cos'改为'sin'.
import numpy as np
from bokeh.plotting import figure, output_file, show
from bokeh.io import curdoc, reset_output
from bokeh.layouts import column, row
from bokeh.models import Button
def plotRoutine(input):
x = np.linspace(0,10)
if input=='cos':
y = np.cos(x)
if input=='sin':
y = np.sin(x)
plot = figure(title = input)
plot.line(x, y)
return plot
def callback():
plot = plotRoutine('sin')
layout.children[1] = plot
plot = plotRoutine('cos')
button = Button(label="Callback button in bokeh server")
button.on_click(callback)
layout = column(button, plot)
curdoc().add_root(layout) …Run Code Online (Sandbox Code Playgroud) 从TensorFlow文档中可以清楚地看到如何使用tf.feature_column.categorical_column_with_vocabulary_list创建一个特征列,该特征列将一些字符串作为输入并输出一个热矢量.例如
vocabulary_feature_column =
tf.feature_column.categorical_column_with_vocabulary_list(
key="vocab_feature",
vocabulary_list=["kitchenware", "electronics", "sports"])
Run Code Online (Sandbox Code Playgroud)
让我们说"kitchenware"映射到[1,0,0]并"electronics"映射到[0,1,0].我的问题与将字符串列表作为特征有关.例如,如果特征值是,["kitchenware","electronics"]那么期望的输出将是[1,1,0].输入列表长度不固定,但输出维度为.
用例是一个直的词袋类型模型(显然有一个更大的词汇表!).
实现这个的正确方法是什么?
machine-learning feature-extraction neural-network tensorflow