Created
January 22, 2012 03:26
-
-
Save npinto/1655329 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import numpy as np | |
from scikits.learn import linear_model | |
from dldata import hongmajaj # Hong & Majaj Neuronal Datasets module | |
# -- random number generator | |
rng = np.random.RandomState(42) | |
# -- dataset object | |
ds = hongmajaj.dataset.ITChaboTitoVar06wh(verify_sha1=True) | |
# -- get data | |
time_window = (70, 170) | |
print 'getting X' | |
xl = [ds.get_neurons(imgd, time_window) | |
for imgd in ds.meta | |
if 'blank' not in imgd['annotations']['labels']] | |
X = np.array(xl) | |
print 'getting y' | |
yl = [imgd['annotations']['pose']['ty'] # translation on the y axis | |
for imgd in ds.meta | |
if 'blank' not in imgd['annotations']['labels']] | |
y = np.array(yl) | |
# -- shuffle data | |
ridx = rng.permutation(len(y)) | |
X = X[ridx] | |
y = y[ridx] | |
# training split | |
X_trn = X[::2] | |
y_trn = y[::2] | |
# testing split | |
X_tst = X[1::2] | |
y_tst = y[1::2] | |
# -- training | |
print 'fit' | |
clf = linear_model.LassoCV() | |
clf.fit(X_trn, y_trn) | |
# -- testing | |
print 'predict' | |
y_gv = clf.predict(X_tst) | |
cc = np.corrcoef(y_gv, y_tst)[0, 1] | |
# -- plot | |
import pylab as pl | |
pl.scatter(y_tst, y_gv) | |
pl.xlabel('translation y (ground truth)') | |
pl.ylabel('translation y (predicted)') | |
pl.title('hongmajaj.ITChaboTitoVar06wh -- half/half -- Lasso Regression (CC=%0.2f)' % cc) | |
pl.savefig('nugget1.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment