Skip to content

Instantly share code, notes, and snippets.

View agramfort's full-sized avatar

Alexandre Gramfort agramfort

View GitHub Profile
@agramfort
agramfort / miss_val_bench.py
Created February 8, 2016 15:56 — forked from raghavrv/.gitignore
RF Missing Value Benchmark script
import numpy as np
from sklearn.datasets import fetch_covtype
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import StratifiedShuffleSplit
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import Imputer
from sklearn.model_selection import cross_val_score
rng = np.random.RandomState(0)
#%% import ####################################################################
import mne
import numpy as np
import os
from mne.datasets import sample
data_path = sample.data_path()
#%% load group avg data #######################################################
os.environ["SUBJECTS_DIR"] = data_path + '/subjects'
import numpy as np
from scipy import linalg
from sklearn import linear_model
def _gcv(X, y, alphas, fit_intercept):
"""Local gcv"""
# singular values of the design matrix
n1, p = X.shape
_, s, _ = linalg.svd(X, 0)
clf = linear_model.Ridge(fit_intercept=fit_intercept)
@agramfort
agramfort / gist:3181189
Created July 26, 2012 09:24 — forked from fabianp/gist:3097107
strong rules lasso
# -*- coding: utf-8 -*-
"""
Generalized linear models via coordinate descent
Author: Fabian Pedregosa <fabian@fseoane.net>
"""
import numpy as np
MAX_ITER = 100
@agramfort
agramfort / cd_fast2.py
Created June 23, 2012 20:38 — forked from ibayer/cd_fast2.py
test pure glmnet cd python implementation against cd_fast.enet_coordinate_descent
import numpy as np
def fsign( f):
if f == 0:
return 0
elif f > 0:
return 1.0
else:
return -1.0
@agramfort
agramfort / scale_c_ridge.py
Created May 2, 2012 17:26 — forked from jaquesgrobler/scale_c_ridge.py
Ridge regression scaled
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
=========================================================
Title
=========================================================
Description
"""
@agramfort
agramfort / ranking.py
Created March 18, 2012 13:10 — forked from fabianp/ranking.py
Pairwise ranking using scikit-learn LinearSVC
"""
Implementation of pairwise ranking using scikit-learn LinearSVC
Reference: "Large Margin Rank Boundaries for Ordinal Regression", R. Herbrich,
T. Graepel, K. Obermayer.
Authors: Fabian Pedregosa <fabian@fseoane.net>
Alexandre Gramfort <alexandre.gramfort@inria.fr>
"""
"""
Author: Oliver Mitevski
References:
A Generalized Linear Model for Principal Component Analysis of Binary Data,
Andrew I. Schein; Lawrence K. Saul; Lyle H. Ungar
The code was translated and adapted from Jakob Verbeek's
"Hidden Markov models and mixtures for Binary PCA" implementation in MATLAB