Skip to content

Instantly share code, notes, and snippets.

View kingjr's full-sized avatar

Jean-Rémi KING kingjr

View GitHub Profile
import numpy as np
import mne
from mne.decoding import GeneralizationAcrossTime as GAT
from sklearn.metrics import roc_auc_score
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.pipeline import make_pipeline
from sklearn.cross_validation import StratifiedKFold
from meeg_preprocessing.utils import setup_provenance
import numpy as np
from sklearn.svm import LinearSVR
class SVR_angle(LinearSVR):
def __init__(self):
from sklearn.svm import LinearSVR
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
@kingjr
kingjr / gist:74d3966013ce44114771
Created July 21, 2015 17:24
pipeline_clement.py
import numpy as np
import os.path as op
import matplotlib.pyplot as plt
import mne
from mne.decoding import GeneralizationAcrossTime
from mne.report import Report
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
# from sklearn.metrics import r2_score
@kingjr
kingjr / for_jona.py
Created July 29, 2015 14:11
quick probabilistic LogisticRegression clf
def scorer_auc(y_true, y_pred):
from sklearn.metrics import roc_auc_score
from sklearn.preprocessing import LabelBinarizer
"""Dedicated to 2class probabilistic outputs"""
le = LabelBinarizer()
y_true = le.fit_transform(y_true)
return roc_auc_score(y_true, y_pred)
import pickle
import numpy as np
from base import subjects, paths
from mne.stats import permutation_cluster_1samp_test
# load scores
all_scores = list()
for subject in subjects:
print subject
with open(paths('scores', subject=subject), 'rb') as f:
scores = pickle.load(f)
@kingjr
kingjr / _dynamics.py
Created September 27, 2015 21:05
sparse fit dynamics jc
import numpy as np
import matplotlib.pyplot as plt
import itertools
import seaborn as sns
from base import paths
from sklearn.linear_model import LassoCV
import pickle
# load data
fname = paths('stats', subject='fsaverage', analysis='all')
@kingjr
kingjr / colored_butterfly.py
Created October 16, 2015 13:54
colored_butterfly.py
import numpy as np
import matplotlib.pyplot as plt
import mne
from mne.channels.layout import find_layout
from mne.datasets import sample
from mpl_toolkits.mplot3d import Axes3D
data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
events_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
@kingjr
kingjr / mask_subtraction.py
Created October 21, 2015 20:19
mask subtraction for gabriela
import numpy as np
def simulate_data():
"""Simulate data"""
from mne import create_info, EpochsArray
n_trial, n_chan, n_time = 100, 64, 200
soas = np.array([17, 33, 50, 67, 83])
event_soa = soas[np.random.randint(0, len(soas), n_trial)]
event_present = np.random.randint(0, 2, n_trial)
@kingjr
kingjr / test_tspca.py
Last active November 28, 2015 00:18
Failed Attempt to use Time Shift PCA
# Author: Jean-Remi King
#
# Licence: BSD 3-clause
"""
This is a failed attempt to use a python implementation of Time Shift
PCA (https://github.com/pealco/python-meg-denoise) that aims as
denoising external MEG sources from the signals when we have reference
sensors available (e.g. in the KIT).
See http://audition.ens.fr/adc/NoiseTools/ for more info on TSPCA
@kingjr
kingjr / test_tspca.m
Created November 28, 2015 00:18
Simplification of of bunch of in-lab scripts to apply Time Shift PCA on MEG KIT data
% Author: Jean-Remi King <jeanremi.king@gmail.com>
%
% Licence : To-be-determined
addpath('/media/DATA/Pro/Toolbox/NoiseTools/') % http://audition.ens.fr/adc/NoiseTools/
demean = @(x) x - repmat(mean(x, 1), [size(x, 1), 1]);
%% Read data, prepare info
raw = load('raw.mat');
data_empty = transpose(raw.empty(1:160, :)); % empty room: chan x time