Results package

Loading of results saved by Analyzer subclasses.

sekupy.results.base module

sekupy.results.base.aggregate_searchlight(path, dir_id, filter)[source]

This should be used for a within subject analysis to collect data from different folders / subjects and collect results.

Be aware of the different parameters of the analysis.

So the best approach is to use get_searchlight_results and then use that to aggregate.

Parameters:
  • path ([type]) – [description]

  • dir_id ([type]) – [description]

sekupy.results.base.dataframe_to_afni(dataframe, outpath=None, command='3dttest++', label_attr='task', **filter)[source]

This should return a command or similar to perform statistics in AFNI

Use filter to select fields of interest

sekupy.results.base.filter_dataframe(dataframe, return_mask=False, return_null=False, **selection_dict)[source]
sekupy.results.base.get_configuration_fields(conf, *args)[source]

This function is used to collect fields from the configuration file.

Parameters:
  • conf (dictionary) – The configuration dictionary to be digged.

  • args (list of strings) – List of keywords to be found in the configuration file.

Returns:

[description]

Return type:

[type]

sekupy.results.base.get_connectivity_results(path, dir_id, field_list=['sample_slicer'], load_cv=False)[source]
sekupy.results.base.get_permutation_values(dataframe, keys, scores=['accuracy'], permutation_key='permutation')[source]
sekupy.results.base.get_results(path, pipeline_name, field_list=['sample_slicer'], result_keys=None, filter=None, n_jobs=-1, verbose=1)[source]

This function is used to collect the results from analysis folders.

Parameters:
  • path (str) – The pathname of the folder in which results are stored

  • pipeline_name (str) – The id / pattern to be used to filter folders. It is often the id of the Analysis Pipeline used.

  • field_list (list, optional) – List of different condition used by the AnalysisIterator (the default is [‘sample_slicer’], which is a fields of the configuration)

  • result_keys (list, optional) – List of strings indicating the other fields to get from the result (e.g. cross_validation folds)

  • filter (dictionary, optional) –

    This is used to filter dataset and include only fields or conditions. See `sekupy.preprocessing.SampleSlicer` for an example of dictionary

    (the default is None, which [default_description])

Returns:

dataframe – A table of the results in pandas format

Return type:

pandas dataframe

sekupy.results.base.get_searchlight_results(path, pipeline_name, field_list=['sample_slicer'], load_cv=False)[source]
sekupy.results.base.get_values(path, directory, field_list, result_keys)[source]

Extract analysis results and configuration from a results directory.

This function reads configuration and result files from an analysis directory and extracts specified fields and scores for further analysis.

Parameters:
  • path (str) – Base path containing analysis results

  • directory (str) – Specific directory name containing the results

  • field_list (list) – List of configuration fields to extract

  • result_keys (list or None) – Additional result keys to extract from .mat files

Returns:

List of dictionaries containing extracted field values and scores

Return type:

list

sekupy.results.base.ttest_values(dataframe, keys, scores=['accuracy'], popmean=0.5)[source]

sekupy.results.bids module

sekupy.results.bids.get_permutation_values(dataframe, keys, scores=['accuracy'])[source]
sekupy.results.bids.get_results_bids(path, field_list=['sample_slicer'], result_keys=[], scores=['score'], n_jobs=-1, verbose=1, filter=None, get_function=<function get_values_bids>, subjects=None, **kwargs)[source]

This function is used to collect the results from analysis folders.

Parameters:
  • path (str) – The pathname of the folder in which results are stored

  • field_list (list, optional) – List of different condition used by the AnalysisIterator (the default is [‘sample_slicer’], which is a fields of the configuration)

  • result_keys (list, optional) – List of strings indicating the other fields to get from the result (e.g. cross_validation folds)

  • filter (dictionary, optional) –

    This is used to filter dataset and include only fields or conditions. See `sekupy.preprocessing.SampleSlicer` for an example of dictionary

    (the default is None, which [default_description])

  • scores (list, optional) – Use mse and corr for regression, score for basic decoding

  • get_function (fx, optional) – The fucntion used to load data

  • subjects (list, optional) – List of string representing subject’s results to be loaded.

  • **kwargs (dictionary, optional) – List of parameters used to filter BIDS folder by ‘pipeline’ for example.

Returns:

dataframe – A table of the results in pandas format

Return type:

pandas dataframe

sekupy.results.bids.get_searchlight_results_bids(path, field_list=['sample_slicer'], **kwargs)[source]
sekupy.results.bids.get_values_bids(path, directory, field_list, result_keys, scores=None)[source]

[summary]

Parameters:
  • path ([type]) – [description]

  • directory ([type]) – [description]

  • field_list ([type]) – [description]

  • result_keys ([type]) – [description]

  • scores ([type], optional) – [description], by default None

Returns:

[description]

Return type:

[type]

sekupy.results.dataframe module

sekupy.results.dataframe.apply_function(dataframe, keys, attr='features', fx=<function <lambda>>, **fx_kwargs)[source]

This function executes an operation on the dataframe, it groups the dataframe by using the keys parameter and applies a function to values indicated by attr.

Parameters:
  • dataframe (pandas Dataframe) – The dataframe to be processed by the function

  • keys (list of string) – The keys that should be used to group the dataframe. These keys are those that were preserved in the output.

  • attr (str, optional) – The key were values should be found (the default is ‘features’)

  • fx (function, optional) – The function that is applied to values. (the default is lambda x:np.vstack(x).sum(0))

  • fx_kwargs (dictionary, optional) – Arguments passed to the fx function.

Returns:

dataframe

Return type:

The processed dataframe.

sekupy.results.dataframe.array2df(dataframe, key)[source]
sekupy.results.dataframe.clean_dataframe(dataframe, keys=[])[source]

Clean columns that are not informative. A list with keys can be provided to delete unuseful columns.

Parameters:

dataframe ([type]) – [description]

sekupy.results.dataframe.dataframe_dummy_columns(dataframe, keyword, mapping)[source]
sekupy.results.dataframe.dataframe_slicer(data, row=None, col=None, hue=None)[source]

Generator for name indices and data subsets for each unique value of row, col, hue.

Adaptively stolen from seaborn.

Yields:

(i, j, k), data_ijk (tuple of ints, DataFrame) – The ints provide an index into the {row, col, hue}_names attribute, and the dataframe contains a subset of the full data corresponding to each facet. The generator yields subsets that correspond with the self.axes.flat iterator, or self.axes[i, j] when col_wrap is None.

sekupy.results.dataframe.get_weights(dataframe)[source]
sekupy.results.dataframe.query_rows(dataframe, keys, attr, fx=<function max>)[source]

[summary]

Parameters:
  • dataframe ([type]) – [description]

  • keys ([type]) – [description]

  • attr ([type]) – [description]

  • fx ([type], optional) – [description], by default np.max

Returns:

[description]

Return type:

[type]

sekupy.results.simulations module

sekupy.results.simulations.calculate_centroids(dataframe)[source]

Returns the centroid of a clustering experiment

Parameters:
  • X (n_samples x n_features array) – The full dataset used for clustering

  • labels (n_samples array) – The clustering labels for each sample.

Returns:

centroids – The centroids of the clusters.

Return type:

n_cluster x n_features shaped array

sekupy.results.simulations.calculate_metrics(dataframe, metrics_kwargs=None, fixed_variables={})[source]

This function calculates the metrics that will be used to identify the number of clusters.

Parameters:
  • dataframe (a pandas dataframe) – The dataframe must contain the field `n_states`, it is supposed to have other fields with unique values (e.g. to identify the analysis)

  • metrics_kwargs (dictionary, optional) – dictionary with other metrics, by default None

  • fixed_variables (dict, optional) – Variables that will be added to output dataframe, usually they are fields that identify a single analysis, and are used to filter the dataframe, by default {}

Returns:

A dataframe with a number of rows equal to the number of k specified in n_states column of the original dataframe. The single entry is composed by the metric name, the metric value and the associated k, plus fixed_variables given as input parameter.

Return type:

dataframe

sekupy.results.simulations.convert_fields(data, key, idx, value)[source]
sekupy.results.simulations.dynamics_errors(dataframe)[source]
sekupy.results.simulations.find_best_k(dataframe)[source]

[summary]

Parameters:

dataframe ([type]) – [description]

Returns:

[description]

Return type:

[type]

sekupy.results.simulations.get_results(path, field_list=['sample_slicer'], result_keys=[], n_jobs=-1, verbose=1, filter={}, **kwargs)[source]

This function is used to collect the results from analysis folders.

Parameters:
  • path (str) – The pathname of the folder in which results are stored

  • field_list (list, optional) – List of different condition used by the AnalysisIterator (the default is [‘sample_slicer’], which is a fields of the configuration)

  • result_keys (list, optional) – List of strings indicating the other fields to get from the result (e.g. cross_validation folds)

  • filter (dictionary, optional) –

    This is used to filter dataset and include only fields or conditions. See `sekupy.preprocessing.SampleSlicer` for an example of dictionary

    (the default is None, which [default_description])

  • scores (list, optional) – Use mse and corr for regression, score for basic decoding

  • **kwargs (dictionary, optional) – List of parameters used to filter BIDS folder by ‘pipeline’ for example.

Returns:

dataframe – A table of the results in pandas format

Return type:

pandas dataframe

sekupy.results.simulations.get_values(path, directory, field_list, result_keys, filter={})[source]
sekupy.results.simulations.may_contain(fields, filter)[source]
sekupy.results.simulations.purge_dataframe(data, keys=['ds.a.snr', 'ds.a.time', 'ds.a.states', 'n_clusters', 'n_components'])[source]
sekupy.results.simulations.purge_fields(fields)[source]
sekupy.results.simulations.state_errors(dataframe)[source]