Skip to content

Instantly share code, notes, and snippets.

View agramfort's full-sized avatar

Alexandre Gramfort agramfort

View GitHub Profile
from scipy import stats
class GaussianKernelDensityEstimation(object):
"""docstring for GaussianKernelDensityEstimation"""
def __init__(self):
self.gkde = None
def fit(self, X):
"""docstring for fit"""
self.gkde = stats.gaussian_kde(X.T)
"""
==========================
Feature Selection Shootout
==========================
Illustration of feature selection with :
- RFE-SVC
- Anova-SVC
- L1-Logistic Regression
"""
"""
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
@agramfort
agramfort / lowess.py
Last active August 16, 2023 06:19
LOWESS : Locally weighted regression
"""
This module implements the Lowess function for nonparametric regression.
Functions:
lowess Fit a smooth nonparametric regression curve to a scatterplot.
For more information, see
William S. Cleveland: "Robust locally weighted regression and smoothing
scatterplots", Journal of the American Statistical Association, December 1979,
@agramfort
agramfort / time_freq_demo.py
Created May 5, 2011 22:04
time freq demo with morlet wavelets
"""A module which implements the continuous wavelet transform
with complex Morlet wavelets.
Author : Alexandre Gramfort, gramfort@nmr.mgh.harvard.edu (2011)
License : BSD 3-clause
inspired by Matlab code from Sheraz Khan & Brainstorm & SPM
"""
from math import sqrt
@agramfort
agramfort / test_linear_svc.py
Created May 22, 2011 12:53
test LinearSVC variance pb
from pprint import pprint
import numpy as np
from scipy import sparse
from scikits.learn.grid_search import GridSearchCV
from scikits.learn.cross_val import StratifiedKFold
from scikits.learn.metrics import f1_score, classification_report
from scikits.learn import svm
from scikits.learn.linear_model import LogisticRegression
from scikits.learn.linear_model.sparse import LogisticRegression as SparseLogisticRegression
@agramfort
agramfort / gist:1108519
Created July 27, 2011 02:07
Testing the difference between two coefficients of correlation
"""Testing the difference between two coefficients of correlation
Following:
Thöni, H. (1977), Testing the Difference Between two Coefficients of Correlation.
Biometrical Journal, 19: 355–359. doi: 10.1002/bimj.4710190506
http://onlinelibrary.wiley.com/doi/10.1002/bimj.4710190506/abstract
"""
from math import log, sqrt
@agramfort
agramfort / om_viz.py
Created September 23, 2011 13:18
OpenMEEG data basic viewer based on Python and Mayavi2
#!/usr/bin/env python
"""
Simple viewer for tri mesh files and OpenMEEG geometry files
Usage
-----
om_viz.py model.geom mesh1.tri mesh2.tri dipoles.txt
@agramfort
agramfort / gist:1357024
Created November 11, 2011 02:41
parameter scaling by n_samples pb
import numpy as np
from scipy import linalg
from sklearn import datasets, svm, linear_model
from sklearn.svm import l1_min_c
iris = datasets.load_iris()
X = iris.data
y = iris.target
@agramfort
agramfort / gist:1501065
Created December 20, 2011 10:19
scikit hierarchical refactoring pseudo code
Dendogram = namedtuple('Dendogram', ['children', 'n_leaves', 'n_components'])
def hierarchical_tree(X, linkage_criterion='ward', connectivity=None, n_components=None, copy=True):
...
for ...:
if linkage_criterion == 'ward':