Created
September 17, 2012 16:02
-
-
Save tdhopper/3738197 to your computer and use it in GitHub Desktop.
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": "Regression bugs" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "mat = array([[ 1.,0.99975145,0.92051498,0.9950906, 0.99815419],\n [ 0.92051498,0.91197251,1.,0.9537393, 0.89636339],\n [ 0.9950906, 0.99264496,0.9537393, 1.,0.9872818 ],\n [ 0.99286679,0.98997523,0.95955895,0.99979104,0.983852],\n [ 0.9840137, 0.98771506,0.84197501,0.96189652,0.99297485],\n [ 0.99815419,0.99925955,0.89636339,0.9872818, 1.],\n [ 0.85914332,0.84844105,0.98967977,0.90296462,0.82930882],\n [ 0.99679373,0.99832835,0.8881177, 0.98404465,0.99981269],\n [ 0.99975145,1.,0.91197251,0.99264496,0.99925955],\n [ 0.99482616,0.99232267,0.95451232,0.99999651,0.98686083]])\ntargets = [[ 0.04081166], [-0.95944469], [ 0.33605717], [ 0.85007786], [ 0.75169075], [-0.83124147], [-0.70947397], [ 0.32914427], [-0.99924773], [-0.9320851 ]]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "from scipy.linalg import pinv, lstsq\nfrom sklearn import linear_model\nwPinv = dot(pinv(mat), targets)\nwNumpy = lstsq(mat, targets)[0]\nclf = linear_model.LinearRegression()\nwSklearn = clf.fit(mat, targets).coef_\nprint wPinv\nprint wNumpy\nprint wSklearn.T", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "[[ 58053202.46203362]\n [-71366378.49680269]\n [ 124225.57851716]\n [ -5251958.64517807]\n [ 18441299.69284547]]\n[[ 58053202.4620336 ]\n [-71366378.49680264]\n [ 124225.57851716]\n [ -5251958.64517807]\n [ 18441299.69284546]]\n[[ -9.16268497e+07]\n [ 1.12356411e+08]\n [ -2.27788482e+05]\n [ 8.44236867e+06]\n [ -2.89493001e+07]]\n" | |
} | |
], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment