我最近查看了Creating interactive applications and toolbars in Jupyter Notebook上的mtap主题,并决定播放一个示例,其中作者编写了一个用于研究推文的界面,但不幸的是,输出出现矩阵混淆的部分遇到了问题< / p>
Figure (axes = [Axis (label = 'Actual', label_offset = '4em', orientation = 'vertical', scale = OrdinalScale (reverse = True) ...
不幸的是,该视频并不太了解我所错过的内容,请您帮忙实现此界面。该视频大约在17分钟左右开始。
我的一段代码。
confusion_mat = confusion_matrix(y_test, y_pred_bigram)
label_map = {0.0 : 'Negative', 1.0 : 'Positive'}
color_map = {0.0 : 'red', 1.0 : 'limegreen'}
row_scale = OrdinalScale(reverse=True)
col_scale = OrdinalScale()
color_scale = ColorScale(scheme='Greens')
row_axis = Axis(scale=row_scale, orientation='vertical', label='Actual',
label_offset='4em')
col_axis = Axis(scale=col_scale, label='Predicted')
conf_mat_grid = GridHeatMap(
column=['Negative', 'Positive'],
row=['Negative', 'Positive'],
color=np.log(confusion_mat),
scales={'row' : row_scale, 'column' : col_scale, 'color' :
color_scale},
interactions={'click' : 'select'},
anchor_style={'stroke' : 'red', 'strocke-width' : 3},
selected_style={'stroke' : 'red'})
y, x, text = zip(*[(label_map[i], label_map[j],
'{:,}'.format(confusion_mat[i, j])) for i in range(2)
for j in range(2)])
grid_labels = Label(x=x, y=y, text=text,
scales={'x' : col_scale, 'y' : row_scale},
font_size=26,
font_weight='bolder')
grid_fig = Figure(title='Confusion Matrix',
marks=[conf_mat_grid, grid_labels],
padding_y=0.0,
axes=[row_axis, col_axis],
fig_margin=dict(left=80, top=80, bottom=40, right=100))
grid_fig.layout.width = '460px'
grid_fig.layout.height = '400px'
grid_fig