示例#1
0
def plotChart(data, title):
    # colors=iter(cm.Set1(np.linspace(0,1,len(data))))
    colors = iter(cm.Dark2(np.linspace(0, 1, len(data))))
    fig = plt.figure(figsize=(20, 10))
    ax = fig.add_subplot(111)
    ax.xaxis.set_major_formatter(ticker.FuncFormatter(myticks))
    plt.grid()
    # plt.yscale("log")
    plt.xlabel("Ilość iteracji", fontsize="xx-large")
    plt.ylabel("%Rozpoznanych przypadków", fontsize="xx-large")
    plt.ylim([0, 100])

    # lists=[iter_n,train_percentage,test_percentage]
    for n_of_neurons, lists in data.items():
        c = next(colors)
        ax.plot(lists[0],
                lists[1],
                color=c,
                label="Ilość neuronow {0}".format(n_of_neurons))
        ax.plot(lists[0],
                lists[2],
                color=c,
                linestyle=":",
                label="Ilość neuronow {0}".format(n_of_neurons))
    legend = plt.legend(loc='upper center',
                        bbox_to_anchor=(0.5, -0.1),
                        ncol=3,
                        fancybox=True,
                        shadow=True)
    legend.get_frame()
    plt.title(title)
    plt.savefig(title + ".png",
                bbox_extra_artists=(legend, ),
                bbox_inches='tight')
示例#2
0
def plotStats(errorss, kappass, resolutions, labels, title=None):
    n = len(errorss)
    fig, (ax1, ax2) = plt.subplots(2, sharex=True)
    fig.set_size_inches(6,6)

    if (title):
        ax1.set_title(title)
    ax1.set_ylabel('K1')

    ax2.set_ylabel('Mean error (pixels)')

    ax2.set_xlabel('Iteration (t)')
    xaxis = range(-1,len(errorss[0])-1)

    colors = cm.Dark2(np.linspace(0,1,n))

    for i in range(n):
        kappas = kappass[i]
        errors = errorss[i]
        color = colors[i]
        resolution = resolutions[i]
        label = labels[i]

        ax1.plot(xaxis, kappas, marker='.', c=color, label=label)

        #ax2.plot(map(lambda e: e.minmax[1], errors), ':', c=color)
        ax2.plot(xaxis, map(lambda e: e.mean, errors), marker='.', c=color, label=label)
        #ax2.plot(map(lambda e: e.minmax[0], errors), ':', c=color)

    ax2.legend()

    return fig
示例#3
0
def plot(query_data,
         x="TP",
         y="Precision",
         y2=None,
         xlim=None,
         ylim=None,
         y2lim=None,
         show=True,
         refs=None,
         save_name=None,
         alpha=0.6,
         markersize=3,
         keep_duplicates=False,
         colors_iter=None,
         stratify=True):
    choices = {
        'Total', 'TP', 'FP', 'FN', 'Duplication', 'Precision', 'Sensitivity',
        'DTP', "F1", "Recall"
    }
    if x not in choices or y not in choices:
        raise ValueError("x and y must be one of: ", choices)

    if isinstance(query_data, dict):
        query_data = list(query_data.values())

    if any(q.false_negative_indexes is None for q in query_data):
        raise ValueError(
            "quant_tools.score function must be called prior to plotting")

    markers = itertools.cycle(
        ['o', '>', '<', '+', 'D', 's', 11, 10, '*', 'X', 3, '_'])

    if colors_iter is None:
        colors = iter(cm.Dark2(np.linspace(0, 1, len(query_data))))
    else:
        colors = iter(colors_iter)

    plots = {}
    for ref_name, grp in itertools.groupby(sorted(query_data,
                                                  key=lambda qq: qq.dataset),
                                           key=lambda q: q.dataset):

        if refs is not None and ref_name not in refs:
            continue

        grp = list(grp)

        plt.figure(figsize=(7, 4))
        ax = plt.subplot(111)
        plt.subplots_adjust(right=0.6)
        plt.title(ref_name)

        ax.spines['right'].set_visible(False)
        ax.spines['top'].set_visible(False)
        ax2 = None
        if y2 is not None:
            ax2 = ax.twinx()
        for cs in grp:
            if cs.breaks_df is not None:

                marker = next(markers)
                clr = next(colors)
                bed = cs.breaks_df  #[cs.breaks_df["quantified"]]

                if "strata" not in bed.columns or cs.stratify_range is None or not stratify:
                    ax.plot(cs.scores[x],
                            cs.scores[y],
                            label=cs.caller,
                            marker=marker,
                            markerfacecolor=clr,
                            alpha=alpha,
                            markeredgecolor=clr,
                            color="none")
                    if ax2:
                        ax2.plot(cs.scores[x],
                                 cs.scores[y2],
                                 marker=marker,
                                 markerfacecolor='none',
                                 alpha=alpha,
                                 label=cs.caller,
                                 markeredgecolor=clr,
                                 color="none")
                else:
                    x_val = []
                    y_val = []
                    y_val2 = []
                    for threshold in cs.stratify_range:
                        # df = bed[(bed["strata"] >= threshold) & (~bed["DTP"])]
                        df = bed[bed["strata"] >= threshold]
                        x_val.append(calc_score(df, x, keep_duplicates))
                        y_val.append(calc_score(df, y, keep_duplicates))
                        if ax2:
                            y_val2.append(calc_score(df, y2))

                    # ax.scatter(x_val, y_val, alpha=0.6, marker=marker, s=20)
                    # ax.plot(x_val, y_val, label=cs.caller, alpha=0.6)
                    ax.plot(x_val,
                            y_val,
                            label=cs.caller,
                            marker=marker,
                            markersize=markersize,
                            alpha=alpha,
                            color=clr)

                    if ax2:
                        # ax2.scatter(x_val, y_val2, alpha=0.6, marker=marker, s=20)
                        ax2.plot(x_val,
                                 y_val2,
                                 linestyle='dashed',
                                 label=cs.caller,
                                 marker=marker,
                                 markersize=markersize,
                                 alpha=alpha,
                                 color=clr)
            else:
                next(markers)
                next(colors)

        ax.set_xlabel(x)
        ax.set_ylabel(y)
        if ax2:
            ax2.set_ylabel(y2)
        if xlim is not None:
            plt.xlim(*xlim)
        if ylim is not None:
            ax.set_ylim(*ylim)
        if y2lim is not None:
            ax2.set_ylim(*y2lim)
        # if ylim is not None:
        #     plt.ylim(*ylim)
        plt.legend(loc='center left', bbox_to_anchor=(1.25, 0.5))
        plots[ref_name] = plt
        if save_name:
            plt.savefig(save_name)
    if show:
        plt.show()
    return plots
示例#4
0
文件: evol_error.py 项目: nsaura/ML
#-------------------------------------------------------------------
#-------------------------------------------------------------------

dict_layers = {"I"  : 4,\
               "N1" : 500,\
               "N2" : 10,\
##               "N6" : 10,\
#               "N7" : 10,\
#               "N8" : 10,\
               "O"  : 1}

Nxlst = [500, 600, 700, 800, 900, 1000]

d = {}
Color = iter(cm.Dark2(np.linspace(0, 1, len(Nxlst) + 1)))
c = next(Color)

plt_lines = []
leg = []

for Nx in Nxlst:
    X, y = build_train(Nx)
    c = next(Color)
    kwargs = {"bsz" : 50,\
              "BN"  : True,\
              "color" : c,\
              "label" : "Nx = %d" % Nx\
             }

    nn = mlt.build_case(8e-4, X, y, act= "selu", opti="Adam", loss="OLS", max_epoch = 100,\
                 max_iter=1000,
                 penalty='l2',
                 class_weight={
                     1: 1,
                     0: 1
                 })

b_thetas_list = []
for x in subj_data_list[0]:
    b_thetas_list.append(x[3] * 180 / np.pi)
b_thetas_list = sorted(set(b_thetas_list))

coef_list = []

for num, subj_data in enumerate(subj_data_list):
    color = iter(cm.Dark2(np.linspace(
        .5, 1, 5)))  #not the best colormap (try a better one)
    plt.figure(figsize=(8, 6))
    for ibtheta, b_theta in enumerate(b_thetas_list):
        X = []
        y = []

        for i in subj_data:
            if i[3] * 180 / np.pi == b_theta:
                X.append(i[1] * 180 / np.pi)
                if i[2] == 'right':
                    y.append(1)
                else:
                    y.append(0)

        X = np.asarray(X)
        X = X[:, np.newaxis]