Skip to content

Instantly share code, notes, and snippets.

@misterhay
Last active July 11, 2022 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save misterhay/06f9893fb914904876e44a7868160821 to your computer and use it in GitHub Desktop.
Save misterhay/06f9893fb914904876e44a7868160821 to your computer and use it in GitHub Desktop.
A "Wisdom of the Crowd" Callysto
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![Callysto.ca Banner](https://github.com/callysto/curriculum-notebooks/blob/master/callysto-notebook-banner-top.jpg?raw=true)\n",
"\n",
"<a href=\"https://hub.callysto.ca/jupyter/hub/user-redirect/git-pull?repo=https://gist.github.com/06f9893fb914904876e44a7868160821.git&branch=main&urlpath=notebooks/06f9893fb914904876e44a7868160821.git/wisdom-of-the-crowd.ipynb&depth=1\" target=\"_parent\"><img src=\"https://raw.githubusercontent.com/callysto/curriculum-notebooks/master/open-in-callysto-button.svg?sanitize=true\" width=\"123\" height=\"24\" alt=\"Open in Callysto\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Wisdom of the Crowd\n",
"\n",
"For this exercise, we'll take turns guessing the number of candies in the supplied container!\n",
"\n",
"Although any single guess is unlikely to get the number exactly right, when a large group of people take individual guesses the distribution of their guesses can get surprisingly close to the true answer! This is known as the \"Wisdom of the Crowd\".\n",
"\n",
"We'll try that here by allowing everyone in the class to enter their guess in the supplied spreadsheet and plot everyone's guesses:\n",
"\n",
"[Google Sheet](https://docs.google.com/spreadsheets/d/116_Eqh_urkADXFegJuIEvQRr6syQKo3K8hFfryGUDWA/edit?usp=sharing)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import plotly.graph_objects as go\n",
"\n",
"# Read from Google Sheet\n",
"spreadsheet_key = '116_Eqh_urkADXFegJuIEvQRr6syQKo3K8hFfryGUDWA'\n",
"spreadsheet_gid = '0'\n",
"csv_link = f'https://docs.google.com/spreadsheets/d/{spreadsheet_key}/export?gid={spreadsheet_gid}&format=csv'\n",
"guesses = pd.read_csv(csv_link)\n",
"guesses.rename(columns={'Enter your guesses below, please do not delete any other guesses!!!': 'Guesses'}, inplace=True)\n",
"\n",
"# Plot\n",
"layout = dict(\n",
" title = 'Distribution of Candy Guesses',\n",
" xaxis = dict(\n",
" title = 'Number of Candies'\n",
" ),\n",
" yaxis = dict(\n",
" title = 'Frequency'\n",
" )\n",
")\n",
"fig = go.Figure(data=[go.Histogram(x=guesses.iloc[:,0],\n",
" xbins=dict(size=50))],\n",
" layout=layout\n",
" )\n",
"\n",
"fig.show()\n",
"\n",
"print('Descriptive statistics:')\n",
"display(guesses.describe())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![Callysto.ca License](https://github.com/callysto/curriculum-notebooks/blob/master/callysto-notebook-banner-bottom.jpg?raw=true)](https://github.com/callysto/curriculum-notebooks/blob/master/LICENSE.md)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.1 64-bit",
"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.10.1"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "d1ca6d17674200220921376aaeb3d36cffe15ecab2470a9a5e7a456cdbf61425"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment