Created
October 28, 2012 18:16
-
-
Save fabianp/3969347 to your computer and use it in GitHub Desktop.
lars ill conditioned
This file contains hidden or 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
{ | |
"metadata": { | |
"name": "Untitled0" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from sklearn import linear_model\n", | |
"import numpy as np\n", | |
"from scipy import linalg" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"X, y = [[10, 10, 0], [1e-32, 0, 0], [0, 0, 1]], [5, 0, 5]\n", | |
"for model in (linear_model.LassoLars(.1), linear_model.Lasso(.1)):\n", | |
" coef_ = model.fit(X, y).coef_\n", | |
" pobj = (1./ (2. * 3.)) * linalg.norm(y - np.dot(X, coef_)) ** 2 + .1 * linalg.norm(coef_, 1)\n", | |
" #print coef_\n", | |
" print('Objective function given by %s: %s' % (model.__class__.__name__, pobj))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"Objective function given by LassoLars: 8.33333333333\n", | |
"Objective function given by Lasso: 0.571155501407\n" | |
] | |
} | |
], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# fitted by R Lars\n", | |
"# > X <- array(c(10, 10, 0, 1e-32, 0, 0, 0, 0, 1), dim=c(3, 3)) \n", | |
"# > y <- c(5, 0, 5)\n", | |
"# > lars(X, y)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment