Python matplotlib.pyplot 模块,boxplot() 实例源码

我们从Python开源项目中,提取了以下29个代码示例,用于说明如何使用matplotlib.pyplot.boxplot()

项目:chash    作者:luhsra    | 项目源码 | 文件源码
def plotTimeMultiHistogram(parseTimes, hashTimes, compileTimes, filename): # times in ms
    bins = np.linspace(0, 5000, 50)
    data = np.vstack([parseTimes, hashTimes, compileTimes]).T
    fig, ax = plt.subplots()
    plt.hist(data, bins, alpha=0.7, label=['parsing', 'hashing', 'compiling'], color=[parseColor, hashColor, compileColor])
    plt.legend(loc='upper right')
    plt.xlabel('time [ms]')
    plt.ylabel('#files')
    fig.savefig(filename)

    fig, ax = plt.subplots()
    boxplot_data = [[i/1000 for i in parseTimes], [i/1000 for i in hashTimes], [i/1000 for i in compileTimes]] # times to s
    plt.boxplot(boxplot_data, 0, 'rs', 0, [5, 95])
    plt.xlabel('time [s]')
    plt.yticks([1, 2, 3], ['parsing', 'hashing', 'compiling'])
    #lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) # legend on the right
    fig.savefig(filename[:-4] + '_boxplots' + GRAPH_EXTENSION)
项目:CommunityMaintenanceSupport    作者:AgileVentures    | 项目源码 | 文件源码
def total_posts_for_week_ending_on_given_day(posts, end_date):
    beginning_date = end_date - datetime.timedelta(days=6)
    return reduce(lambda total, date: posts[date] + total if date <= end_date and beginning_date <= date else total , posts, 0)

# one_week_before_premium_signup = {}
# two_weeks_before_premium_signup = {}
# three_weeks_before_premium_signup = {}
# for premium_user in premium_postings:
#     one_week_before_premium_signup[premium_user] = total_posts_for_week_ending_on_given_day(premium_postings[premium_user]["posts"], premium_postings[premium_user]["start_date"])
#     two_weeks_before_premium_signup[premium_user] = total_posts_for_week_ending_on_given_day(premium_postings[premium_user]['posts'],premium_postings[premium_user]["start_date"] - datetime.timedelta(days=7))
#     three_weeks_before_premium_signup[premium_user] = total_posts_for_week_ending_on_given_day(premium_postings[premium_user]['posts'],premium_postings[premium_user]["start_date"] - datetime.timedelta(days=14))

# plt.figure()
# plt.boxplot([one_week_before_premium_signup.values(), two_weeks_before_premium_signup.values(), three_weeks_before_premium_signup.values()],1)

# plt.show()
#two_week_before_export_time = datetime.datetime.strptime('2017-03-12',"%Y-%m-%d")
#three_week_before_export_time = datetime.datetime.strptime('2017-03-05',"%Y-%m-%d")
项目:tschdata    作者:tum-lkn    | 项目源码 | 文件源码
def plot_delays(self):
        """
        Plot delay distribution for all motes
        :return:
        """
        plt.figure()
        delays = []
        for addr in gl_mote_range:
            delays.append(self.get_delays(addr))

        plt.boxplot(delays, showmeans=True, showfliers=False)

        plt.ylabel('delay, s')
        plt.xlabel('mote #')
        plt.grid(True)

        # return means
        return [np.mean(d) for d in delays if len(d) > 0]
项目:IRCLogParser    作者:prasadtalasila    | 项目源码 | 文件源码
def box_plot(data, output_directory, output_file_name):
    """
        Plots Box Plots

    Args:
        data (list):  data
        output_drectory(str): location to save graph
        output_file_name(str): name of the image file to be saved

    Returns:
        null
    """
    plt.figure()
    plt.boxplot(data)

    plt.legend()
    saver.check_if_dir_exists(output_directory)
    plt.savefig(output_directory + "/" + output_file_name + ".png")
    plt.close()
项目:wub    作者:nanoporetech    | 项目源码 | 文件源码
def plot_boxplots(self, data_map, title="", xlab="", ylab="", xticks_rotation=0, xticks_fontsize=5):
        """Plot multiple pairs of data arrays.

        :param self: object.
        :param data_map: A dictionary with labels as keys and lists as data values.
        :param title: Figure title.
        :param xlab: X axis label.
        :param ylab: Y axis label.
        :param xticks_rotation: Rotation value for x tick labels.
        :param xticks_fontsize: Fontsize for x tick labels.
        :returns: None
        :rtype: object
        """
        fig = plt.figure()
        plt.boxplot(list(data_map.values()))
        plt.xticks(np.arange(len(data_map)) + 1, data_map.keys(), rotation=xticks_rotation, fontsize=xticks_fontsize)
        self._set_properties_and_close(fig, title, xlab, ylab)
项目:FaceAnalysis    作者:ElliotSalisbury    | 项目源码 | 文件源码
def topRatingAuthors(df):
    authorRatings = collections.defaultdict(list)
    for index, row in df.iterrows():
        authorRatings[row['Rating Author']].append(row["Rating"])

    authors = list(authorRatings.keys())
    authors = sorted(authors, key=lambda author: len(authorRatings[author]))

    top = authors[-10:]

    data = np.random.lognormal(size=(37, 4), mean=1.5, sigma=1.75)
    myData = []
    labels = []
    for author in top:
        if author == "None":
            continue
        myData.append(authorRatings[author])
        labels.append(author)

    plt.boxplot(myData, labels=labels)
    plt.savefig("Top Commenters Distribution of Ratings")
    plt.clf()
项目:openml-pimp    作者:janvanrijn    | 项目源码 | 文件源码
def box_plots(results, all_tasks, clf_params):
    boxplotlabel_names = []
    boxplot_data = []

    tasks = obtain_complete_tasks(results, all_tasks, [clf_params])

    for strategy in results[clf_params]:
        current = []
        for task_id in tasks:
            current.append(results[clf_params][strategy][task_id])
        boxplot_data.append(current)
        boxplotlabel_names.append(strategy_name(strategy))

    # creates the box plot
    plt.figure()
    plt.boxplot(boxplot_data)
    plt.xticks(list(range(1, len(boxplotlabel_names) + 1)), boxplotlabel_names, fontsize=12, rotation=45, ha='right')
    plt.savefig(os.path.join(args.result_directory, clf_params + '_boxplot.png'), bbox_inches='tight')
    plt.close()
项目:openml-pimp    作者:janvanrijn    | 项目源码 | 文件源码
def boxplot_traces(strategy_traces, save_directory, name):
    # only import matplotlib for this function, as meta cluster doesn't like it
    import matplotlib.pyplot as plt
    try:
        os.makedirs(save_directory)
    except FileExistsError:
        pass

    data = []
    label_names = []

    for strategy, trace in strategy_traces.items():
        current = [trace_item.evaluation for trace_item in trace.trace_iterations.values()]
        data.append(current)
        label_names.append(strategy.split('__')[0])

    plt.figure()
    plt.boxplot(data)
    plt.xticks(list(range(1, len(label_names) + 1)), label_names)
    plt.savefig(os.path.join(save_directory, name))
    plt.close()
项目:demcoreg    作者:dshean    | 项目源码 | 文件源码
def bin_stats(x, y, stat='median', nbins=360):
    import scipy.stats
    #bin_range = (x.min(), x.max())
    bin_range = (0., 360.)
    bin_width = (bin_range[1] - bin_range[0]) / nbins
    print("Computing 1-degree bin statistics: %s" % stat)
    bin_stat, bin_edges, bin_number = scipy.stats.binned_statistic(x, y, \
            statistic=stat, bins=nbins, range=bin_range)
    bin_centers = bin_edges[:-1] + bin_width/2.
    bin_stat = np.ma.masked_invalid(bin_stat)

    """
    #Mask bins in grid directions, can potentially contain biased stats
    badbins = [0, 45, 90, 180, 225, 270, 315]
    bin_stat = np.ma.masked_where(np.around(bin_edges[:-1]) % 45 == 0, bin_stat)
    bin_edges = np.ma.masked_where(np.around(bin_edges[:-1]) % 45 == 0, bin_edges)
    """

    #Generate plots
    if False:
        plt.figure()
        #Need to pull out original values for each bin
        #Loop through unique bin numbers, pull out original values into list of lists
        #plt.boxplot(bin_stat, sym='')
        plt.xlim(*bin_range)
        plt.xticks(np.arange(bin_range[0],bin_range[1],30))
        plt.ylabel('dh/tan(slope) (m)')
        plt.xlabel('Aspect (1-deg bins)')

        plt.figure()
        plt.bar(bin_centers, bin_count)
        plt.xlim(*bin_range)
        plt.xticks(np.arange(bin_range[0],bin_range[1],30))
        plt.ylabel('Count')
        plt.xlabel('Aspect (1-deg bins)')
        plt.show()

    return bin_stat, bin_edges, bin_centers

#Function for fitting Nuth and Kaab (2011)
项目:krait    作者:lmdu    | 项目源码 | 文件源码
def box(x, xlabels, ylabel, name, dpi=96):
    colors = ['pink', 'lightblue', 'lightgreen', 'orangered', 'goldenrod', 'orchid']
    bplot = plt.boxplot(x,
        notch = False,
        vert = True, 
        patch_artist = True,
        labels = xlabels,
        showfliers = False
    )
    for path, color in zip(bplot['boxes'], colors):
        path.set_facecolor(color)
    plt.ylabel(ylabel)
    plt.savefig(cache_path(name), dpi=dpi, bbox_inches='tight')
    plt.close()
项目:MLPractices    作者:carefree0910    | 项目源码 | 文件源码
def box_plot(self):
        plt.figure()
        plt.boxplot(self._data, vert=False, showmeans=True)
        plt.show()
项目:amplicon_sequencing_pipeline    作者:thomasgurry    | 项目源码 | 文件源码
def plotAlphaDiversities(self, alphaDiversityFile, figure_filename):
        # Take an alpha diversity file and create a box plot
        with open(alphaDiversityFile,'r') as fid:
            all_lines = fid.readlines()
            alpha_diversities = [float(line.split()[1]) for line in all_lines[1:]]
            sampleIDs = [line.split()[0] for line in all_lines[1:]]
            figure()
            plt.boxplot(alpha_diversities)
            plt.xlabel('Sample category')
            plt.ylabel('Alpha diversity')
            plt.savefig(figure_filename)
项目:chainladder-python    作者:jbogaardt    | 项目源码 | 文件源码
def __dict_plot(self, my_dict):
        """ Method that renders the matplotlib plots based on the configurations
        in __get_plot_dict().  This method should probably be private and may be
        so in a future release.

        """
        for i in range(len(my_dict['chart_type_dict']['type'])):
            if my_dict['chart_type_dict']['type'][i] == 'plot':
                _ = plt.plot(my_dict['chart_type_dict']['x'][i], 
                             my_dict['chart_type_dict']['y'][i],
                             linestyle=my_dict['chart_type_dict']['linestyle'][i], 
                             marker=my_dict['chart_type_dict']['marker'][i], 
                             color=my_dict['chart_type_dict']['color'][i])
            if my_dict['chart_type_dict']['type'][i] == 'bar':
                _ =plt.bar(height = my_dict['chart_type_dict']['height'][i], 
                           left = my_dict['chart_type_dict']['left'][i],
                           yerr = my_dict['chart_type_dict']['yerr'][i], 
                           bottom = my_dict['chart_type_dict']['bottom'][i],
                           width = my_dict['chart_type_dict']['width'][i])
            if my_dict['chart_type_dict']['type'][i] == 'line':
                _ = plt.gca().set_prop_cycle(None)
                for j in range(my_dict['chart_type_dict']['rows'][i]):
                    _ = plt.plot(my_dict['chart_type_dict']['x'][i], 
                                 my_dict['chart_type_dict']['y'][i].iloc[j], 
                                 linestyle=my_dict['chart_type_dict']['linestyle'][i], 
                                 linewidth=my_dict['chart_type_dict']['linewidth'][i],
                                 alpha=my_dict['chart_type_dict']['alpha'][i])
            if my_dict['chart_type_dict']['type'][i] == 'hist':
                _ = plt.hist(my_dict['chart_type_dict']['x'][i],
                             bins=my_dict['chart_type_dict']['bins'][i])
            if my_dict['chart_type_dict']['type'][i] == 'box':
                _ = plt.boxplot(my_dict['chart_type_dict']['x'][i],
                                positions= my_dict['chart_type_dict']['positions'][i],
                                showfliers=True)
            _ = plt.title(my_dict['Title'], fontsize=30)
            _ = plt.xlabel(my_dict['XLabel'], fontsize=20)
            _ = plt.ylabel(my_dict['YLabel'],fontsize=20)
项目:Machine-learning-for-cybersecurity    作者:Logo252    | 项目源码 | 文件源码
def show_plot_of_algorithms_results(methods_names, results, problem_title):
    """
    Shows plot of machine learning algorithms results.
    :param methods_names: machine learning methods names
    :param results: results got from applying methods for constructor
    :param problem_title: title of the problem
    """
    fig = plt.figure()

    axes = fig.add_subplot(111)  # 111 means "1x1 grid, first subplot"
    plt.boxplot(results)

    # x and y axis titles
    plt.xlabel('Machine learning algorithms')
    plt.ylabel('Accuracy')

    plt.title(
        'Machine learning algorithms applied for {}'.format(problem_title))

    # Set the Name of each box
    axes.set_xticklabels(methods_names)

    # Change font size of the text
    plt.rcParams.update({'font.size': 23})

    plt.show()
项目:throttlebot    作者:mchang6137    | 项目源码 | 文件源码
def plot_boxplot(axis_labels, box_array, metric, resource_field, subplot_number, ylim_min, ylim_max):
    axis_labels.sort()
    axis_labels = [str(x) for x in axis_labels]
    print axis_labels
    plt.xticks([1,2,3,4,5], axis_labels)
    # plt.subplot(subplot_number)
    plt.ylabel('Metric: {}'.format(metric))
    plt.ylim([ylim_min, ylim_max])
    plt.xlabel('Stress Percentage')
    plt.title('Stressing only {}'.format(resource_field))
    plt.boxplot(box_array)
    plt.grid(True)

# OUTDATED NO CONTAINER
项目:tschdata    作者:tum-lkn    | 项目源码 | 文件源码
def plot_all_reliabilities():
    """
    Plot packet delivery ratio for all data sets
    :return:
    """
    rel = []
    avg = []

    for filename in get_all_files(gl_dump_path):
        p = BasicProcessor(filename=filename)

        # compensate for the rest
        p.correct_timeline(clean_all=False)

        # plot the timeline
        # p.plot_timeline(writer=None)
        r, w = p.plot_motes_reliability(return_result=True)
        rel.append(r)
        avg.append(w)

    plt.figure(figsize=(7.5, 3.5))
    bp = plt.boxplot(rel, flierprops={'linewidth':1.5}, showmeans=True)

    plt.hlines(0.95, xmin=0, xmax=9, linestyles='--', linewidth=1, label='0.95')
    x_axis = list(range(9))
    labels = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII']

    plt.xticks(x_axis, labels)
    plt.grid(True)
    plt.ylim((0.35, 1.1))
    plt.legend(loc=4)

    plt.ylabel('PDR')

    set_box_plot(bp)

    plt.show()
项目:tschdata    作者:tum-lkn    | 项目源码 | 文件源码
def plot_delay_per_mote(self, addr):
        """
        Plot the delay distribution for motes
        :return:
        """
        plt.figure()
        plt.boxplot(self.get_delays(addr))
        plt.grid(True)
项目:HiCembler    作者:lpryszcz    | 项目源码 | 文件源码
def main(fn, method="ward"): #
    d, bin_chr, bin_position, contig2size = load_matrix(fn, remove_shorter=0)
    sizes = np.diff(bin_position, axis=1)[:, 0] / 1000
    contacts = d.diagonal()
    print d.sum(), d.diagonal().sum()
    # get bins
    bins = np.arange(1, 101, 5)

    # get counts
    contacts = [[] for i in range(len(bins)+1)]
    for s, c in zip(np.digitize(sizes, bins, right=1), d.diagonal()):
        contacts[s].append(c)
    print len(contacts), len(bins), len(sizes)#, contacts# np.digitize(sizes, bins, right=1)
    plt.title("HiC contacts at given distance")
    plt.boxplot(contacts[:-1], 1, '', positions=bins, widths=.75*bins[0])#; plt.legend("HiC data")
    plt.xticks(rotation=90)

    plt.xlabel("contig size [kb]")
    plt.ylabel("self contacts")
    plt.xlim(xmin=-bins[0])
    plt.ylim(ymin=0)#, ymax=20)
    #plt.yscale('log')
    #plt.show()
    outfn = fn+".selfcontacts.png"
    plt.savefig(outfn)
    print "Figure saved as: %s"%outfn
项目:Discriminator    作者:NicolasAG    | 项目源码 | 文件源码
def plot_human_correlation(self, data):
        print "\nGet probabilities of each response..."
        n_batches = len(data['r']) // self.batch_size
        all_human_scores = [s for s in data['score']]
        all_discriminator_scores = []
        human_to_disc = {}
        for i in xrange(n_batches):  # i = batch index
            probas = self.compute_probas(data, i)  # probabilities of each response within that batch of being true
            scores = [s for s in data['score'][i*len(probas): (i+1)*len(probas)]]
            for j, s in enumerate(scores):  # j = context-response-score triple index
                if s not in human_to_disc:
                    human_to_disc[s] = [probas[j]]
                else:
                    human_to_disc[s].append(probas[j])
            all_discriminator_scores.extend(probas)

        n = min(len(all_human_scores), len(all_discriminator_scores))
        print "discriminator--human pearson:", pearsonr(all_human_scores[:n], all_discriminator_scores[:n])
        print "discriminator--human spearman:", spearmanr(all_human_scores[:n], all_discriminator_scores[:n])

        print "number of different scores:", len(human_to_disc)
        # Order dictionary by keys (by human scores)
        human_to_disc = collections.OrderedDict(sorted(human_to_disc.items()))
        fig = plt.figure()
        plt.boxplot([human_to_disc[s] for s in human_to_disc.keys()], labels=human_to_disc.keys())
        plt.title('Human - Discriminator score correlation')
        plt.xlabel('human score')
        plt.ylabel('discriminator score')
        plt.savefig('./plots/plot_human-disc_scores.png')
        plt.close(fig)
        print "saved plot."
项目:human_activity    作者:bfetler    | 项目源码 | 文件源码
def gridscoreBoxplot2(gslist, plotdir, label, xlabel):
    vals = list(map(lambda e: e.cv_validation_scores, gslist))
    labs = list(map(lambda e: list(e.parameters.values()), gslist))
# test if labs[0].__class__ == 'list' and len(labs[0]) > 1
    labs = list(map(lambda e: reduce(lambda a,b: str(a)+"\n"+str(b), e), labs))
    xpar = list(gslist[0].parameters.keys())
    xpar = reduce(lambda a,b: a+", "+b, xpar)
    plt.clf()
    plt.boxplot(vals, labels=labs)
    plt.title("Human Activity Fitted by Random Forest")
    plt.xlabel(xpar + " (with " + xlabel + ")")
    plt.ylabel("Fraction Correct")
    plt.tight_layout()
    plt.savefig(plotdir + "gridscore_" + label)
项目:human_activity    作者:bfetler    | 项目源码 | 文件源码
def gridscoreBoxplot(gslist, plotdir, label, xlabel):
    vals = list(map(lambda e: e.cv_validation_scores, gslist))
    labs = list(map(lambda e: list(e.parameters.values()), gslist))
    labs = list(map(lambda e: str(e[0]), labs))
    plt.clf()
    plt.boxplot(vals, labels=labs)
    plt.title("Human Activity Fitted by Random Forest")
    plt.xlabel(label + " (with " + xlabel + ")")
    plt.ylabel("Fraction Correct")
    plt.savefig(plotdir + "gridscore_" + label)
项目:Parallel-SGD    作者:angadgill    | 项目源码 | 文件源码
def boxplot_runtimes(runtimes, pred_type, configuration):
    """
    Plot a new `Figure` with boxplots of prediction runtimes.

    Parameters
    ----------
    runtimes : list of `np.array` of latencies in micro-seconds
    cls_names : list of estimator class names that generated the runtimes
    pred_type : 'bulk' or 'atomic'

    """

    fig, ax1 = plt.subplots(figsize=(10, 6))
    bp = plt.boxplot(runtimes, )

    cls_infos = ['%s\n(%d %s)' % (estimator_conf['name'],
                                  estimator_conf['complexity_computer'](
                                      estimator_conf['instance']),
                                  estimator_conf['complexity_label']) for
                 estimator_conf in configuration['estimators']]
    plt.setp(ax1, xticklabels=cls_infos)
    plt.setp(bp['boxes'], color='black')
    plt.setp(bp['whiskers'], color='black')
    plt.setp(bp['fliers'], color='red', marker='+')

    ax1.yaxis.grid(True, linestyle='-', which='major', color='lightgrey',
                   alpha=0.5)

    ax1.set_axisbelow(True)
    ax1.set_title('Prediction Time per Instance - %s, %d feats.' % (
        pred_type.capitalize(),
        configuration['n_features']))
    ax1.set_ylabel('Prediction Time (us)')

    plt.show()
项目:stock-predict-by-RNN-LSTM    作者:blockchain99    | 项目源码 | 文件源码
def make_plots(self):
        # Boxplot to compare classifier error distributions
        plt.figure()
        plt.boxplot(self.errors)
        plt.xlabel(' vs '.join(self.names))
        plt.ylabel('K-fold cross-validation error [%]')
        plt.xticks(range(self.count), self.names)
        plt.show()
项目:tschdata    作者:tum-lkn    | 项目源码 | 文件源码
def plot_all_path_delays(shared=False):
    """
    Plot for interference / buffering delay for all scenarios
    :return:
    """

    # create a schedule
    if shared:
        folder = gl_dump_path + '/shared/'
        sched = Schedule(num_slots=gl_num_active_slots, num_off=gl_num_off_slots,
                         num_serial=gl_num_serial_slots, shared=shared)
    else:
        folder = gl_dump_path + '/tdma/'
        sched = Schedule(num_slots=gl_num_active_slots, num_off=gl_num_off_slots, num_serial=gl_num_serial_slots)

    files = [f for f in os.listdir(folder) if isfile(join(folder, f))]
    files = sorted(files)

    int_delays = []
    buf_delays = []

    for idx, filename in enumerate(files):
        if idx == 1:
            # ignore medium interference case
            continue

        p = AdvDelayProcessor(filename=folder + filename, schedule=sched)

        r0, m0 = p.plot_path_delay()

        i, b = p.print_delay(r0, m0)
        int_delays.append(i)
        buf_delays.append(b)

    # comparison figure for different delays
    plt.figure()
    plt.boxplot(int_delays + buf_delays, showmeans=True, showfliers=False)

    x = range(1, 7)
    plt.xticks(x,  ['I (i)', 'III (i)', 'IV (i)', 'I (b)', 'III (b)', 'IV (b)'])
    locs, labels = plt.xticks()
    plt.setp(labels, rotation=0)

    plt.grid(True)
    plt.show()
项目:tschdata    作者:tum-lkn    | 项目源码 | 文件源码
def plot_intercepting_path_delays(ax, shared=False):
    if shared:
        folder = gl_dump_path + '/shared/'
        sched = Schedule(num_slots=gl_num_active_slots, num_off=gl_num_off_slots,
                         num_serial=gl_num_serial_slots, shared=shared)
    else:
        folder = gl_dump_path + '/tdma/'
        sched = Schedule(num_slots=gl_num_active_slots, num_off=gl_num_off_slots, num_serial=gl_num_serial_slots)

    files = [f for f in os.listdir(folder) if isfile(join(folder, f))]
    files = sorted(files)

    df = pd.DataFrame(columns=['set', 'path', 'real_delay', 'min_delay'])

    for idx, filename in enumerate(files):
        if idx == 1:
            # skip the low interference scenario
            continue

        set_id = idx
        if idx > 0:
            set_id -= 1

        pr = AdvDelayProcessor(filename=folder + filename, schedule=sched)

        r, m = pr.plot_path_delay()

        for i, el in enumerate(r):
            df = df.append({'set': set_id, 'path': el[0], 'real_delay': el[1], 'min_delay': m[i][1]}, ignore_index=True)

    data = df.groupby('path').filter(lambda x: len(x) == 3)

    print(data)

    data['min_path_delay'] = data.path.apply(sched.get_min_path_delay)


    int_delay = [[], [], []]
    buf_delay = [[], [], []]

    for iter in data.iterrows():
        index, d = iter
        int_delay[int(d.set)] += list((np.array(d.min_delay) - d.min_path_delay))#/len(d.path))
        buf_delay[int(d.set)] += list((np.array(d.real_delay) - np.array(d.min_delay)))#/len(d.path))

    bp = ax.boxplot(int_delay + buf_delay, showmeans=True, showfliers=False)
    plt.grid(True)
    set_box_plot(bp)
    # plt.show()
    return
项目:FaceAnalysis    作者:ElliotSalisbury    | 项目源码 | 文件源码
def numRatersWhoSubmitted(df):
    df = df[np.isfinite(df['Rating'])]

    submittersCount = collections.defaultdict(set)
    ratersCount = collections.defaultdict(set)
    ratingsByAuthor = collections.defaultdict(list)
    for index, row in df.iterrows():
        submittersCount[row["Submission Author"]].add(row["Folder"])
        ratersCount[row["Rating Author"]].add(row["Folder"])
        ratingsByAuthor[row["Rating Author"]].append(int(row["Rating"]))

    submitters = set(submittersCount.keys())
    raters = set(ratersCount.keys())
    both = raters.intersection(submitters)
    noSubmitters = raters-submitters

    print("#Submitters :%d, #Raters :%d, #Both :%d"%(len(submitters), len(raters), len(both)))

    numRepeatSubmissions = []
    for submitter in submittersCount:
        numRepeatSubmissions.append(len(submittersCount[submitter]))

    #HIST of the submission count
    plt.hist(numRepeatSubmissions, bins=np.arange(1,np.max(numRepeatSubmissions)+1)-0.5)
    title = "Number of Submissions Per User"
    plt.title(title, fontproperties=titleFont)
    plt.xticks(range(1,np.max(numRepeatSubmissions)+1))
    # plt.ylim(0,200)
    plt.xlim(0.5, np.max(numRepeatSubmissions)+0.5)
    plt.savefig(title)
    plt.clf()

    #box and whiskers wether submitters rate differently to others (empathy?)
    bothRatings = []
    noSubmittersRatings = []
    for rater in both:
        bothRatings.extend(ratingsByAuthor[rater])
    for rater in noSubmitters:
        noSubmittersRatings.extend(ratingsByAuthor[rater])
    labels = ["Submitters", "No Submitters"]
    data = [bothRatings, noSubmittersRatings]
    plt.boxplot(data, labels=labels)
    plt.savefig("Submitters Vs NoSubmmiters Distribution of Ratings")
    plt.clf()

    #variance of raters
    variance = []
    for rater in raters:
        if len(ratingsByAuthor[rater]) < 3:
            continue
        variance.append(np.var(ratingsByAuthor[rater]))
    plt.hist(variance, bins=np.arange(0,4,0.1))
    plt.savefig("Variance of Raters")
    plt.clf()
项目:jamespy_py3    作者:jskDr    | 项目源码 | 文件源码
def _save_result_r0(fold, sc_a2d, mc_a2d, cf_a3d):
    if not os.path.exists(fold):
        os.mkdir(fold)
        # os.mkdir(fold+'/sheet')
    fold += '/'

    plt.boxplot(sc_a2d)
    plt.show()
    print('Accuracy', ["DT", "SVC", "DNN", "CDNN", "RF"])
    print(np.average(sc_a2d, axis=0))
    plt.boxplot(mc_a2d)
    plt.show()
    print('Matthews Corrcoef', ["DT", "SVC", "DNN", "CDNN", "RF"])
    print(np.average(mc_a2d, axis=0))

    np.save(fold + 'sc_a2d', sc_a2d)
    np.save(fold + 'cf_a3d', cf_a3d)
    np.save(fold + 'mc_a2d', mc_a2d)

    sc_df = pd.DataFrame(sc_a2d, columns=["DT", "SVC", "DNN", "CDNN", "RF"])
    # sc_df.plot(kind='bar')
    # plt.show()
    sc_df.to_csv(fold + 'sheet_sc_a2d.csv')
    sc_df.head()

    mc_df = pd.DataFrame(mc_a2d, columns=["DT", "SVC", "DNN", "CDNN", "RF"])
    # mc_df.plot(kind='bar')
    # plt.show()
    mc_df.to_csv(fold + 'sheet_mc_a2d.csv')
    mc_df.head()

    cf_a3d_avg = np.average(cf_a3d, axis=0)

    mode_l = ['DT', 'SVC', 'DNN', 'CDNN', 'RF']
    with open(fold + 'cf_a3d_avg.txt', 'w') as F:
        # dt_score, sv_score, mlp_score, cnn_score, rf_score
        for i, mode in enumerate(mode_l):
            F.write("{} Confusion Metrics\n".format(mode))
            F.write(", ".join([str(x) for x in cf_a3d_avg[i, 0, :]]))
            F.write('\n')
            F.write(", ".join([str(x) for x in cf_a3d_avg[i, 1, :]]))
            F.write('\n\n')

    print("Current working directory:")
    print(os.getcwd() + '/' + fold)
    print("Saved data")
    print(os.listdir(fold))
项目:jamespy_py3    作者:jskDr    | 项目源码 | 文件源码
def save_result(fold, sc_a2d, mc_a2d, cf_a3d):
    if not os.path.exists(fold):
        os.mkdir(fold)
        # os.mkdir(fold+'/sheet')
    fold += '/'

    plt.boxplot(sc_a2d)
    plt.show()
    print('Accuracy', ["DT", "SVC", "DNN", "CDNN", "RF"])
    print(np.average(sc_a2d, axis=0))
    plt.boxplot(mc_a2d)
    plt.show()
    print('Matthews Corrcoef', ["DT", "SVC", "DNN", "CDNN", "RF"])
    print(np.average(mc_a2d, axis=0))

    np.save(fold + 'sc_a2d', sc_a2d)
    np.save(fold + 'cf_a3d', cf_a3d)
    np.save(fold + 'mc_a2d', mc_a2d)

    sc_df = pd.DataFrame(sc_a2d, columns=["DT", "SVC", "DNN", "CDNN", "RF"])
    # sc_df.plot(kind='bar')
    # plt.show()
    sc_df.to_csv(fold + 'sheet_sc_a2d.csv')
    sc_df.head()

    mc_df = pd.DataFrame(mc_a2d, columns=["DT", "SVC", "DNN", "CDNN", "RF"])
    # mc_df.plot(kind='bar')
    # plt.show()
    mc_df.to_csv(fold + 'sheet_mc_a2d.csv')
    mc_df.head()

    cf_a3d_avg = np.average(cf_a3d, axis=0)

    mode_l = ['DT', 'SVC', 'DNN', 'CDNN', 'RF']
    with open(fold + 'cf_a3d_avg.txt', 'w') as F:
        # dt_score, sv_score, mlp_score, cnn_score, rf_score
        for i, mode in enumerate(mode_l):
            F.write("{} Confusion Metrics\n".format(mode))
            for j in range(cf_a3d_avg.shape[1]):
                F.write(", ".join([str(x) for x in cf_a3d_avg[i, j, :]]))
                F.write('\n')
            # F.write(", ".join([str(x) for x in cf_a3d_avg[i, 1, :]]))
            F.write('\n')

    print("Current working directory:")
    print(os.getcwd() + '/' + fold)
    print("Saved data")
    print(os.listdir(fold))
项目:jamespy_py3    作者:jskDr    | 项目源码 | 文件源码
def save_result_multiple_classes(fold, sc_a2d, cf_a3d):
    if not os.path.exists(fold):
        os.mkdir(fold)
        # os.mkdir(fold+'/sheet')
    fold += '/'

    plt.boxplot(sc_a2d)
    plt.xticks(range(1,6), ["DT", "SVC", "DNN", "CDNN", "RF"])
    plt.show()
    print('Accuracy', ["DT", "SVC", "DNN", "CDNN", "RF"])
    print(np.average(sc_a2d, axis=0))

    # plt.boxplot(mc_a2d)
    # plt.show()
    # print('Matthews Corrcoef', ["DT", "SVC", "DNN", "CDNN", "RF"])
    # print(np.average(mc_a2d, axis=0))

    np.save(fold + 'sc_a2d', sc_a2d)
    np.save(fold + 'cf_a3d', cf_a3d)
    # np.save(fold + 'mc_a2d', mc_a2d)

    sc_df = pd.DataFrame(sc_a2d, columns=["DT", "SVC", "DNN", "CDNN", "RF"])
    # sc_df.plot(kind='bar')
    # plt.show()
    sc_df.to_csv(fold + 'sheet_sc_a2d.csv')
    sc_df.head()

    # mc_df = pd.DataFrame(mc_a2d, columns=["DT", "SVC", "DNN", "CDNN", "RF"])
    # mc_df.plot(kind='bar')
    # plt.show()
    # mc_df.to_csv(fold + 'sheet_mc_a2d.csv')
    # mc_df.head()

    cf_a3d_avg = np.average(cf_a3d, axis=0)

    mode_l = ['DT', 'SVC', 'DNN', 'CDNN', 'RF']
    with open(fold + 'cf_a3d_avg.txt', 'w') as F:
        # dt_score, sv_score, mlp_score, cnn_score, rf_score
        for i, mode in enumerate(mode_l):
            F.write("{} Confusion Metrics\n".format(mode))
            for j in range(cf_a3d_avg.shape[1]):
                F.write(", ".join([str(x) for x in cf_a3d_avg[i, j, :]]))
                F.write('\n')
            # F.write(", ".join([str(x) for x in cf_a3d_avg[i, 1, :]]))
            F.write('\n')

    print("Current working directory:")
    print(os.getcwd() + '/' + fold)
    print("Saved data")
    print(os.listdir(fold))