feature_reader#
- class analysis.feature_reader.FeatureReader(feature_dir: str | PathLike, feature_file: str | PathLike = '', binarize_label: bool = True)[source]#
- static filter_features(feature_columns: list, ch_name: str | None = None, list_feature_keywords: list[str] | None = None) list [source]#
filters read features by ch_name and/or modality
- static get_epochs(data, y_, epoch_len, sfreq, threshold=0) tuple[ndarray, ndarray] [source]#
Return epoched data.
- Parameters:
data (np.ndarray) – array of extracted features of shape (n_samples, n_channels, n_features)
y (np.ndarray) – array of labels e.g. ones for movement and zeros for no movement or baseline corr. rotameter data
epoch_len (int) – length of epoch in seconds
sfreq (int/float) – sampling frequency of data
threshold (int/float) – (Optional) threshold to be used for identifying events (default=0 for y_tr with only ones and zeros)
- Returns:
epoch_ (np.ndarray) – array of epoched ieeg data with shape (epochs,samples,channels,features)
y_arr (np.ndarray) – array of epoched event label data with shape (epochs,samples)
- normalize_features() DataFrame [source]#
Normalize feature_arr feature columns
- Returns:
z-scored feature_arr
- Return type:
pd.DataFrame
- plot_all_features(ch_used: str | None = None, time_limit_low_s: float | None = None, time_limit_high_s: float | None = None, normalize: bool = True, save: bool = False, title='all_feature_plt.pdf', ytick_labelsize: int = 10, clim_low: float | None = None, clim_high: float | None = None)[source]#
_summary_
- Parameters:
ch_used (str, optional)
time_limit_low_s (float, optional)
time_limit_high_s (float, optional)
normalize (bool, optional)
save (bool, optional)
title (str, optional) – default “all_feature_plt.pdf”
ytick_labelsize (int, optional) – by default 10
clim_low (float, optional) – by default None
clim_high (float, optional) – by default None
- plot_subject_grid_ch_performance(subject_name=None, performance_dict=None, plt_grid=False, feature_str_add='performance_allch_allgrid')[source]#
plot subject specific performance for individual channeal and optional grid points
- plot_target_averaged_channel(ch: str = '', list_feature_keywords: list[str] | None = None, features_to_plt: list | None = None, epoch_len: int = 4, threshold: float = 0.1, normalize_data: bool = True, show_plot: bool = True, title: str = 'Movement aligned features', ytick_labelsize=None, figsize_x: float = 8, figsize_y: float = 8) None [source]#
_summary_
- Parameters:
ch (str, optional)
features_to_plt (list, optional)
epoch_len (int, optional)
threshold (float, optional)
normalize_data (bool, optional)
show_plot (bool, optional)
title (str, optional) – by default “Movement aligned features”
ytick_labelsize (_type_, optional)
figsize_x (float, optional) – by default 8
figsize_y (float, optional) – by default 8
- plot_target_avg_all_channels(ch_names_ECOG=None, list_feature_keywords: list[str] = ['stft'], epoch_len: int = 4, threshold: float = 0.1)[source]#
Wrapper that call plot_features_per_channel for every given ECoG channel
- Parameters:
ch_names_ECOG (list, optional) – list of ECoG channel to plot features for, by default None
list_feature_keywords (list[str], optional) – keywords to plot, by default [“stft”]
epoch_len (int, optional) – epoch length in seconds, by default 4
threshold (float, optional) – threshold for event detection, by default 0.1
- read_results(performance_dict: dict = {}, subject_name: str | None = None, DEFAULT_PERFORMANCE: float = 0.5, read_grid_points: bool = True, read_channels: bool = True, read_all_combined: bool = False, ML_model_name: str = 'LM', read_mov_detection_rates: bool = False, read_bay_opt_params: bool = False, read_mrmr: bool = False, model_save: bool = False, save_results: bool = False, PATH_OUT: str = '', folder_name: str = '', str_add: str = '')[source]#
Save performances of a given patient into performance_dict from saved nm_decoder
- Parameters:
performance_dict (dictionary) – dictionary including decoding performances, by default dictionary
subject_name (string, optional) – subject name, by default None
DEFAULT_PERFORMANCE (float, optional) – chance performance, by default 0.5
read_grid_points (bool, optional) – true if grid point performances are read, by default True
read_channels (bool, optional) – true if channels performances are read, by default True
read_all_combined (bool, optional) – true if all combined channel performances are read, by default False
ML_model_name (str, optional) – machine learning model name, by default ‘LM’
read_mov_detection_rates (boolean, by defaulte False) – if True, read movement detection rates, as well as fpr’s and tpr’s
read_bay_opt_params (boolean, by default False)
read_mrmr (boolean, by default False)
model_save (boolean, by default False)
save_results (boolean, by default False)
PATH_OUT (string, by default None)
folder_name (string, by default None)
str_add (string, by default None)
- Returns:
performance_dict
- Return type:
dictionary
- static read_target_ch(feature_arr: DataFrame, label_name: str, binarize: bool = True, binarize_th: float = 0.3) ndarray [source]#
_summary_
- run_ML_model(feature_file: str | None = None, estimate_gridpoints: bool = False, estimate_channels: bool = True, estimate_all_channels_combined: bool = False, output_name: str = 'LM', save_results: bool = True)[source]#
machine learning model evaluation for ECoG strip channels and/or grid points
- Parameters:
feature_file (string, optional)
estimate_gridpoints (bool, optional) – run ML analysis for grid points, by default True
estimate_channels (bool, optional) – run ML analysis for ECoG strip channel, by default True
estimate_all_channels_combined (bool, optional) – run ML analysis features of all channels concatenated, by default False
model (sklearn model, optional) – ML model, needs to obtain fit and predict functions, by default linear_model.LogisticRegression(class_weight=”balanced”)
eval_method (sklearn.metrics, optional) – evaluation performance metric, by default metrics.balanced_accuracy_score
cv_method (sklearn.model_selection, optional) – valdation strategy, by default model_selection.KFold(n_splits=3, shuffle=False)
output_name (str, optional) – saving name, by default “LM”
save_results (boolean) – if true, save model._coef trained coefficients