Skip to content

Instantly share code, notes, and snippets.

@VikParuchuri
Last active August 29, 2015 14:22
Show Gist options
  • Save VikParuchuri/1c53fe151939ec0d76d3 to your computer and use it in GitHub Desktop.
Save VikParuchuri/1c53fe151939ec0d76d3 to your computer and use it in GitHub Desktop.
Sample ipython notebook to test rescaling
Display the source blob
Display the rendered blob
Raw
{"cells": [{"metadata": {}, "source": "# Rescaling sample", "cell_type": "markdown"}, {"execution_count": 45, "metadata": {"trusted": true, "collapsed": false}, "outputs": [{"name": "stdout", "output_type": "stream", "text": "2.49008925792\n1.45241337087\n2.51447280486\n1.45712533955\n"}], "source": "import random\nfrom itertools import chain\nimport numpy as np\n\n# Set seed to ensure determinism\nrandom.seed(1)\n\n# Initialize a certain number of judges\njudge_count = 100\n\n# Generate scores randomly for each judge\nscores = []\nscore_count = 100\nfor i in range(judge_count):\n score = [random.uniform(0, 5) for z in range(score_count)]\n score = np.asarray(score)\n scores.append(score)\n\n# Combine the scores, and calculate overall mean and standard deviation\nflat_scores = list(chain.from_iterable(scores))\noverall_mean = np.mean(flat_scores)\nprint(overall_mean)\noverall_std = np.std(flat_scores)\nprint(overall_std)\n\n# New scores list initialized\nnew_scores = []\n\n# Rescale scores using formula\nfor i in range(judge_count):\n sd_scaled = scores[i]/(numpy.std(scores[i]) / overall_std)\n mean_scaled = sd_scaled - (numpy.mean(scores[i]) - overall_mean)\n new_scores.append(mean_scaled)\n\n# Generate a new flat score list\nnew_flat_scores = list(chain.from_iterable(new_scores))\n\n# Print the new mean/standard deviation\nprint(np.mean(new_flat_scores))\nprint(np.std(new_flat_scores))", "cell_type": "code"}, {"execution_count": null, "metadata": {"trusted": true, "collapsed": true}, "outputs": [], "source": "", "cell_type": "code"}], "nbformat": 4, "nbformat_minor": 0, "metadata": {"kernelspec": {"display_name": "Python 3", "name": "python3", "language": "python"}, "language_info": {"mimetype": "text/x-python", "file_extension": ".py", "codemirror_mode": {"name": "ipython", "version": 3}, "name": "python", "pygments_lexer": "ipython3", "version": "3.4.2", "nbconvert_exporter": "python"}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment