bokeh网站上有一个示例:
https://docs.bokeh.org/en/latest/docs/gallery/bar_nested.html
但是它在我的Jupiter笔记本电脑上不起作用。
我有以下数据框:
precision recall f1
Random Forest 0.493759 1.0 0.661096
XGBoost 0.493759 1.0 0.661096
我想构建一个图表,以比较这三个指标上的两个模型。但首先,我只想比较一个指标。这是我的无效代码:
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource, FactorRange
from bokeh.plotting import figure
data = pd.DataFrame({'precision':[percision_rf,percision_xgb],'recall':[recall_rf,recall_xgb],'f1':[f1_rf,f1_xgb]})
data.rename({0:'Random Forest',1:'XGBoost'}, inplace=True)
source = ColumnDataSource(data=data)
p = figure()
p.vbar(x='Random Forest', top=0.9, width=0.9, source=source)
p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xaxis.major_label_orientation = 1
p.xgrid.grid_line_color = None
show(p)
[Bokeh网站上有一个简单条形图的示例,但未使用ColumnDataSource。
[将DataFrame
传递给ColumnDataSource
时,Bokeh使CDS列超出DataFrame的列。您可以在字形方法中引用Those,然后该字形将为该列的all值绘制字形。例如,在上面的示例中,您可以执行
# plot bars for every precision value along the x axis
p.vbar(x='precision', top=0.9, width=0.9, source=source)
所有散景字形都以这种方式固有地“矢量化”。
但是在上述情况下,x='Random Forest'
没有意义,因为在DataFrame
中没有称为“随机森林”的列。