Skip to content

Instantly share code, notes, and snippets.

@deepanshululla
Created February 13, 2019 02:06
Show Gist options
  • Save deepanshululla/38acbda61eea8f053a8789d998ac7adc to your computer and use it in GitHub Desktop.
Save deepanshululla/38acbda61eea8f053a8789d998ac7adc to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy\n",
"from pandas import read_csv\n",
"from sklearn.utils import resample\n",
"from sklearn.metrics import accuracy_score\n",
"from matplotlib import pyplot\n",
"\n",
"# load dataset\n",
"x = numpy.array([180,162,158,172,168,150,171,183,165,176])\n",
"\n",
"# configure bootstrap\n",
"n_iterations = 1000\n",
"n_size = int(len(x))\n",
"\n",
"# run bootstrap\n",
"medians = list()\n",
"for i in range(n_iterations):\n",
" # prepare train and test sets\n",
" s = resample(x, n_samples=n_size);\n",
" m = numpy.median(s);\n",
" #print(m)\n",
" medians.append(m)\n",
"\n",
"# plot scores\n",
"pyplot.hist(medians)\n",
"pyplot.show()\n",
"\n",
"# confidence intervals\n",
"alpha = 0.95\n",
"p = ((1.0-alpha)/2.0) * 100\n",
"lower = numpy.percentile(medians, p)\n",
"\n",
"p = (alpha+((1.0-alpha)/2.0)) * 100\n",
"upper = numpy.percentile(medians, p)\n",
"print('%.1f confidence interval %.1f and %.1f' % (alpha*100, lower, upper))\n",
"\n"
]
}
],
"metadata": {
"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.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment