Skip to content

Instantly share code, notes, and snippets.

@malhotrachetan
Last active July 12, 2017 17:56
Show Gist options
  • Save malhotrachetan/7671faae2dac62fc8181a5af1e55fbf8 to your computer and use it in GitHub Desktop.
Save malhotrachetan/7671faae2dac62fc8181a5af1e55fbf8 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Descriptive and basic statistics terms/concepts explained with their python code.\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#imports\n",
"import numpy as np #the saviour\n",
"from statistics import mode\n",
"import matplotlib.pyplot as plt\n",
"from scipy import stats"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Our Distribution: [ 1 1 1 4 6 8 3 25 7 56 45 67 89 44 44 6 56 34 23 43 46 8 99 9 9\n",
" 9 9 0 3 4 4 4 4 4 5 12 13 14 15]\n",
"Number of scores: 39\n",
"Number of uniques scores: 24\n",
"Sum: 834\n",
"Maximum: 99\n",
"Minimum: 0\n",
"Range: 99\n",
"Mean: 21.3846153846\n",
"Median: 9.0\n",
"Mode: 4\n",
"Variance: 622.287968442\n",
"Standard Deviation: 24.9457003999\n",
"1st quartile: 4.0\n",
"3rd quartile: 38.5\n",
"Interquartile Range: 34.5\n",
"Distribution Skew: 1.5025542613555614\n"
]
}
],
"source": [
" distribution=[1,1,1,4,6,8,3,25,7,56,45,67,89,44,44,6,56,34,23,43,46,8,99,9,9,9,9,0,3,4,4,4,4,4,5,12,13,14,15] \n",
" dist=np.array(distribution)\n",
" \n",
" print(\"Our Distribution: \",dist)\n",
" print(\"Number of scores: \",len(dist))\n",
" print(\"Number of uniques scores: \",len(np.unique(dist)))\n",
" print(\"Sum: \",sum(dist))\n",
" print(\"Maximum: \",max(dist))\n",
" print(\"Minimum: \",min(dist))\n",
" print(\"Range: \",max(dist)-min(dist))\n",
" print(\"Mean: \",np.mean(dist, axis=0))\n",
" print(\"Median: \",np.median(dist, axis=0))\n",
" print(\"Mode: \",stats.mode(dist)[0][0]) #yes, numpy doesn't support mode functionality\n",
" print(\"Variance: \",np.var(dist, axis=0))\n",
" print(\"Standard Deviation: \",np.std(dist, axis=0))\n",
" print(\"1st quartile: \",np.percentile(dist, 25))\n",
" print(\"3rd quartile: \",np.percentile(dist, 75))\n",
" print(\"Interquartile Range: \",np.percentile(dist, 75)-np.percentile(dist, 25))\n",
" print(\"Distribution Skew: \",stats.skew(dist))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Plotting a Histogram of distribution scores\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAEICAYAAAB/Dx7IAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEzVJREFUeJzt3XmwZGV9xvHvIyC7KzeGbbxGEAUrSpwIUcogbuiAGksr\nKBgtNZPNBCwMwSUJroWJIWhcStwwooCFO5RG4xILF8wMEsKwBCJjhnVAHWFcEOSXP84Z0tzcvrdn\n5vbc+977/VR1TZ9z3j7n957u+/Tp95yeTlUhSWrHfea7AEnS5jG4JakxBrckNcbglqTGGNyS1BiD\nW5IaY3AvQEnWJDl8vuuYT0l+L8m6JBuTHDxC+68neUV//9gkX5rDWu55PpKckuSsOVz3a5N8YK7W\np6XB4N7GkqxN8tQp816a5MJN01V1UFV9fZb1TCapJNuPqdT59nbglVW1W1V9b3MeWFUfq6qnz9Yu\nyZlJ3jzC+mZ9PkaR5PAk101Z91ur6hVbu24tLQa3prUA3hAeCqyZzwIWwD5YsNw388vgXoAGj8qT\nPD7JqiS3Jbk5yWl9s2/0/27ohxN+J8l9krw+yQ+SrE/yz0nuP7DeP+iX/TDJX0/ZzilJzktyVpLb\ngJf22/52kg1J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cCRU+ZN28/+\nb/wY4KD+Me/pc2+LLIjgZgl9rb6qbqyqi/v7t9P9Ie9N19+P9M0+Ajx3fiocjyT7ACuADwzMXux9\nvj/wJOCDAFX1y6rawCLvN93Vajsn2R7YBbiBRdjnqvoG8KMps4f18znAOVV1R1VdC1xDl3tbZKEE\n997AuoHp6/p5i1qSSeBg4CLgIVV1Y7/oJuAh81TWuJwOnATcPTBvsff5YcAtwIf7IaIPJNmVRdzv\nqroeeDvwP8CNwE+q6kss4j5PMayfc5pxCyW4l5wkuwGfBE6oqtsGl1V3jeaiuU4zyVHA+qpaPazN\nYutzb3vgt4D3VtXBwE+ZMkSw2Prdj+k+h+5Nay9g1yTHDbZZbH0eZpz9XCjBvaS+Vp9kB7rQ/lhV\nfaqffXOSPfvlewLr56u+MXgi8Owka+mGwY5IchaLu8/QHVVdV1UX9dPn0QX5Yu73U4Frq+qWqroT\n+BTwBBZ3nwcN6+ecZtxCCe4l87X6JKEb87yiqk4bWPQ54CX9/ZcAn93WtY1LVb2mqvapqkm65/ar\nVXUci7jPAFV1E7AuyQH9rKcAl7O4+/0/wKFJdulf60+hO4+zmPs8aFg/Pwcck2THJA8D9ge+u8Vb\nqaoFcQOeBfwX8N/A6+a7njH28zC6j0+XApf0t2cBD6Y7C3018K/Ag+a71jH1/3Dg/P7+ou8z8Fhg\nVf98fwZ44GLvN/AG4ErgMuCjwI6Lsc/A2XTj+HfSfbp6+Uz9BF7X59tVwDO3Ztt+5V2SGrNQhkok\nSSMyuCWpMQa3JDXG4JakxhjcktQYg1uSGmNwS1Jj/hcstvJicnlISQAAAABJRU5ErkJggg==\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x1047264a8>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.hist(dist, bins=len(dist))\n",
"plt.yticks(np.arange(0, 6, 1.0))\n",
"plt.title('Histogram of distribution scores')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment