我想表示Isomap算法的结果。但我也希望用户选择他想要保留的组件数量。 我为此创建了一个slider对象,但问题是回调函数是用Javascript编写的。因此,我不能使用scikit learn更新我的数据。 这是我的代码,有人能给我一些建议吗? 谢谢你
import numpy as np
from bokeh.io import vform
from bokeh.models import CustomJS, ColumnDataSource
from bokeh.plotting import figure, output_file, show
from bokeh.models.widgets import Slider
from sklearn import manifold
output_file("test.html")
X = np.random.randn(1000,20)
Y = np.random.randn(1000,20)
X_isomap = manifold.Isomap(n_neighbors=10, n_components=2).fit_transform(X)
X1 = X_isomap[:,0]
X2 = X_isomap[:,1]
IsoSource = ColumnDataSource(data=dict(x=X1, y=X2,DATA=X))
plot1 = figure(plot_width=400, plot_height=400,tools = "pan,wheel_zoom,box_zoom,reset,resize")
plot1.circle('x', 'y',source=IsoSource,size=7, color="navy")
#sliderCompMDS = Slider(title="n_components MDS",value=2,start=2,end=20,step=1)
callback = CustomJS(args=dict(source=IsoSource),code="""
var data = source.get('data');
var f = cb_obj.get('value')
x = data['x']
y =data['y']
X = data['DATA']
donnees = manifold.Isomap(n_neighbors=10, n_components=f).fit_transform(X)
x = donnees[:,0]
y = donnees[:,1]
source.trigger('change');
""")
sliderCompIso = Slider(title="n_components Isomap",value=2,start=1,end=20,step=1,callback=callback)
layout = vform(sliderCompIso, plot1)
show(layout)
首先,最好一次更新整个
.data
dict。所以,不要这样做:取而代之的是先用数据生成一个
^{pr2}$newdict
,然后再做除此之外,很难说。看起来你每次更新都要发送大约1000个x-y点?这不是一个不合理的数字,而且许多例子显示了更多。你确定计算本身并没有花费多少时间吗?多长时间:
以及
^{4}$独自完成?
我的猜测是这些只是需要一些时间来计算。如果是这样的话,博克就无能为力了。在
0.12
中,应该有一个“busy”消息添加到协议中,这样应用程序可以直观地指示正在进行的昂贵的计算。相关问题 更多 >
编程相关推荐