예제 #1
0
def analyze(results, out_path, name="analysis", plot=False):
    """Analyze results.

    Given a results dataframe, generates a folder with
    results and a dataframe of the exact data used to generate those results,
    aswell as introspection to return information on the computer

    parameters
    ----------
    out_path: location to store analysis folder

    results: Dataframe generated from Results object

    path: string/None

    plot: whether to plot results

    Either path or results is necessary

    """
    # input checks #
    if not isinstance(out_path, str):
        raise ValueError("Given out_path argument is not string")
    elif not os.path.isdir(out_path):
        raise IOError("Given directory does not exist")
    else:
        analysis_path = os.path.join(out_path, name)

    unique_ids = [plt._simplify_names(x) for x in results.pipeline.unique()]
    simplify = True
    print(unique_ids)
    print(set(unique_ids))
    if len(unique_ids) != len(set(unique_ids)):
        log.warning(
            "Pipeline names are too similar, turning off name shortening")
        simplify = False

    os.makedirs(analysis_path, exist_ok=True)
    # TODO: no good cross-platform way of recording CPU info?
    with open(os.path.join(analysis_path, "info.txt"), "a") as f:
        dt = datetime.now()
        f.write("Date: {:%Y-%m-%d}\n Time: {:%H:%M}\n".format(dt, dt))
        f.write("System: {}\n".format(platform.system()))
        f.write("CPU: {}\n".format(platform.processor()))

    results.to_csv(os.path.join(analysis_path, "data.csv"))

    stats = compute_dataset_statistics(results)
    stats.to_csv(os.path.join(analysis_path, "stats.csv"))
    P, T = find_significant_differences(stats)
    if plot:
        fig, color_dict = plt.score_plot(results)
        fig.savefig(os.path.join(analysis_path, "scores.pdf"))
        fig = plt.summary_plot(P, T, simplify=simplify)
        fig.savefig(os.path.join(analysis_path, "ordering.pdf"))
예제 #2
0
파일: __init__.py 프로젝트: xtaraim/moabb
def analyze(results, out_path, name='analysis', suffix=''):
    '''Given a results object (or the location for one), generates a folder with
    results and a dataframe of the exact data used to generate those results, as
    well as introspection to return information on the computer

    In:
    out_path: location to store analysis folder

    results: Obj/tuple;

    path: string/None

    Either path or results is necessary

    '''
    # input checks #
    if type(results) is not Results:
        res = Results(*results, suffix=suffix)
    if type(out_path) is not str:
        raise ValueError('Given out_path argument is not string')
    elif not os.path.isdir(out_path):
        raise IOError('Given directory does not exist')
    else:
        analysis_path = os.path.join(out_path, name)

    os.makedirs(analysis_path, exist_ok=True)
    # TODO: no good cross-platform way of recording CPU info?
    with open(os.path.join(analysis_path, 'info.txt'), 'a') as f:
        f.write('Date: {:%Y-%m-%d}\n Time: {:%H:%M}\n'.format(
            datetime.now(), datetime.now()))
        f.write('System: {}\n'.format(platform.system()))
        f.write('CPU: {}\n'.format(platform.processor()))

    res = results

    data = res.to_dataframe()
    data.to_csv(os.path.join(analysis_path, 'data.csv'))

    plt.score_plot(data).savefig(os.path.join(analysis_path, 'scores.pdf'))
    plt.time_line_plot(data).savefig(os.path.join(analysis_path, 'time2d.pdf'))
예제 #3
0
def analyze(results, out_path, name='analysis', plot=False):
    '''Analyze results.

    Given a results dataframe, generates a folder with
    results and a dataframe of the exact data used to generate those results,
    aswell as introspection to return information on the computer

    parameters
    ----------
    out_path: location to store analysis folder

    results: Dataframe generated from Results object

    path: string/None

    plot: whether to plot results

    Either path or results is necessary

    '''
    # input checks #
    if type(out_path) is not str:
        raise ValueError('Given out_path argument is not string')
    elif not os.path.isdir(out_path):
        raise IOError('Given directory does not exist')
    else:
        analysis_path = os.path.join(out_path, name)

    os.makedirs(analysis_path, exist_ok=True)
    # TODO: no good cross-platform way of recording CPU info?
    with open(os.path.join(analysis_path, 'info.txt'), 'a') as f:
        dt = datetime.now()
        f.write('Date: {:%Y-%m-%d}\n Time: {:%H:%M}\n'.format(dt, dt))
        f.write('System: {}\n'.format(platform.system()))
        f.write('CPU: {}\n'.format(platform.processor()))

    results.to_csv(os.path.join(analysis_path, 'data.csv'))

    stats = compute_dataset_statistics(results)
    stats.to_csv(os.path.join(analysis_path, 'stats.csv'))
    P, T = find_significant_differences(stats)
    if plot:
        fig, color_dict = plt.score_plot(results)
        fig.savefig(os.path.join(analysis_path, 'scores.pdf'))
        fig = plt.summary_plot(P, T)
        fig.savefig(os.path.join(analysis_path, 'ordering.pdf'))
예제 #4
0
evaluation = CrossSessionEvaluation(paradigm=paradigm,
                                    datasets=datasets,
                                    suffix="stats",
                                    overwrite=overwrite)

results = evaluation.process(pipelines)

##############################################################################
# MOABB plotting
# ----------------
#
# Here we plot the results using some of the convenience methods within the
# toolkit.  The score_plot visualizes all the data with one score per subject
# for every dataset and pipeline.

fig = moabb_plt.score_plot(results)
plt.show()

###############################################################################
# For a comparison of two algorithms, there is the paired_plot, which plots
# performance in one versus the performance in the other over all chosen
# datasets. Note that there is only one score per subject, regardless of the
# number of sessions.

fig = moabb_plt.paired_plot(results, "CSP+LDA", "RG+LDA")
plt.show()

###############################################################################
# Statistical testing and further plots
# ----------------------------------------
#