Skip to content

Instantly share code, notes, and snippets.

@jaganadhg
Created October 9, 2013 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaganadhg/6899806 to your computer and use it in GitHub Desktop.
Save jaganadhg/6899806 to your computer and use it in GitHub Desktop.
Scipy Linier reg
{
"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