Created
October 9, 2013 11:30
-
-
Save jaganadhg/6899806 to your computer and use it in GitHub Desktop.
Scipy Linier reg
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
{ | |
"metadata": { | |
"name": "Scipy_linier_regression" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "from scipy import stats\nimport numpy as np\nimport pylab\n\n# Fit the model\nx = np.array([1, 2, 5, 7, 10, 15])\ny = np.array([2, 6, 7, 9, 14, 19])\nslope, intercept, r_value, p_value, slope_std_error = stats.linregress(x, y)\n\n# Calculate some additional outputs\npredict_y = intercept + slope * x\npred_error = y - predict_y\ndegrees_of_freedom = len(x) - 2\nresidual_std_error = np.sqrt(np.sum(pred_error**2) / degrees_of_freedom)\n\n# Plotting\npylab.plot(x, y, 'o')\npylab.plot(x, predict_y, 'k-')\npylab.show()", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"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