plots.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:tu-dortmund-ice-cube 作者: wjam1995 项目源码 文件源码
def purity_efficiency_plot(y_true, y_pred, inset=True, savepath=None):
    # Purity = precision
    # Efficiency = recall
    purity, efficiency, thresholds = precision_recall_curve(y_true[:, 1], y_pred[:, 1])

    # Discard last point in purity, efficiency
    # (sklearn sets them to 1, 0 respectively)
    purity = purity[:-1]
    efficiency = efficiency[:-1]

    # Set larger font for legibility
    matplotlib.rcParams.update({'font.size': FONT_SIZE})

    # Code adapted from http://matplotlib.org/1.3.1/mpl_toolkits/axes_grid/examples/inset_locator_demo.py
    fig, ax = plt.subplots()

    # Plot purity and efficiency
    ax.plot(thresholds, purity, label="Purity")
    ax.plot(thresholds, efficiency, label="Efficiency")

    # If necessary, make an inset plot
    if inset:
        # Use a zoom of five, place in lower left corner, pad border by 3
        axins = zoomed_inset_axes(ax, zoom=5, loc=4, borderpad=3)

        axins.plot(thresholds, purity)
        axins.plot(thresholds, efficiency)

        # Set limits for inset plot
        axins.set_xlim(0.9, 1)
        axins.set_ylim(0.9, 1)

        # Set ticks for inset plot
        axins.set_xticks([0.9, 0.95, 1.0])
        axins.set_yticks([0.9, 0.95, 1.0])

        # Mark inset box
        mark_inset(ax, axins, loc1=2, loc2=4, fc="none", ec="0.5")

    ax.set_xlabel("Confidence Cut")
    ax.set_ylabel("Quality Parameter")

    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)

    ax.legend(bbox_to_anchor=(0.5, 1), loc="lower center", ncol=2, frameon=False)

    if savepath is None:
        plt.show()
    else:
        plt.savefig(savepath)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号