├── .ipynb_checkpoints ├── Untitled-checkpoint.ipynb ├── evolved-forest-demo-checkpoint.ipynb ├── evolved-forest-demo-implicit-fitness-checkpoint.ipynb ├── evolved-forest-demo-implicit-fitness-multi-oob-checkpoint.ipynb ├── evolved-forest-demo-original-checkpoint.ipynb ├── evolved-forest-demo-scaled-checkpoint.ipynb ├── evolved-forest-demo-variance-implicit-fitness-pressure-checkpoint.ipynb ├── evolved-forest-demo-variance-lexicase-checkpoint.ipynb ├── evolved-forest-demo-variance-only-checkpoint.ipynb ├── evolved-forest-demo-variance-only-objective-checkpoint.ipynb ├── evolved-forest-demo-variance-only-olson-Copy2-checkpoint.ipynb ├── evolved-forest-demo-variance-only-olson-checkpoint.ipynb └── evolved-forest-demo-variance-only-olson-multi-oob-checkpoint.ipynb ├── README.md ├── datasets ├── GAMETES-easy-4x2-way_her-0.4_pop-1600_attribs-100_discrete.csv └── spambase.csv ├── papers └── Lexicase Selection.pdf ├── subsampling ├── .ipynb_checkpoints │ ├── Difficulty Level of Rows - Approach - Results-checkpoint.ipynb │ ├── evolved-forest-demo-checkpoint.ipynb │ ├── evolved-forest-demo-variance-only-objective-checkpoint.ipynb │ ├── evolved-forest-implicit-fitness-multi-oob-checkpoint.ipynb │ ├── evolved-forest-multi-obj-variance-oob-score-checkpoint.ipynb │ ├── evolved-forest-oob-variance-only-checkpoint.ipynb │ ├── evolved-forest-single-obj-implicit-fitness-pressure-checkpoint.ipynb │ ├── evolved-forest-single-obj-true-variance-checkpoint.ipynb │ └── evolved-forest-variance-lexicase-checkpoint.ipynb ├── Difficulty Level of Rows - Approach - Results.ipynb ├── dump │ ├── evolved-forest-demo-variance-only-objective.ipynb │ ├── evolved-forest-demo-variance-only-olson-Copy2.ipynb │ ├── evolved-forest-demo-variance-only.ipynb │ └── evolved-forest-demo.ipynb ├── evolved-forest - Update levels after each row's evaluation-Multi-objectives.ipynb ├── evolved-forest-implicit-fitness-multi-oob.ipynb ├── evolved-forest-multi-obj-variance-oob-score.ipynb ├── evolved-forest-oob-variance-only.ipynb ├── evolved-forest-single-obj-implicit-fitness-pressure.ipynb ├── evolved-forest-single-obj-true-variance.ipynb └── evolved-forest-variance-lexicase.ipynb └── subspacing ├── .ipynb_checkpoints └── evolved-forest-demo-variance-only-subspacing-checkpoint.ipynb ├── dataset_describe.py ├── dataset_describe.pyc └── evolved-forest-demo-variance-only-subspacing.ipynb /.ipynb_checkpoints/Untitled-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 0 6 | } 7 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/evolved-forest-demo-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "import operator\n", 12 | "import itertools\n", 13 | "import numpy as np\n", 14 | "\n", 15 | "from deap import algorithms\n", 16 | "from deap import base\n", 17 | "from deap import creator\n", 18 | "from deap import tools\n", 19 | "from deap import gp\n", 20 | "\n", 21 | "from sklearn.tree import DecisionTreeClassifier\n", 22 | "from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier\n", 23 | "from sklearn.datasets import load_digits\n", 24 | "from sklearn.cross_validation import train_test_split\n", 25 | "\n", 26 | "np.seterr(all='raise')\n", 27 | "\n", 28 | "digits = load_digits()\n", 29 | "digit_features, digit_labels = digits.data, digits.target\n", 30 | "X_train, X_test, y_train, y_test = train_test_split(digit_features, digit_labels, stratify=digit_labels,\n", 31 | " train_size=0.75, test_size=0.25)\n", 32 | "\n", 33 | "# defined a new primitive set for strongly typed GP\n", 34 | "pset = gp.PrimitiveSetTyped('MAIN', itertools.repeat(float, digit_features.shape[1]), bool, 'Feature')\n", 35 | "\n", 36 | "# boolean operators\n", 37 | "pset.addPrimitive(operator.and_, [bool, bool], bool)\n", 38 | "pset.addPrimitive(operator.or_, [bool, bool], bool)\n", 39 | "pset.addPrimitive(operator.not_, [bool], bool)\n", 40 | "\n", 41 | "# floating point operators\n", 42 | "# Define a protected division function\n", 43 | "def protectedDiv(left, right):\n", 44 | " try: return left / right\n", 45 | " except (ZeroDivisionError, FloatingPointError): return 1.\n", 46 | "\n", 47 | "pset.addPrimitive(operator.add, [float, float], float)\n", 48 | "pset.addPrimitive(operator.sub, [float, float], float)\n", 49 | "pset.addPrimitive(operator.mul, [float, float], float)\n", 50 | "pset.addPrimitive(protectedDiv, [float, float], float)\n", 51 | "\n", 52 | "# logic operators\n", 53 | "# Define a new if-then-else function\n", 54 | "def if_then_else(in1, output1, output2):\n", 55 | " if in1: return output1\n", 56 | " else: return output2\n", 57 | "\n", 58 | "pset.addPrimitive(operator.lt, [float, float], bool)\n", 59 | "pset.addPrimitive(operator.eq, [float, float], bool)\n", 60 | "pset.addPrimitive(if_then_else, [bool, float, float], float)\n", 61 | "\n", 62 | "# terminals\n", 63 | "pset.addTerminal(False, bool)\n", 64 | "pset.addTerminal(True, bool)\n", 65 | "for val in np.arange(-10., 11.):\n", 66 | " pset.addTerminal(val, float)\n", 67 | "\n", 68 | "creator.create('FitnessMax', base.Fitness, weights=(1.0,))\n", 69 | "creator.create('Individual', gp.PrimitiveTree, fitness=creator.FitnessMax)\n", 70 | "\n", 71 | "toolbox = base.Toolbox()\n", 72 | "toolbox.register('expr', gp.genHalfAndHalf, pset=pset, min_=1, max_=3)\n", 73 | "toolbox.register('individual', tools.initIterate, creator.Individual, toolbox.expr)\n", 74 | "toolbox.register('population', tools.initRepeat, list, toolbox.individual)\n", 75 | "toolbox.register('compile', gp.compile, pset=pset)\n", 76 | "\n", 77 | "def evaluate_individual(individual):\n", 78 | " # Transform the tree expression into a callable function\n", 79 | " func = toolbox.compile(expr=individual)\n", 80 | " subsample = np.array([func(*record) for record in X_train])\n", 81 | " \n", 82 | " if X_train[subsample].shape[0] == 0:\n", 83 | " return 1e-20,\n", 84 | " \n", 85 | " clf = DecisionTreeClassifier(random_state=34092)\n", 86 | " clf.fit(X_train[subsample], y_train[subsample])\n", 87 | " score = clf.score(X_test, y_test)\n", 88 | " \n", 89 | " return score,\n", 90 | " \n", 91 | "toolbox.register('evaluate', evaluate_individual)\n", 92 | "toolbox.register('select', tools.selTournament, tournsize=3)\n", 93 | "toolbox.register('mate', gp.cxOnePoint)\n", 94 | "toolbox.register('expr_mut', gp.genFull, min_=0, max_=3)\n", 95 | "toolbox.register('mutate', gp.mutUniform, expr=toolbox.expr_mut, pset=pset)\n", 96 | "\n", 97 | "population = toolbox.population(n=100)\n", 98 | "halloffame = tools.HallOfFame(1)\n", 99 | "stats = tools.Statistics(lambda ind: ind.fitness.values)\n", 100 | "stats.register('std', np.std)\n", 101 | "stats.register('min', np.min)\n", 102 | "stats.register('avg', np.mean)\n", 103 | "stats.register('max', np.max)\n", 104 | "\n", 105 | "clf = DecisionTreeClassifier(random_state=34092)\n", 106 | "clf.fit(X_train, y_train)\n", 107 | "print('Base DecisionTreeClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 108 | "\n", 109 | "clf = RandomForestClassifier(random_state=34092)\n", 110 | "clf.fit(X_train, y_train)\n", 111 | "print('Base RandomForestClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 112 | "\n", 113 | "clf = GradientBoostingClassifier(random_state=34092)\n", 114 | "clf.fit(X_train, y_train)\n", 115 | "print('Base GradientBoostingClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 116 | "\n", 117 | "print('')\n", 118 | "\n", 119 | "cxpb = 0.5\n", 120 | "mutpb = 0.5\n", 121 | "ngen = 50\n", 122 | "verbose = True\n", 123 | "\n", 124 | "logbook = tools.Logbook()\n", 125 | "logbook.header = ['gen', 'nevals'] + (stats.fields if stats else [])\n", 126 | "\n", 127 | "# Evaluate the individuals with an invalid fitness\n", 128 | "invalid_ind = [ind for ind in population if not ind.fitness.valid]\n", 129 | "fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)\n", 130 | "for ind, fit in zip(invalid_ind, fitnesses):\n", 131 | " ind.fitness.values = fit\n", 132 | "\n", 133 | "if halloffame is not None:\n", 134 | " halloffame.update(population)\n", 135 | "\n", 136 | "record = stats.compile(population) if stats else {}\n", 137 | "logbook.record(gen=0, nevals=len(invalid_ind), **record)\n", 138 | "if verbose:\n", 139 | " print(logbook.stream)\n", 140 | "\n", 141 | "# Begin the generational process\n", 142 | "for gen in range(1, ngen + 1):\n", 143 | " # Select the next generation individuals\n", 144 | " offspring = toolbox.select(population, len(population))\n", 145 | "\n", 146 | " # Vary the pool of individuals\n", 147 | " offspring = algorithms.varAnd(offspring, toolbox, cxpb, mutpb)\n", 148 | "\n", 149 | " # Evaluate the individuals with an invalid fitness\n", 150 | " invalid_ind = [ind for ind in offspring if not ind.fitness.valid]\n", 151 | " fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)\n", 152 | " for ind, fit in zip(invalid_ind, fitnesses):\n", 153 | " ind.fitness.values = fit\n", 154 | "\n", 155 | " # Update the hall of fame with the generated individuals\n", 156 | " if halloffame is not None:\n", 157 | " halloffame.update(offspring)\n", 158 | "\n", 159 | " # Replace the current population by the offspring\n", 160 | " population[:] = offspring\n", 161 | "\n", 162 | " # Append the current generation statistics to the logbook\n", 163 | " record = stats.compile(population) if stats else {}\n", 164 | " logbook.record(gen=gen, nevals=len(invalid_ind), **record)\n", 165 | " if verbose:\n", 166 | " print(logbook.stream)\n", 167 | "\n", 168 | "str(halloffame[0])" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": null, 174 | "metadata": { 175 | "collapsed": false 176 | }, 177 | "outputs": [], 178 | "source": [ 179 | "forest_predictions = []\n", 180 | "\n", 181 | "for ind_num, individual in enumerate(pop):\n", 182 | " func = toolbox.compile(expr=individual)\n", 183 | " subsample = np.array([func(*record) for record in X_train])\n", 184 | " \n", 185 | " if X_train[subsample].shape[0] == 0:\n", 186 | " continue\n", 187 | " \n", 188 | " clf = DecisionTreeClassifier(random_state=34092)\n", 189 | " clf.fit(X_train[subsample], y_train[subsample])\n", 190 | " predictions = clf.predict(X_test)\n", 191 | " forest_predictions.append(predictions)" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": null, 197 | "metadata": { 198 | "collapsed": false, 199 | "scrolled": false 200 | }, 201 | "outputs": [], 202 | "source": [ 203 | "from collections import Counter\n", 204 | "from sklearn.metrics import accuracy_score\n", 205 | "\n", 206 | "y_pred = np.array(\n", 207 | " [Counter(instance_forest_predictions).most_common(1)[0][0] for instance_forest_predictions in zip(*forest_predictions)])\n", 208 | "np.sum(y_test == y_pred) / len(y_test)" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": null, 214 | "metadata": { 215 | "collapsed": true 216 | }, 217 | "outputs": [], 218 | "source": [] 219 | } 220 | ], 221 | "metadata": { 222 | "kernelspec": { 223 | "display_name": "Python 3", 224 | "language": "python", 225 | "name": "python3" 226 | }, 227 | "language_info": { 228 | "codemirror_mode": { 229 | "name": "ipython", 230 | "version": 3 231 | }, 232 | "file_extension": ".py", 233 | "mimetype": "text/x-python", 234 | "name": "python", 235 | "nbconvert_exporter": "python", 236 | "pygments_lexer": "ipython3", 237 | "version": "3.5.1" 238 | } 239 | }, 240 | "nbformat": 4, 241 | "nbformat_minor": 0 242 | } 243 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/evolved-forest-demo-original-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "name": "stdout", 12 | "output_type": "stream", 13 | "text": [ 14 | "Base DecisionTreeClassifier accuracy: 0.869179600887\n", 15 | "Base RandomForestClassifier accuracy: 0.946784922395\n", 16 | "Base GradientBoostingClassifier accuracy: 0.953436807095\n", 17 | "\n", 18 | "gen\tnevals\tstd \tmin \tavg \tmax \n", 19 | "0 \t100 \t0.379036\t1e-20\t0.394612\t0.875831\n", 20 | "1 \t85 \t0.337387\t1e-20\t0.584945\t0.878049\n", 21 | "2 \t76 \t0.300443\t1e-20\t0.709135\t0.873614\n", 22 | "3 \t73 \t0.311377\t1e-20\t0.707761\t0.873614\n", 23 | "4 \t75 \t0.251842\t1e-20\t0.774656\t0.875831\n", 24 | "5 \t73 \t0.268957\t1e-20\t0.754745\t0.880266\n", 25 | "6 \t71 \t0.21039 \t1e-20\t0.80051 \t0.882483\n", 26 | "7 \t78 \t0.209782\t1e-20\t0.811175\t0.882483\n", 27 | "8 \t77 \t0.125856\t1e-20\t0.852106\t0.891353\n", 28 | "9 \t71 \t0.132058\t1e-20\t0.843259\t0.891353\n", 29 | "10 \t76 \t0.0994663\t1e-20\t0.855277\t0.891353" 30 | ] 31 | } 32 | ], 33 | "source": [ 34 | "import operator\n", 35 | "import itertools\n", 36 | "import numpy as np\n", 37 | "\n", 38 | "from deap import algorithms\n", 39 | "from deap import base\n", 40 | "from deap import creator\n", 41 | "from deap import tools\n", 42 | "from deap import gp\n", 43 | "\n", 44 | "from sklearn.tree import DecisionTreeClassifier\n", 45 | "from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier\n", 46 | "from sklearn.datasets import load_digits\n", 47 | "from sklearn.cross_validation import train_test_split\n", 48 | "\n", 49 | "np.seterr(all='raise')\n", 50 | "\n", 51 | "digits = load_digits()\n", 52 | "digit_features, digit_labels = digits.data, digits.target\n", 53 | "X_train, X_test, y_train, y_test = train_test_split(digit_features, digit_labels, stratify=digit_labels,\n", 54 | " train_size=0.75, test_size=0.25)\n", 55 | "\n", 56 | "# defined a new primitive set for strongly typed GP\n", 57 | "pset = gp.PrimitiveSetTyped('MAIN', itertools.repeat(float, digit_features.shape[1]), bool, 'Feature')\n", 58 | "\n", 59 | "# boolean operators\n", 60 | "pset.addPrimitive(operator.and_, [bool, bool], bool)\n", 61 | "pset.addPrimitive(operator.or_, [bool, bool], bool)\n", 62 | "pset.addPrimitive(operator.not_, [bool], bool)\n", 63 | "\n", 64 | "# floating point operators\n", 65 | "# Define a protected division function\n", 66 | "def protectedDiv(left, right):\n", 67 | " try: return left / right\n", 68 | " except (ZeroDivisionError, FloatingPointError): return 1.\n", 69 | "\n", 70 | "pset.addPrimitive(operator.add, [float, float], float)\n", 71 | "pset.addPrimitive(operator.sub, [float, float], float)\n", 72 | "pset.addPrimitive(operator.mul, [float, float], float)\n", 73 | "pset.addPrimitive(protectedDiv, [float, float], float)\n", 74 | "\n", 75 | "# logic operators\n", 76 | "# Define a new if-then-else function\n", 77 | "def if_then_else(in1, output1, output2):\n", 78 | " if in1: return output1\n", 79 | " else: return output2\n", 80 | "\n", 81 | "pset.addPrimitive(operator.lt, [float, float], bool)\n", 82 | "pset.addPrimitive(operator.eq, [float, float], bool)\n", 83 | "pset.addPrimitive(if_then_else, [bool, float, float], float)\n", 84 | "\n", 85 | "# terminals\n", 86 | "pset.addTerminal(False, bool)\n", 87 | "pset.addTerminal(True, bool)\n", 88 | "for val in np.arange(-10., 11.):\n", 89 | " pset.addTerminal(val, float)\n", 90 | "\n", 91 | "creator.create('FitnessMax', base.Fitness, weights=(1.0,))\n", 92 | "creator.create('Individual', gp.PrimitiveTree, fitness=creator.FitnessMax)\n", 93 | "\n", 94 | "toolbox = base.Toolbox()\n", 95 | "toolbox.register('expr', gp.genHalfAndHalf, pset=pset, min_=1, max_=3)\n", 96 | "toolbox.register('individual', tools.initIterate, creator.Individual, toolbox.expr)\n", 97 | "toolbox.register('population', tools.initRepeat, list, toolbox.individual)\n", 98 | "toolbox.register('compile', gp.compile, pset=pset)\n", 99 | "\n", 100 | "def evaluate_individual(individual):\n", 101 | " # Transform the tree expression into a callable function\n", 102 | " func = toolbox.compile(expr=individual)\n", 103 | " subsample = np.array([func(*record) for record in X_train])\n", 104 | " \n", 105 | " if X_train[subsample].shape[0] == 0:\n", 106 | " return 1e-20,\n", 107 | " \n", 108 | " clf = DecisionTreeClassifier(random_state=34092)\n", 109 | " clf.fit(X_train[subsample], y_train[subsample])\n", 110 | " score = clf.score(X_test, y_test)\n", 111 | " \n", 112 | " return score,\n", 113 | " \n", 114 | "toolbox.register('evaluate', evaluate_individual)\n", 115 | "toolbox.register('select', tools.selTournament, tournsize=3)\n", 116 | "toolbox.register('mate', gp.cxOnePoint)\n", 117 | "toolbox.register('expr_mut', gp.genFull, min_=0, max_=3)\n", 118 | "toolbox.register('mutate', gp.mutUniform, expr=toolbox.expr_mut, pset=pset)\n", 119 | "\n", 120 | "population = toolbox.population(n=100)\n", 121 | "halloffame = tools.HallOfFame(1)\n", 122 | "stats = tools.Statistics(lambda ind: ind.fitness.values)\n", 123 | "stats.register('std', np.std)\n", 124 | "stats.register('min', np.min)\n", 125 | "stats.register('avg', np.mean)\n", 126 | "stats.register('max', np.max)\n", 127 | "\n", 128 | "clf = DecisionTreeClassifier(random_state=34092)\n", 129 | "clf.fit(X_train, y_train)\n", 130 | "print('Base DecisionTreeClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 131 | "\n", 132 | "clf = RandomForestClassifier(random_state=34092)\n", 133 | "clf.fit(X_train, y_train)\n", 134 | "print('Base RandomForestClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 135 | "\n", 136 | "clf = GradientBoostingClassifier(random_state=34092)\n", 137 | "clf.fit(X_train, y_train)\n", 138 | "print('Base GradientBoostingClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 139 | "\n", 140 | "print('')\n", 141 | "\n", 142 | "cxpb = 0.5\n", 143 | "mutpb = 0.5\n", 144 | "ngen = 50\n", 145 | "verbose = True\n", 146 | "\n", 147 | "logbook = tools.Logbook()\n", 148 | "logbook.header = ['gen', 'nevals'] + (stats.fields if stats else [])\n", 149 | "\n", 150 | "# Evaluate the individuals with an invalid fitness\n", 151 | "invalid_ind = [ind for ind in population if not ind.fitness.valid]\n", 152 | "fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)\n", 153 | "for ind, fit in zip(invalid_ind, fitnesses):\n", 154 | " ind.fitness.values = fit\n", 155 | "\n", 156 | "if halloffame is not None:\n", 157 | " halloffame.update(population)\n", 158 | "\n", 159 | "record = stats.compile(population) if stats else {}\n", 160 | "logbook.record(gen=0, nevals=len(invalid_ind), **record)\n", 161 | "if verbose:\n", 162 | " print(logbook.stream)\n", 163 | "\n", 164 | "# Begin the generational process\n", 165 | "for gen in range(1, ngen + 1):\n", 166 | " # Select the next generation individuals\n", 167 | " offspring = toolbox.select(population, len(population))\n", 168 | "\n", 169 | " # Vary the pool of individuals\n", 170 | " offspring = algorithms.varAnd(offspring, toolbox, cxpb, mutpb)\n", 171 | "\n", 172 | " # Evaluate the individuals with an invalid fitness\n", 173 | " invalid_ind = [ind for ind in offspring if not ind.fitness.valid]\n", 174 | " fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)\n", 175 | " for ind, fit in zip(invalid_ind, fitnesses):\n", 176 | " ind.fitness.values = fit\n", 177 | "\n", 178 | " # Update the hall of fame with the generated individuals\n", 179 | " if halloffame is not None:\n", 180 | " halloffame.update(offspring)\n", 181 | "\n", 182 | " # Replace the current population by the offspring\n", 183 | " population[:] = offspring\n", 184 | "\n", 185 | " # Append the current generation statistics to the logbook\n", 186 | " record = stats.compile(population) if stats else {}\n", 187 | " logbook.record(gen=gen, nevals=len(invalid_ind), **record)\n", 188 | " if verbose:\n", 189 | " print(logbook.stream)\n", 190 | "\n", 191 | "str(halloffame[0])" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": null, 197 | "metadata": { 198 | "collapsed": false 199 | }, 200 | "outputs": [], 201 | "source": [ 202 | "forest_predictions = []\n", 203 | "\n", 204 | "for ind_num, individual in enumerate(pop):\n", 205 | " func = toolbox.compile(expr=individual)\n", 206 | " subsample = np.array([func(*record) for record in X_train])\n", 207 | " \n", 208 | " if X_train[subsample].shape[0] == 0:\n", 209 | " continue\n", 210 | " \n", 211 | " clf = DecisionTreeClassifier(random_state=34092)\n", 212 | " clf.fit(X_train[subsample], y_train[subsample])\n", 213 | " predictions = clf.predict(X_test)\n", 214 | " forest_predictions.append(predictions)" 215 | ] 216 | }, 217 | { 218 | "cell_type": "code", 219 | "execution_count": null, 220 | "metadata": { 221 | "collapsed": false, 222 | "scrolled": false 223 | }, 224 | "outputs": [], 225 | "source": [ 226 | "from collections import Counter\n", 227 | "from sklearn.metrics import accuracy_score\n", 228 | "\n", 229 | "y_pred = np.array(\n", 230 | " [Counter(instance_forest_predictions).most_common(1)[0][0] for instance_forest_predictions in zip(*forest_predictions)])\n", 231 | "np.sum(y_test == y_pred) / len(y_test)" 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "execution_count": null, 237 | "metadata": { 238 | "collapsed": true 239 | }, 240 | "outputs": [], 241 | "source": [] 242 | } 243 | ], 244 | "metadata": { 245 | "kernelspec": { 246 | "display_name": "Python 2", 247 | "language": "python", 248 | "name": "python2" 249 | }, 250 | "language_info": { 251 | "codemirror_mode": { 252 | "name": "ipython", 253 | "version": 2 254 | }, 255 | "file_extension": ".py", 256 | "mimetype": "text/x-python", 257 | "name": "python", 258 | "nbconvert_exporter": "python", 259 | "pygments_lexer": "ipython2", 260 | "version": "2.7.9" 261 | } 262 | }, 263 | "nbformat": 4, 264 | "nbformat_minor": 0 265 | } 266 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/evolved-forest-demo-scaled-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "import operator\n", 12 | "import itertools\n", 13 | "import numpy as np\n", 14 | "\n", 15 | "from deap import algorithms\n", 16 | "from deap import base\n", 17 | "from deap import creator\n", 18 | "from deap import tools\n", 19 | "from deap import gp\n", 20 | "\n", 21 | "from sklearn.tree import DecisionTreeClassifier\n", 22 | "from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier\n", 23 | "from sklearn.datasets import load_digits\n", 24 | "from sklearn.cross_validation import train_test_split\n", 25 | "\n", 26 | "np.seterr(all='raise')\n", 27 | "\n", 28 | "digits = load_digits()\n", 29 | "digit_features, digit_labels = digits.data, digits.target\n", 30 | "X_train, X_test, y_train, y_test = train_test_split(digit_features, digit_labels, stratify=digit_labels,\n", 31 | " train_size=0.75, test_size=0.25)\n", 32 | "\n", 33 | "# defined a new primitive set for strongly typed GP\n", 34 | "pset = gp.PrimitiveSetTyped('MAIN', itertools.repeat(float, digit_features.shape[1]), bool, 'Feature')\n", 35 | "\n", 36 | "# boolean operators\n", 37 | "pset.addPrimitive(operator.and_, [bool, bool], bool)\n", 38 | "pset.addPrimitive(operator.or_, [bool, bool], bool)\n", 39 | "pset.addPrimitive(operator.not_, [bool], bool)\n", 40 | "\n", 41 | "# floating point operators\n", 42 | "# Define a protected division function\n", 43 | "def protectedDiv(left, right):\n", 44 | " try: return left / right\n", 45 | " except (ZeroDivisionError, FloatingPointError): return 1.\n", 46 | "\n", 47 | "pset.addPrimitive(operator.add, [float, float], float)\n", 48 | "pset.addPrimitive(operator.sub, [float, float], float)\n", 49 | "pset.addPrimitive(operator.mul, [float, float], float)\n", 50 | "pset.addPrimitive(protectedDiv, [float, float], float)\n", 51 | "\n", 52 | "# logic operators\n", 53 | "# Define a new if-then-else function\n", 54 | "def if_then_else(in1, output1, output2):\n", 55 | " if in1: return output1\n", 56 | " else: return output2\n", 57 | "\n", 58 | "pset.addPrimitive(operator.lt, [float, float], bool)\n", 59 | "pset.addPrimitive(operator.eq, [float, float], bool)\n", 60 | "pset.addPrimitive(if_then_else, [bool, float, float], float)\n", 61 | "\n", 62 | "# terminals\n", 63 | "pset.addTerminal(False, bool)\n", 64 | "pset.addTerminal(True, bool)\n", 65 | "for val in np.arange(-10., 11.):\n", 66 | " pset.addTerminal(val, float)\n", 67 | "\n", 68 | "creator.create('FitnessMax', base.Fitness, weights=(1.0,))\n", 69 | "creator.create('Individual', gp.PrimitiveTree, fitness=creator.FitnessMax)\n", 70 | "\n", 71 | "toolbox = base.Toolbox()\n", 72 | "toolbox.register('expr', gp.genHalfAndHalf, pset=pset, min_=1, max_=3)\n", 73 | "toolbox.register('individual', tools.initIterate, creator.Individual, toolbox.expr)\n", 74 | "toolbox.register('population', tools.initRepeat, list, toolbox.individual)\n", 75 | "toolbox.register('compile', gp.compile, pset=pset)\n", 76 | "\n", 77 | "def evaluate_individual(individual):\n", 78 | " # Transform the tree expression into a callable function\n", 79 | " func = toolbox.compile(expr=individual)\n", 80 | " subsample = np.array([func(*record) for record in X_train])\n", 81 | " \n", 82 | " if X_train[subsample].shape[0] == 0:\n", 83 | " return 1e-20,\n", 84 | " \n", 85 | " clf = DecisionTreeClassifier(random_state=34092)\n", 86 | " clf.fit(X_train[subsample], y_train[subsample])\n", 87 | " score = clf.score(X_test, y_test)\n", 88 | " \n", 89 | " return score,\n", 90 | " \n", 91 | "toolbox.register('evaluate', evaluate_individual)\n", 92 | "toolbox.register('select', tools.selTournament, tournsize=3)\n", 93 | "toolbox.register('mate', gp.cxOnePoint)\n", 94 | "toolbox.register('expr_mut', gp.genFull, min_=0, max_=3)\n", 95 | "toolbox.register('mutate', gp.mutUniform, expr=toolbox.expr_mut, pset=pset)\n", 96 | "\n", 97 | "population = toolbox.population(n=100)\n", 98 | "halloffame = tools.HallOfFame(1)\n", 99 | "stats = tools.Statistics(lambda ind: ind.fitness.values)\n", 100 | "stats.register('std', np.std)\n", 101 | "stats.register('min', np.min)\n", 102 | "stats.register('avg', np.mean)\n", 103 | "stats.register('max', np.max)\n", 104 | "\n", 105 | "clf = DecisionTreeClassifier(random_state=34092)\n", 106 | "clf.fit(X_train, y_train)\n", 107 | "print('Base DecisionTreeClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 108 | "\n", 109 | "clf = RandomForestClassifier(random_state=34092)\n", 110 | "clf.fit(X_train, y_train)\n", 111 | "print('Base RandomForestClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 112 | "\n", 113 | "clf = GradientBoostingClassifier(random_state=34092)\n", 114 | "clf.fit(X_train, y_train)\n", 115 | "print('Base GradientBoostingClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 116 | "\n", 117 | "print('')\n", 118 | "\n", 119 | "cxpb = 0.5\n", 120 | "mutpb = 0.5\n", 121 | "ngen = 50\n", 122 | "verbose = True\n", 123 | "\n", 124 | "logbook = tools.Logbook()\n", 125 | "logbook.header = ['gen', 'nevals'] + (stats.fields if stats else [])\n", 126 | "\n", 127 | "# Evaluate the individuals with an invalid fitness\n", 128 | "invalid_ind = [ind for ind in population if not ind.fitness.valid]\n", 129 | "fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)\n", 130 | "for ind, fit in zip(invalid_ind, fitnesses):\n", 131 | " ind.fitness.values = fit\n", 132 | "\n", 133 | "if halloffame is not None:\n", 134 | " halloffame.update(population)\n", 135 | "\n", 136 | "record = stats.compile(population) if stats else {}\n", 137 | "logbook.record(gen=0, nevals=len(invalid_ind), **record)\n", 138 | "if verbose:\n", 139 | " print(logbook.stream)\n", 140 | "\n", 141 | "# Begin the generational process\n", 142 | "for gen in range(1, ngen + 1):\n", 143 | " # Select the next generation individuals\n", 144 | " offspring = toolbox.select(population, len(population))\n", 145 | "\n", 146 | " # Vary the pool of individuals\n", 147 | " offspring = algorithms.varAnd(offspring, toolbox, cxpb, mutpb)\n", 148 | "\n", 149 | " # Evaluate the individuals with an invalid fitness\n", 150 | " invalid_ind = [ind for ind in offspring if not ind.fitness.valid]\n", 151 | " fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)\n", 152 | " for ind, fit in zip(invalid_ind, fitnesses):\n", 153 | " ind.fitness.values = fit\n", 154 | "\n", 155 | " # Update the hall of fame with the generated individuals\n", 156 | " if halloffame is not None:\n", 157 | " halloffame.update(offspring)\n", 158 | "\n", 159 | " # Replace the current population by the offspring\n", 160 | " population[:] = offspring\n", 161 | "\n", 162 | " # Append the current generation statistics to the logbook\n", 163 | " record = stats.compile(population) if stats else {}\n", 164 | " logbook.record(gen=gen, nevals=len(invalid_ind), **record)\n", 165 | " if verbose:\n", 166 | " print(logbook.stream)\n", 167 | "\n", 168 | "str(halloffame[0])" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": null, 174 | "metadata": { 175 | "collapsed": false 176 | }, 177 | "outputs": [], 178 | "source": [ 179 | "forest_predictions = []\n", 180 | "\n", 181 | "for ind_num, individual in enumerate(pop):\n", 182 | " func = toolbox.compile(expr=individual)\n", 183 | " subsample = np.array([func(*record) for record in X_train])\n", 184 | " \n", 185 | " if X_train[subsample].shape[0] == 0:\n", 186 | " continue\n", 187 | " \n", 188 | " clf = DecisionTreeClassifier(random_state=34092)\n", 189 | " clf.fit(X_train[subsample], y_train[subsample])\n", 190 | " predictions = clf.predict(X_test)\n", 191 | " forest_predictions.append(predictions)" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": null, 197 | "metadata": { 198 | "collapsed": false, 199 | "scrolled": false 200 | }, 201 | "outputs": [], 202 | "source": [ 203 | "from collections import Counter\n", 204 | "from sklearn.metrics import accuracy_score\n", 205 | "\n", 206 | "y_pred = np.array(\n", 207 | " [Counter(instance_forest_predictions).most_common(1)[0][0] for instance_forest_predictions in zip(*forest_predictions)])\n", 208 | "np.sum(y_test == y_pred) / len(y_test)" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": null, 214 | "metadata": { 215 | "collapsed": true 216 | }, 217 | "outputs": [], 218 | "source": [] 219 | } 220 | ], 221 | "metadata": { 222 | "kernelspec": { 223 | "display_name": "Python 3", 224 | "language": "python", 225 | "name": "python3" 226 | }, 227 | "language_info": { 228 | "codemirror_mode": { 229 | "name": "ipython", 230 | "version": 3 231 | }, 232 | "file_extension": ".py", 233 | "mimetype": "text/x-python", 234 | "name": "python", 235 | "nbconvert_exporter": "python", 236 | "pygments_lexer": "ipython3", 237 | "version": "3.5.1" 238 | } 239 | }, 240 | "nbformat": 4, 241 | "nbformat_minor": 0 242 | } 243 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Evolved Forest 2 | 3 | Using Genetic Programming to grow forests for regression and classification. Metafeatures are used to reduce the exploration space and aid the GP to come with the better informed forests. 4 | Hunch is to see if GP can grow better trees than randomised generation of forests. 5 | 6 | Repo contains notebooks for different experiments. 7 | 8 | ## Subsampling 9 | Currently subspacing based methods have been explored. Each tree in the GP decides which rows to keep based on simple rules. 10 | Eg. 11 | ``` 12 | Feature_3 should be greater than 3 and Feature_4 < 2. 13 | ``` 14 | ## Subspacing 15 | [todo] Feature level metafeatures need to be extracted and made as primitives to be fed to GP. 16 | 17 | ##Fitness and Selection methods being explored 18 | - true_probablity variance 19 | - Custom difficulty scores per row. 20 | - Lexicase Selection 21 | - Implicit Fitness pressure. 22 | - Private Holdout Fitness 23 | - Out of Bag Error Fitness 24 | 25 | 26 | 27 | Multi-objective evolution and Pareto front are also being explored combining above methods. 28 | 29 | 30 | -------------------------------------------------------------------------------- /datasets/GAMETES-easy-4x2-way_her-0.4_pop-1600_attribs-100_discrete.csv: -------------------------------------------------------------------------------- 1 | N0 N1 N2 N3 N4 N5 N6 N7 N8 N9 N10 N11 N12 N13 N14 N15 N16 N17 N18 N19 N20 N21 N22 N23 N24 N25 N26 N27 N28 N29 N30 N31 N32 N33 N34 N35 N36 N37 N38 N39 N40 N41 N42 N43 N44 N45 N46 N47 N48 N49 N50 N51 N52 N53 N54 N55 N56 N57 N58 N59 N60 N61 N62 N63 N64 N65 N66 N67 N68 N69 N70 N71 N72 N73 N74 N75 N76 N77 N78 N79 N80 N81 N82 N83 N84 N85 N86 N87 N88 N89 N90 N91 M0P0 M0P1 M1P0 M1P1 M2P0 M2P1 M3P0 M3P1 class 2 | 1 1 1 0 1 1 1 1 0 0 1 0 0 1 1 1 0 0 2 0 0 0 1 0 0 1 0 0 1 1 1 1 1 0 1 2 1 0 1 1 1 1 1 0 1 0 0 1 2 0 1 0 0 1 0 1 2 1 0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 1 2 0 1 0 1 1 1 1 1 1 1 0 1 1 0 2 1 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 0 0 1 0 0 1 1 1 1 1 0 1 0 1 0 0 2 0 0 0 1 0 1 0 0 202 | -------------------------------------------------------------------------------- /papers/Lexicase Selection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EvoML/evolved-forests/7572d5bcf38cfed643bcd42f9f3461aa7b102f17/papers/Lexicase Selection.pdf -------------------------------------------------------------------------------- /subsampling/.ipynb_checkpoints/Difficulty Level of Rows - Approach - Results-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Aim \n", 8 | "What I tried was with the intuition that if we provide a difficulty level to each of the row and allot the fitness function according to this difficulty then we can make ensemble of models which tries to solve different chunks of the dataset.\n", 9 | "\n", 10 | "-------------------------------\n", 11 | "\n", 12 | "#### Difficulty Marks\n", 13 | " - The difficulty would define that how many models were able to predict the exact value for that row. If the model is difficult then more marks will be awarded to the model on solving it.\n", 14 | " \n", 15 | " - We tried\n", 16 | " \n", 17 | " -- Discrete level of marking (ex: 0-10)\n", 18 | " \n", 19 | " -- -ve of Marks as per how many models have solved it. So higher magnitude on the -ve side would indicate many models have already solved it and now this model should focus on other rows.\n", 20 | " \n", 21 | " -- 1/(number of pop that has solved it)\n", 22 | " \n", 23 | " -- Again incremental marks but with upper and lower margin.\n", 24 | "\n", 25 | "-------------------------------------\n", 26 | "\n", 27 | "#### When to update the marks\n", 28 | " \n", 29 | " - We updated the score after each fitness calculation for each model, so that the models below in the population can focus on the harder problems. \n", 30 | " \n", 31 | " - Updated the score after each population iteration, so that in the next iteration the models can focus on harder rows of the dataset.\n", 32 | " \n", 33 | "-------------------------------------\n", 34 | "\n", 35 | "#### Results\n", 36 | " \n", 37 | " - But the results were not inline with our expectations. the difficulty seemed to be changing from one end to the other. It keeps on fluctuating during the iterations.\n", 38 | " \n", 39 | " - Also the accuracy kept on fluctuating. If we run it for multiple iterations, it wins sometimes but loses to the basic models most of the time.\n" 40 | ] 41 | } 42 | ], 43 | "metadata": { 44 | "kernelspec": { 45 | "display_name": "Python 2", 46 | "language": "python", 47 | "name": "python2" 48 | }, 49 | "language_info": { 50 | "codemirror_mode": { 51 | "name": "ipython", 52 | "version": 2 53 | }, 54 | "file_extension": ".py", 55 | "mimetype": "text/x-python", 56 | "name": "python", 57 | "nbconvert_exporter": "python", 58 | "pygments_lexer": "ipython2", 59 | "version": "2.7.9" 60 | } 61 | }, 62 | "nbformat": 4, 63 | "nbformat_minor": 0 64 | } 65 | -------------------------------------------------------------------------------- /subsampling/Difficulty Level of Rows - Approach - Results.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Aim \n", 8 | "What I tried was with the intuition that if we provide a difficulty level to each of the row and allot the fitness function according to this difficulty then we can make ensemble of models which tries to solve different chunks of the dataset.\n", 9 | "\n", 10 | "-------------------------------\n", 11 | "\n", 12 | "#### Difficulty Marks\n", 13 | " - The difficulty would define that how many models were able to predict the exact value for that row. If the model is difficult then more marks will be awarded to the model on solving it.\n", 14 | " \n", 15 | " - We tried\n", 16 | " \n", 17 | " -- Discrete level of marking (ex: 0-10)\n", 18 | " \n", 19 | " -- -ve of Marks as per how many models have solved it. So higher magnitude on the -ve side would indicate many models have already solved it and now this model should focus on other rows.\n", 20 | " \n", 21 | " -- 1/(number of pop that has solved it)\n", 22 | " \n", 23 | " -- Again incremental marks but with upper and lower margin.\n", 24 | "\n", 25 | "-------------------------------------\n", 26 | "\n", 27 | "#### When to update the marks\n", 28 | " \n", 29 | " - We updated the score after each fitness calculation for each model, so that the models below in the population can focus on the harder problems. \n", 30 | " \n", 31 | " - Updated the score after each population iteration, so that in the next iteration the models can focus on harder rows of the dataset.\n", 32 | " \n", 33 | "-------------------------------------\n", 34 | "\n", 35 | "#### Results\n", 36 | " \n", 37 | " - But the results were not inline with our expectations. the difficulty seemed to be changing from one end to the other. It keeps on fluctuating during the iterations.\n", 38 | " \n", 39 | " - Also the accuracy kept on fluctuating. If we run it for multiple iterations, it wins sometimes but loses to the basic models most of the time.\n" 40 | ] 41 | } 42 | ], 43 | "metadata": { 44 | "kernelspec": { 45 | "display_name": "Python 2", 46 | "language": "python", 47 | "name": "python2" 48 | }, 49 | "language_info": { 50 | "codemirror_mode": { 51 | "name": "ipython", 52 | "version": 2 53 | }, 54 | "file_extension": ".py", 55 | "mimetype": "text/x-python", 56 | "name": "python", 57 | "nbconvert_exporter": "python", 58 | "pygments_lexer": "ipython2", 59 | "version": "2.7.9" 60 | } 61 | }, 62 | "nbformat": 4, 63 | "nbformat_minor": 0 64 | } 65 | -------------------------------------------------------------------------------- /subsampling/dump/evolved-forest-demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 484, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "tools.selTournament?=" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 488, 17 | "metadata": { 18 | "collapsed": false, 19 | "scrolled": false 20 | }, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "Base DecisionTreeClassifier accuracy: 0.79822616408\n", 27 | "Base RandomForestClassifier accuracy: 0.935698447894\n", 28 | "Base GradientBoostingClassifier accuracy: 0.953436807095\n", 29 | "\n", 30 | "gen\tnevals\tstd \tmin \tavg \tmax \n", 31 | "0 \t100 \t0.29591\t1e-20\t0.283743\t0.845697\n", 32 | "1 \t74 \t0.286518\t1e-20\t0.265852\t0.845697\n", 33 | "0.377744807122\n", 34 | "0.153958785316\n", 35 | "0.838137472284\n", 36 | "2 \t70 \t0.298589\t1e-20\t0.298604\t0.863501\n", 37 | "0.418545994065\n", 38 | "0.178662031471\n", 39 | "0.835920177384\n", 40 | "3 \t71 \t0.296482\t1e-20\t0.312243\t0.851632\n", 41 | "0.448872403561\n", 42 | "0.175614031596\n", 43 | "0.835920177384\n", 44 | "4 \t71 \t0.297173\t1e-20\t0.314295\t0.866469\n", 45 | "0.456112759644\n", 46 | "0.172477157744\n", 47 | "0.835920177384\n", 48 | "5 \t71 \t0.287548\t1e-20\t0.300233\t0.851632\n", 49 | "0.432551928783\n", 50 | "0.16791387545\n", 51 | "0.853658536585\n", 52 | "6 \t79 \t0.291583\t1e-20\t0.33621 \t0.851632\n", 53 | "0.475044510386\n", 54 | "0.197375676971\n", 55 | "0.851441241685\n", 56 | "7 \t83 \t0.288972\t1e-20\t0.325717\t0.860534\n", 57 | "0.46590504451\n", 58 | "0.185528906462\n", 59 | "0.862527716186\n", 60 | "8 \t73 \t0.28661 \t1e-20\t0.302143\t0.860534\n", 61 | "0.429317507418\n", 62 | "0.174967656034\n", 63 | "0.875831485588\n", 64 | "9 \t71 \t0.281472\t1e-20\t0.300827\t0.872404\n", 65 | "0.423560830861\n", 66 | "0.178092622587\n", 67 | "0.871396895787\n", 68 | "10 \t70 \t0.288094\t1e-20\t0.292819\t0.872404\n", 69 | "0.410652818991\n", 70 | "0.174985296847\n", 71 | "0.875831485588\n", 72 | "11 \t76 \t0.293143\t1e-20\t0.295748\t0.872404\n", 73 | "0.415400593472\n", 74 | "0.176095295506\n", 75 | "0.866962305987\n", 76 | "12 \t71 \t0.289762\t1e-20\t0.273901\t0.872404\n", 77 | "0.392433234421\n", 78 | "0.155369342742\n", 79 | "0.860310421286\n", 80 | "13 \t72 \t0.295138\t1e-20\t0.291235\t0.857567\n", 81 | "0.416320474777\n", 82 | "0.166150042546\n", 83 | "0.844789356984\n", 84 | "14 \t73 \t0.294758\t1e-20\t0.292039\t0.863501\n", 85 | "0.42765578635\n", 86 | "0.156421940329\n", 87 | "0.840354767184\n", 88 | "15 \t69 \t0.296153\t1e-20\t0.299076\t0.848665\n", 89 | "0.430652818991\n", 90 | "0.167498226142\n", 91 | "0.835920177384\n", 92 | "16 \t79 \t0.296001\t1e-20\t0.328756\t0.845697\n", 93 | "0.477952522255\n", 94 | "0.179559713439\n", 95 | "0.840354767184\n", 96 | "17 \t71 \t0.29285 \t1e-20\t0.317651\t0.845697\n", 97 | "0.461364985163\n", 98 | "0.173936089295\n", 99 | "0.849223946785\n", 100 | "18 \t68 \t0.29147 \t1e-20\t0.316392\t0.848665\n", 101 | "0.462759643917\n", 102 | "0.17002515921\n", 103 | "0.853658536585\n", 104 | "19 \t67 \t0.298827\t1e-20\t0.329119\t0.866469\n", 105 | "0.476824925816\n", 106 | "0.181412345922\n", 107 | "0.840354767184\n", 108 | "20 \t67 \t0.298097\t1e-20\t0.327061\t0.866469\n", 109 | "0.472611275964\n", 110 | "0.181510332729\n", 111 | "0.853658536585\n", 112 | "21 \t76 \t0.28923 \t1e-20\t0.307447\t0.866469\n", 113 | "0.442314540059\n", 114 | "0.172578744847\n", 115 | "0.855875831486\n", 116 | "22 \t73 \t0.285179\t1e-20\t0.32282 \t0.854599\n", 117 | "0.457210682493\n", 118 | "0.188430112702\n", 119 | "0.889135254989\n", 120 | "23 \t78 \t0.284747\t1e-20\t0.32154 \t0.845697\n", 121 | "0.452136498516\n", 122 | "0.19094445343\n", 123 | "0.875831485588\n", 124 | "24 \t73 \t0.28068 \t1e-20\t0.322317\t0.860534\n", 125 | "0.448931750742\n", 126 | "0.19570142394\n", 127 | "0.866962305987\n", 128 | "25 \t81 \t0.27866 \t1e-20\t0.317622\t0.860534\n", 129 | "0.445519287834\n", 130 | "0.18972445102\n", 131 | "0.889135254989\n", 132 | "26 \t77 \t0.284933\t1e-20\t0.328825\t0.860534\n", 133 | "0.466884272997\n", 134 | "0.190766626822\n", 135 | "0.889135254989\n", 136 | "27 \t70 \t0.280739\t1e-20\t0.324522\t0.848665\n", 137 | "0.45884272997\n", 138 | "0.190202114038\n", 139 | "0.89800443459\n", 140 | "28 \t81 \t0.282713\t1e-20\t0.337602\t0.860534\n", 141 | "0.477151335312\n", 142 | "0.198052890902\n", 143 | "0.882483370288\n", 144 | "29 \t77 \t0.29214 \t1e-20\t0.350574\t0.860534\n", 145 | "0.502225519288\n", 146 | "0.198922673136\n", 147 | "0.880266075388\n", 148 | "30 \t80 \t0.290774\t1e-20\t0.327165\t0.851632\n", 149 | "0.471424332344\n", 150 | "0.18290616772\n", 151 | "0.882483370288\n", 152 | "31 \t68 \t0.292776\t1e-20\t0.34284 \t0.851632\n", 153 | "0.496053412463\n", 154 | "0.189626659651\n", 155 | "0.844789356984\n", 156 | "32 \t72 \t0.291386\t1e-20\t0.353735\t0.857567\n", 157 | "0.511721068249\n", 158 | "0.195749254913\n", 159 | "0.847006651885\n", 160 | "33 \t71 \t0.289644\t1e-20\t0.326167\t0.851632\n", 161 | "0.468516320475\n", 162 | "0.183816854062\n", 163 | "0.860310421286\n", 164 | "34 \t76 \t0.280292\t1e-20\t0.311883\t0.860534\n", 165 | "0.442077151335\n", 166 | "0.181687974098\n", 167 | "0.882483370288\n", 168 | "35 \t63 \t0.276928\t1e-20\t0.32416 \t0.869436\n", 169 | "0.451928783383\n", 170 | "0.196391914623\n", 171 | "0.886917960089\n", 172 | "36 \t81 \t0.27892 \t1e-20\t0.315959\t0.869436\n", 173 | "0.435400593472\n", 174 | "0.196517872464\n", 175 | "0.875831485588\n", 176 | "37 \t76 \t0.28591 \t1e-20\t0.313277\t0.869436\n", 177 | "0.437329376855\n", 178 | "0.189225307873\n", 179 | "0.871396895787\n", 180 | "38 \t79 \t0.285711\t1e-20\t0.31892 \t0.860534\n", 181 | "0.446735905045\n", 182 | "0.191104504858\n", 183 | "0.884700665188\n", 184 | "39 \t70 \t0.292208\t1e-20\t0.326781\t0.854599\n", 185 | "0.4646884273\n", 186 | "0.188872948757\n", 187 | "0.875831485588\n", 188 | "40 \t72 \t0.284664\t1e-20\t0.33649 \t0.863501\n", 189 | "0.479792284866\n", 190 | "0.193188312152\n", 191 | "0.871396895787\n", 192 | "41 \t76 \t0.286813\t1e-20\t0.333206\t0.863501\n", 193 | "0.472670623145\n", 194 | "0.193742314499\n", 195 | "0.871396895787\n", 196 | "42 \t80 \t0.289526\t1e-20\t0.325685\t0.863501\n", 197 | "0.465133531157\n", 198 | "0.186237456756\n", 199 | "0.878048780488\n", 200 | "43 \t79 \t0.291194\t1e-20\t0.321169\t0.863501\n", 201 | "0.460860534125\n", 202 | "0.181476933701\n", 203 | "0.866962305987\n", 204 | "44 \t82 \t0.29731 \t1e-20\t0.315888\t0.863501\n", 205 | "0.457537091988\n", 206 | "0.174238962257\n", 207 | "0.860310421286\n", 208 | "45 \t78 \t0.288061\t1e-20\t0.312245\t0.863501\n", 209 | "0.454629080119\n", 210 | "0.169860825014\n", 211 | "0.858093126386\n", 212 | "46 \t69 \t0.291955\t1e-20\t0.317767\t0.863501\n", 213 | "0.45234421365\n", 214 | "0.183188930581\n", 215 | "0.860310421286\n", 216 | "47 \t70 \t0.296527\t1e-20\t0.299055\t0.863501\n", 217 | "0.42762611276\n", 218 | "0.170484506309\n", 219 | "0.855875831486\n", 220 | "48 \t73 \t0.292385\t1e-20\t0.273031\t0.860534\n", 221 | "0.396112759644\n", 222 | "0.14994997282\n", 223 | "0.847006651885\n", 224 | "49 \t78 \t0.287511\t1e-20\t0.29503 \t0.857567\n", 225 | "0.421246290801\n", 226 | "0.168813387474\n", 227 | "0.891352549889\n", 228 | "50 \t70 \t0.282213\t1e-20\t0.287907\t0.857567\n", 229 | "0.407299703264\n", 230 | "0.168514699756\n", 231 | "0.866962305987\n" 232 | ] 233 | }, 234 | { 235 | "data": { 236 | "text/plain": [ 237 | "'not_(or_(False, lt(if_then_else(False, add(Feature20, 3.0), if_then_else(False, Feature48, 7.0)), mul(if_then_else(False, Feature14, Feature8), if_then_else(False, Feature54, Feature36)))))'" 238 | ] 239 | }, 240 | "execution_count": 488, 241 | "metadata": {}, 242 | "output_type": "execute_result" 243 | } 244 | ], 245 | "source": [ 246 | "import operator\n", 247 | "import itertools\n", 248 | "import numpy as np\n", 249 | "\n", 250 | "from deap import algorithms\n", 251 | "from deap import base\n", 252 | "from deap import creator\n", 253 | "from deap import tools\n", 254 | "from deap import gp\n", 255 | "\n", 256 | "from sklearn.tree import DecisionTreeClassifier\n", 257 | "from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier\n", 258 | "from sklearn.datasets import load_digits\n", 259 | "from sklearn.cross_validation import train_test_split\n", 260 | "\n", 261 | "np.seterr(all='raise')\n", 262 | "\n", 263 | "digits = load_digits()\n", 264 | "digit_features, digit_labels = digits.data, digits.target\n", 265 | "\n", 266 | "\n", 267 | "X_train_tot, X_test_tot, y_train_tot, y_test_tot = train_test_split(digit_features, digit_labels, stratify=digit_labels,\n", 268 | " train_size=0.75, test_size=0.25)\n", 269 | "\n", 270 | "\n", 271 | "X_train, X_test, y_train, y_test = train_test_split(X_train_tot, y_train_tot, stratify=y_train_tot,\n", 272 | " train_size=0.75, test_size=0.25)\n", 273 | "\n", 274 | "\n", 275 | "\n", 276 | "\n", 277 | "# defined a new primitive set for strongly typed GP\n", 278 | "pset = gp.PrimitiveSetTyped('MAIN', itertools.repeat(float, digit_features.shape[1]), bool, 'Feature')\n", 279 | "\n", 280 | "# boolean operators\n", 281 | "pset.addPrimitive(operator.and_, [bool, bool], bool)\n", 282 | "pset.addPrimitive(operator.or_, [bool, bool], bool)\n", 283 | "pset.addPrimitive(operator.not_, [bool], bool)\n", 284 | "\n", 285 | "# floating point operators\n", 286 | "# Define a protected division function\n", 287 | "def protectedDiv(left, right):\n", 288 | " try: return left / right\n", 289 | " except (ZeroDivisionError, FloatingPointError): return 1.\n", 290 | "\n", 291 | "pset.addPrimitive(operator.add, [float, float], float)\n", 292 | "pset.addPrimitive(operator.sub, [float, float], float)\n", 293 | "pset.addPrimitive(operator.mul, [float, float], float)\n", 294 | "pset.addPrimitive(protectedDiv, [float, float], float)\n", 295 | "\n", 296 | "# logic operators\n", 297 | "# Define a new if-then-else function\n", 298 | "def if_then_else(in1, output1, output2):\n", 299 | " if in1: return output1\n", 300 | " else: return output2\n", 301 | "\n", 302 | "pset.addPrimitive(operator.lt, [float, float], bool)\n", 303 | "pset.addPrimitive(operator.eq, [float, float], bool)\n", 304 | "pset.addPrimitive(if_then_else, [bool, float, float], float)\n", 305 | "\n", 306 | "# terminals\n", 307 | "pset.addTerminal(False, bool)\n", 308 | "pset.addTerminal(True, bool)\n", 309 | "for val in np.arange(-10., 11.):\n", 310 | " pset.addTerminal(val, float)\n", 311 | "\n", 312 | "creator.create('FitnessMax', base.Fitness, weights=(2.0,1.0))\n", 313 | "creator.create('Individual', gp.PrimitiveTree, fitness=creator.FitnessMax)\n", 314 | "\n", 315 | "toolbox = base.Toolbox()\n", 316 | "toolbox.register('expr', gp.genHalfAndHalf, pset=pset, min_=1, max_=3)\n", 317 | "toolbox.register('individual', tools.initIterate, creator.Individual, toolbox.expr)\n", 318 | "toolbox.register('population', tools.initRepeat, list, toolbox.individual)\n", 319 | "toolbox.register('compile', gp.compile, pset=pset)\n", 320 | "\n", 321 | "\n", 322 | "\n", 323 | "row_prob = {} # Each key is row index,\n", 324 | "row_mean_prob = {}\n", 325 | "def update_true_class_variance(pop_):\n", 326 | " \n", 327 | " \"\"\"\n", 328 | " pop is a list of indiv.\n", 329 | " Each indiv\n", 330 | " \"\"\"\n", 331 | " global row_prob, row_mean_prob\n", 332 | " row_prob = {} #reset\n", 333 | " row_mean_prob = {}\n", 334 | " \n", 335 | " for individual in pop_:\n", 336 | " func = toolbox.compile(expr=individual)\n", 337 | " subsample = np.array([func(*record) for record in X_train])\n", 338 | "\n", 339 | " if X_train[subsample].shape[0] == 0:\n", 340 | " continue\n", 341 | "\n", 342 | " clf = DecisionTreeClassifier(random_state=34092)\n", 343 | " clf.fit(X_train[subsample], y_train[subsample])\n", 344 | "\n", 345 | " probas = clf.predict_proba(X_test)\n", 346 | "# print clf.classes_\n", 347 | " for ix, row in enumerate(probas):\n", 348 | "# print row\n", 349 | " try:\n", 350 | " true_p = row[y_test[ix]]\n", 351 | " except:\n", 352 | " true_p = np.nan\n", 353 | " try:\n", 354 | " row_prob[ix].append(true_p)\n", 355 | " except:\n", 356 | " row_prob[ix] = [true_p]\n", 357 | "# print row_prob[ix]\n", 358 | " \n", 359 | "# print 'row_prob', row_prob\n", 360 | " for key in row_prob.keys():\n", 361 | " row_mean_prob[key] = np.nanmean(row_prob[key])\n", 362 | " \n", 363 | " return \n", 364 | " \n", 365 | "\n", 366 | "def evaluate_individual(individual):\n", 367 | " global row_mean_prob\n", 368 | " # Transform the tree expression into a callable function\n", 369 | " func = toolbox.compile(expr=individual)\n", 370 | " subsample = np.array([func(*record) for record in X_train])\n", 371 | " \n", 372 | " if X_train[subsample].shape[0] == 0:\n", 373 | " return (1e-20,1e-20)\n", 374 | " \n", 375 | " clf = DecisionTreeClassifier(random_state=34092)\n", 376 | " clf.fit(X_train[subsample], y_train[subsample])\n", 377 | " score = clf.score(X_test, y_test)\n", 378 | " \n", 379 | " probas = clf.predict_proba(X_test)\n", 380 | " total_variance = []\n", 381 | " for ix, row in enumerate(probas):\n", 382 | " try:\n", 383 | " true_p = row[y_test[ix]]\n", 384 | " except:\n", 385 | " true_p = 0\n", 386 | " mean_p = row_mean_prob[ix]\n", 387 | " \n", 388 | " # Can also simply do - 1 - true_p and measure variance in the model.\n", 389 | " if true_p>=0.1:\n", 390 | " added_variance = (mean_p - true_p)**2\n", 391 | " else:\n", 392 | " added_variance = 0 #Should this be nan?\n", 393 | " total_variance.append(added_variance)\n", 394 | " \n", 395 | " mean_variance_added = np.sqrt(np.nanmean(total_variance))\n", 396 | " \n", 397 | " return (score, mean_variance_added)\n", 398 | " \n", 399 | "toolbox.register('evaluate', evaluate_individual)\n", 400 | "#todo: change this according to multi-objective\n", 401 | "# toolbox.register('select', tools.selTournament, tournsize=3)\n", 402 | "toolbox.register('select', tools.selNSGA2)\n", 403 | "\n", 404 | "toolbox.register('mate', gp.cxOnePoint)\n", 405 | "toolbox.register('expr_mut', gp.genFull, min_=0, max_=3)\n", 406 | "toolbox.register('mutate', gp.mutUniform, expr=toolbox.expr_mut, pset=pset)\n", 407 | "\n", 408 | "population = toolbox.population(n=100)\n", 409 | "halloffame = tools.HallOfFame(1)\n", 410 | "stats = tools.Statistics(lambda ind: ind.fitness.values)\n", 411 | "stats.register('std', np.std)\n", 412 | "stats.register('min', np.min)\n", 413 | "stats.register('avg', np.mean)\n", 414 | "stats.register('max', np.max)\n", 415 | "\n", 416 | "clf = DecisionTreeClassifier(random_state=34092)\n", 417 | "clf.fit(X_train_tot, y_train_tot)\n", 418 | "print('Base DecisionTreeClassifier accuracy: {}'.format(clf.score(X_test_tot, y_test_tot)))\n", 419 | "\n", 420 | "clf = RandomForestClassifier(random_state=34092)\n", 421 | "clf.fit(X_train_tot, y_train_tot)\n", 422 | "print('Base RandomForestClassifier accuracy: {}'.format(clf.score(X_test_tot, y_test_tot)))\n", 423 | "\n", 424 | "clf = GradientBoostingClassifier(random_state=34092)\n", 425 | "clf.fit(X_train_tot, y_train_tot)\n", 426 | "print('Base GradientBoostingClassifier accuracy: {}'.format(clf.score(X_test_tot, y_test_tot)))\n", 427 | "\n", 428 | "print('')\n", 429 | "\n", 430 | "cxpb = 0.5\n", 431 | "mutpb = 0.5\n", 432 | "ngen = 50\n", 433 | "verbose = True\n", 434 | "holdout_perf = {}\n", 435 | "\n", 436 | "logbook = tools.Logbook()\n", 437 | "logbook.header = ['gen', 'nevals'] + (stats.fields if stats else [])\n", 438 | "\n", 439 | "\n", 440 | "update_true_class_variance(population)\n", 441 | "\n", 442 | "# Evaluate the individuals with an invalid fitness ~\n", 443 | "invalid_ind = [ind for ind in population if not ind.fitness.valid]\n", 444 | "fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)\n", 445 | "for ind, fit in zip(invalid_ind, fitnesses):\n", 446 | " ind.fitness.values = fit\n", 447 | "\n", 448 | "if halloffame is not None:\n", 449 | " halloffame.update(population)\n", 450 | "\n", 451 | "record = stats.compile(population) if stats else {}\n", 452 | "logbook.record(gen=0, nevals=len(invalid_ind), **record)\n", 453 | "if verbose:\n", 454 | " print(logbook.stream)\n", 455 | "\n", 456 | "# Begin the generational process\n", 457 | "for gen in range(1, ngen + 1):\n", 458 | " # Select the next generation individuals\n", 459 | " offspring = toolbox.select(population, len(population))\n", 460 | "\n", 461 | " # Vary the pool of individuals\n", 462 | " offspring = algorithms.varAnd(offspring, toolbox, cxpb, mutpb)\n", 463 | "\n", 464 | " # Evaluate the individuals with an invalid fitness\n", 465 | " invalid_ind = [ind for ind in offspring if not ind.fitness.valid]\n", 466 | " fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)\n", 467 | " for ind, fit in zip(invalid_ind, fitnesses):\n", 468 | " ind.fitness.values = fit\n", 469 | "\n", 470 | " # Update the hall of fame with the generated individuals\n", 471 | " if halloffame is not None:\n", 472 | " halloffame.update(offspring)\n", 473 | "\n", 474 | " # Replace the current population by the offspring\n", 475 | " population[:] = offspring\n", 476 | "\n", 477 | " #Generate true class predict_proba variance for each row.\n", 478 | " update_true_class_variance(population)\n", 479 | " \n", 480 | " # Append the current generation statistics to the logbook\n", 481 | " fits = pd.DataFrame()\n", 482 | " fits['score'] = map(lambda x: x.fitness.values[0], population)\n", 483 | " fits['contrib_variance'] = map(lambda x: x.fitness.values[1], population)\n", 484 | " \n", 485 | " record = stats.compile(population) if stats else {}\n", 486 | " logbook.record(gen=gen, nevals=len(invalid_ind),**record)\n", 487 | " holdout_perf[gen] = predict_holdout(population)\n", 488 | " if verbose:\n", 489 | " print(logbook.stream)\n", 490 | " print(fits.score.mean())\n", 491 | " print(fits.contrib_variance.mean())\n", 492 | " print(holdout_perf[gen])\n", 493 | "str(halloffame[0])" 494 | ] 495 | }, 496 | { 497 | "cell_type": "code", 498 | "execution_count": 489, 499 | "metadata": { 500 | "collapsed": false 501 | }, 502 | "outputs": [ 503 | { 504 | "data": { 505 | "text/plain": [ 506 | "deap.creator.FitnessMax((0.87240356083086057, 0.34103981606075923))" 507 | ] 508 | }, 509 | "execution_count": 489, 510 | "metadata": {}, 511 | "output_type": "execute_result" 512 | } 513 | ], 514 | "source": [ 515 | "\n", 516 | "# pop = offspring[:]\n", 517 | "# pop = [halloffame[0]]\n", 518 | "halloffame[0].fitness" 519 | ] 520 | }, 521 | { 522 | "cell_type": "code", 523 | "execution_count": 480, 524 | "metadata": { 525 | "collapsed": true 526 | }, 527 | "outputs": [], 528 | "source": [ 529 | "def predict_holdout(pop):\n", 530 | " forest_predictions = []\n", 531 | " subsample_sizes = []\n", 532 | " for ind_num, individual in enumerate(pop):\n", 533 | " func = toolbox.compile(expr=individual)\n", 534 | " # print individual\n", 535 | " subsample = np.array([func(*record) for record in X_train])\n", 536 | " subsample_sizes.append(subsample.sum())\n", 537 | "\n", 538 | " if X_train[subsample].shape[0] == 0:\n", 539 | " continue\n", 540 | "\n", 541 | " clf = DecisionTreeClassifier(random_state=34092)\n", 542 | " clf.fit(X_train[subsample], y_train[subsample])\n", 543 | " predictions = clf.predict(X_test_tot)\n", 544 | " forest_predictions.append(predictions)\n", 545 | " y_pred = np.array(\n", 546 | " [Counter(instance_forest_predictions).most_common(1)[0][0] for instance_forest_predictions in zip(*forest_predictions)])\n", 547 | " \n", 548 | " return np.sum(y_test_tot == y_pred)*1.0 / len(y_test_tot)" 549 | ] 550 | }, 551 | { 552 | "cell_type": "code", 553 | "execution_count": 467, 554 | "metadata": { 555 | "collapsed": false 556 | }, 557 | "outputs": [], 558 | "source": [ 559 | "forest_predictions = []\n", 560 | "subsample_sizes = []\n", 561 | "for ind_num, individual in enumerate(pop):\n", 562 | " func = toolbox.compile(expr=individual)\n", 563 | "# print individual\n", 564 | " subsample = np.array([func(*record) for record in X_train])\n", 565 | " subsample_sizes.append(subsample.sum())\n", 566 | " \n", 567 | " if X_train[subsample].shape[0] == 0:\n", 568 | " continue\n", 569 | " \n", 570 | " clf = DecisionTreeClassifier(random_state=34092, max_depth=5)\n", 571 | " clf.fit(X_train[subsample], y_train[subsample])\n", 572 | " predictions = clf.predict(X_test_tot)\n", 573 | " forest_predictions.append(predictions)" 574 | ] 575 | }, 576 | { 577 | "cell_type": "code", 578 | "execution_count": 468, 579 | "metadata": { 580 | "collapsed": true 581 | }, 582 | "outputs": [], 583 | "source": [ 584 | "# for x in \n", 585 | "fits = pd.DataFrame()\n", 586 | "fits['score'] = map(lambda x: x.fitness.values[0], pop)\n", 587 | "fits['contrib_variance'] = map(lambda x: x.fitness.values[1], pop)" 588 | ] 589 | }, 590 | { 591 | "cell_type": "code", 592 | "execution_count": 469, 593 | "metadata": { 594 | "collapsed": false 595 | }, 596 | "outputs": [], 597 | "source": [ 598 | "%matplotlib inline\n", 599 | "import matplotlib.pyplot as plt\n", 600 | "# fits.contrib_variance.hist()" 601 | ] 602 | }, 603 | { 604 | "cell_type": "code", 605 | "execution_count": 470, 606 | "metadata": { 607 | "collapsed": false 608 | }, 609 | "outputs": [ 610 | { 611 | "data": { 612 | "text/plain": [ 613 | "0.78528189910979218" 614 | ] 615 | }, 616 | "execution_count": 470, 617 | "metadata": {}, 618 | "output_type": "execute_result" 619 | } 620 | ], 621 | "source": [ 622 | "fits.score.mean()\n" 623 | ] 624 | }, 625 | { 626 | "cell_type": "code", 627 | "execution_count": 471, 628 | "metadata": { 629 | "collapsed": false 630 | }, 631 | "outputs": [ 632 | { 633 | "name": "stdout", 634 | "output_type": "stream", 635 | "text": [ 636 | "863.09\n", 637 | "100.248001975\n" 638 | ] 639 | } 640 | ], 641 | "source": [ 642 | "\n", 643 | "# plt.hist(subsample_sizes)\n", 644 | "print np.mean(subsample_sizes)\n", 645 | "print np.std(subsample_sizes)" 646 | ] 647 | }, 648 | { 649 | "cell_type": "code", 650 | "execution_count": 472, 651 | "metadata": { 652 | "collapsed": false 653 | }, 654 | "outputs": [ 655 | { 656 | "data": { 657 | "text/plain": [ 658 | "2.3569844789356984" 659 | ] 660 | }, 661 | "execution_count": 472, 662 | "metadata": {}, 663 | "output_type": "execute_result" 664 | } 665 | ], 666 | "source": [ 667 | "import pandas as pd\n", 668 | "## Mean # of unique labels predicted per sample.\n", 669 | "pd.DataFrame(forest_predictions).apply(lambda x: len(x.unique()), axis=0).mean()" 670 | ] 671 | }, 672 | { 673 | "cell_type": "code", 674 | "execution_count": 473, 675 | "metadata": { 676 | "collapsed": false, 677 | "scrolled": false 678 | }, 679 | "outputs": [ 680 | { 681 | "data": { 682 | "text/plain": [ 683 | "0.80487804878048785" 684 | ] 685 | }, 686 | "execution_count": 473, 687 | "metadata": {}, 688 | "output_type": "execute_result" 689 | } 690 | ], 691 | "source": [ 692 | "from collections import Counter\n", 693 | "from sklearn.metrics import accuracy_score\n", 694 | "\n", 695 | "y_pred = np.array(\n", 696 | " [Counter(instance_forest_predictions).most_common(1)[0][0] for instance_forest_predictions in zip(*forest_predictions)])\n", 697 | "np.sum(y_test_tot == y_pred)*1.0 / len(y_test_tot)" 698 | ] 699 | }, 700 | { 701 | "cell_type": "code", 702 | "execution_count": 465, 703 | "metadata": { 704 | "collapsed": false 705 | }, 706 | "outputs": [ 707 | { 708 | "data": { 709 | "text/html": [ 710 | "
\n", 711 | "\n", 712 | " \n", 713 | " \n", 714 | " \n", 715 | " \n", 716 | " \n", 717 | " \n", 718 | " \n", 719 | " \n", 720 | " \n", 721 | " \n", 722 | " \n", 723 | " \n", 724 | " \n", 725 | " \n", 726 | " \n", 727 | " \n", 728 | " \n", 729 | " \n", 730 | " \n", 731 | " \n", 732 | " \n", 733 | " \n", 734 | " \n", 735 | " \n", 736 | " \n", 737 | " \n", 738 | " \n", 739 | " \n", 740 | " \n", 741 | " \n", 742 | " \n", 743 | " \n", 744 | " \n", 745 | " \n", 746 | " \n", 747 | " \n", 748 | " \n", 749 | " \n", 750 | " \n", 751 | " \n", 752 | " \n", 753 | " \n", 754 | " \n", 755 | " \n", 756 | " \n", 757 | " \n", 758 | " \n", 759 | " \n", 760 | " \n", 761 | " \n", 762 | " \n", 763 | " \n", 764 | "
0123456789...441442443444445446447448449450
06610182274...8805229934
\n", 765 | "

1 rows × 451 columns

\n", 766 | "
" 767 | ], 768 | "text/plain": [ 769 | " 0 1 2 3 4 5 6 7 8 9 ... 441 442 443 444 \\\n", 770 | "0 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 771 | "\n", 772 | " 445 446 447 448 449 450 \n", 773 | "0 2 2 9 9 3 4 \n", 774 | "\n", 775 | "[1 rows x 451 columns]" 776 | ] 777 | }, 778 | "execution_count": 465, 779 | "metadata": {}, 780 | "output_type": "execute_result" 781 | } 782 | ], 783 | "source": [ 784 | "pd.DataFrame(forest_predictions)" 785 | ] 786 | }, 787 | { 788 | "cell_type": "code", 789 | "execution_count": 475, 790 | "metadata": { 791 | "collapsed": false 792 | }, 793 | "outputs": [ 794 | { 795 | "data": { 796 | "text/html": [ 797 | "
\n", 798 | "\n", 799 | " \n", 800 | " \n", 801 | " \n", 802 | " \n", 803 | " \n", 804 | " \n", 805 | " \n", 806 | " \n", 807 | " \n", 808 | " \n", 809 | " \n", 810 | " \n", 811 | " \n", 812 | " \n", 813 | " \n", 814 | " \n", 815 | " \n", 816 | " \n", 817 | " \n", 818 | " \n", 819 | " \n", 820 | " \n", 821 | " \n", 822 | " \n", 823 | " \n", 824 | " \n", 825 | " \n", 826 | " \n", 827 | " \n", 828 | " \n", 829 | " \n", 830 | " \n", 831 | " \n", 832 | " \n", 833 | " \n", 834 | " \n", 835 | " \n", 836 | " \n", 837 | " \n", 838 | " \n", 839 | " \n", 840 | " \n", 841 | " \n", 842 | " \n", 843 | " \n", 844 | " \n", 845 | " \n", 846 | " \n", 847 | " \n", 848 | " \n", 849 | " \n", 850 | " \n", 851 | " \n", 852 | " \n", 853 | " \n", 854 | " \n", 855 | " \n", 856 | " \n", 857 | " \n", 858 | " \n", 859 | " \n", 860 | " \n", 861 | " \n", 862 | " \n", 863 | " \n", 864 | " \n", 865 | " \n", 866 | " \n", 867 | " \n", 868 | " \n", 869 | " \n", 870 | " \n", 871 | " \n", 872 | " \n", 873 | " \n", 874 | " \n", 875 | " \n", 876 | " \n", 877 | " \n", 878 | " \n", 879 | " \n", 880 | " \n", 881 | " \n", 882 | " \n", 883 | " \n", 884 | " \n", 885 | " \n", 886 | " \n", 887 | " \n", 888 | " \n", 889 | " \n", 890 | " \n", 891 | " \n", 892 | " \n", 893 | " \n", 894 | " \n", 895 | " \n", 896 | " \n", 897 | " \n", 898 | " \n", 899 | " \n", 900 | " \n", 901 | " \n", 902 | " \n", 903 | " \n", 904 | " \n", 905 | " \n", 906 | " \n", 907 | " \n", 908 | " \n", 909 | " \n", 910 | " \n", 911 | " \n", 912 | " \n", 913 | " \n", 914 | " \n", 915 | " \n", 916 | " \n", 917 | " \n", 918 | " \n", 919 | " \n", 920 | " \n", 921 | " \n", 922 | " \n", 923 | " \n", 924 | " \n", 925 | " \n", 926 | " \n", 927 | " \n", 928 | " \n", 929 | " \n", 930 | " \n", 931 | " \n", 932 | " \n", 933 | " \n", 934 | " \n", 935 | " \n", 936 | " \n", 937 | " \n", 938 | " \n", 939 | " \n", 940 | " \n", 941 | " \n", 942 | " \n", 943 | " \n", 944 | " \n", 945 | " \n", 946 | " \n", 947 | " \n", 948 | " \n", 949 | " \n", 950 | " \n", 951 | " \n", 952 | " \n", 953 | " \n", 954 | " \n", 955 | " \n", 956 | " \n", 957 | " \n", 958 | " \n", 959 | " \n", 960 | " \n", 961 | " \n", 962 | " \n", 963 | " \n", 964 | " \n", 965 | " \n", 966 | " \n", 967 | " \n", 968 | " \n", 969 | " \n", 970 | " \n", 971 | " \n", 972 | " \n", 973 | " \n", 974 | " \n", 975 | " \n", 976 | " \n", 977 | " \n", 978 | " \n", 979 | " \n", 980 | " \n", 981 | " \n", 982 | " \n", 983 | " \n", 984 | " \n", 985 | " \n", 986 | " \n", 987 | " \n", 988 | " \n", 989 | " \n", 990 | " \n", 991 | " \n", 992 | " \n", 993 | " \n", 994 | " \n", 995 | " \n", 996 | " \n", 997 | " \n", 998 | " \n", 999 | " \n", 1000 | " \n", 1001 | " \n", 1002 | " \n", 1003 | " \n", 1004 | " \n", 1005 | " \n", 1006 | " \n", 1007 | " \n", 1008 | " \n", 1009 | " \n", 1010 | " \n", 1011 | " \n", 1012 | " \n", 1013 | " \n", 1014 | " \n", 1015 | " \n", 1016 | " \n", 1017 | " \n", 1018 | " \n", 1019 | " \n", 1020 | " \n", 1021 | " \n", 1022 | " \n", 1023 | " \n", 1024 | " \n", 1025 | " \n", 1026 | " \n", 1027 | " \n", 1028 | " \n", 1029 | " \n", 1030 | " \n", 1031 | " \n", 1032 | " \n", 1033 | " \n", 1034 | " \n", 1035 | " \n", 1036 | " \n", 1037 | " \n", 1038 | " \n", 1039 | " \n", 1040 | " \n", 1041 | " \n", 1042 | " \n", 1043 | " \n", 1044 | " \n", 1045 | " \n", 1046 | " \n", 1047 | " \n", 1048 | " \n", 1049 | " \n", 1050 | " \n", 1051 | " \n", 1052 | " \n", 1053 | " \n", 1054 | " \n", 1055 | " \n", 1056 | " \n", 1057 | " \n", 1058 | " \n", 1059 | " \n", 1060 | " \n", 1061 | " \n", 1062 | " \n", 1063 | " \n", 1064 | " \n", 1065 | " \n", 1066 | " \n", 1067 | " \n", 1068 | " \n", 1069 | " \n", 1070 | " \n", 1071 | " \n", 1072 | " \n", 1073 | " \n", 1074 | " \n", 1075 | " \n", 1076 | " \n", 1077 | " \n", 1078 | " \n", 1079 | " \n", 1080 | " \n", 1081 | " \n", 1082 | " \n", 1083 | " \n", 1084 | " \n", 1085 | " \n", 1086 | " \n", 1087 | " \n", 1088 | " \n", 1089 | " \n", 1090 | " \n", 1091 | " \n", 1092 | " \n", 1093 | " \n", 1094 | " \n", 1095 | " \n", 1096 | " \n", 1097 | " \n", 1098 | " \n", 1099 | " \n", 1100 | " \n", 1101 | " \n", 1102 | " \n", 1103 | " \n", 1104 | " \n", 1105 | " \n", 1106 | " \n", 1107 | " \n", 1108 | " \n", 1109 | " \n", 1110 | " \n", 1111 | " \n", 1112 | " \n", 1113 | " \n", 1114 | " \n", 1115 | " \n", 1116 | " \n", 1117 | " \n", 1118 | " \n", 1119 | " \n", 1120 | " \n", 1121 | " \n", 1122 | " \n", 1123 | " \n", 1124 | " \n", 1125 | " \n", 1126 | " \n", 1127 | " \n", 1128 | " \n", 1129 | " \n", 1130 | " \n", 1131 | " \n", 1132 | " \n", 1133 | " \n", 1134 | " \n", 1135 | " \n", 1136 | " \n", 1137 | " \n", 1138 | " \n", 1139 | " \n", 1140 | " \n", 1141 | " \n", 1142 | " \n", 1143 | " \n", 1144 | " \n", 1145 | " \n", 1146 | " \n", 1147 | " \n", 1148 | " \n", 1149 | " \n", 1150 | " \n", 1151 | " \n", 1152 | " \n", 1153 | " \n", 1154 | " \n", 1155 | " \n", 1156 | " \n", 1157 | " \n", 1158 | " \n", 1159 | " \n", 1160 | " \n", 1161 | " \n", 1162 | " \n", 1163 | " \n", 1164 | " \n", 1165 | " \n", 1166 | " \n", 1167 | " \n", 1168 | " \n", 1169 | " \n", 1170 | " \n", 1171 | " \n", 1172 | " \n", 1173 | " \n", 1174 | " \n", 1175 | " \n", 1176 | " \n", 1177 | " \n", 1178 | " \n", 1179 | " \n", 1180 | " \n", 1181 | " \n", 1182 | " \n", 1183 | " \n", 1184 | " \n", 1185 | " \n", 1186 | " \n", 1187 | " \n", 1188 | " \n", 1189 | " \n", 1190 | " \n", 1191 | " \n", 1192 | " \n", 1193 | " \n", 1194 | " \n", 1195 | " \n", 1196 | " \n", 1197 | " \n", 1198 | " \n", 1199 | " \n", 1200 | " \n", 1201 | " \n", 1202 | " \n", 1203 | " \n", 1204 | " \n", 1205 | " \n", 1206 | " \n", 1207 | " \n", 1208 | " \n", 1209 | " \n", 1210 | " \n", 1211 | " \n", 1212 | " \n", 1213 | " \n", 1214 | " \n", 1215 | " \n", 1216 | " \n", 1217 | " \n", 1218 | " \n", 1219 | " \n", 1220 | " \n", 1221 | " \n", 1222 | " \n", 1223 | " \n", 1224 | " \n", 1225 | " \n", 1226 | " \n", 1227 | " \n", 1228 | " \n", 1229 | " \n", 1230 | " \n", 1231 | " \n", 1232 | " \n", 1233 | " \n", 1234 | " \n", 1235 | " \n", 1236 | " \n", 1237 | " \n", 1238 | " \n", 1239 | " \n", 1240 | " \n", 1241 | " \n", 1242 | " \n", 1243 | " \n", 1244 | " \n", 1245 | " \n", 1246 | " \n", 1247 | " \n", 1248 | " \n", 1249 | " \n", 1250 | " \n", 1251 | " \n", 1252 | " \n", 1253 | " \n", 1254 | " \n", 1255 | " \n", 1256 | " \n", 1257 | " \n", 1258 | " \n", 1259 | " \n", 1260 | " \n", 1261 | " \n", 1262 | " \n", 1263 | " \n", 1264 | " \n", 1265 | " \n", 1266 | " \n", 1267 | " \n", 1268 | " \n", 1269 | " \n", 1270 | " \n", 1271 | " \n", 1272 | " \n", 1273 | " \n", 1274 | " \n", 1275 | " \n", 1276 | " \n", 1277 | " \n", 1278 | " \n", 1279 | " \n", 1280 | " \n", 1281 | " \n", 1282 | " \n", 1283 | " \n", 1284 | " \n", 1285 | " \n", 1286 | " \n", 1287 | " \n", 1288 | " \n", 1289 | " \n", 1290 | " \n", 1291 | " \n", 1292 | " \n", 1293 | " \n", 1294 | " \n", 1295 | " \n", 1296 | " \n", 1297 | " \n", 1298 | " \n", 1299 | " \n", 1300 | " \n", 1301 | " \n", 1302 | " \n", 1303 | " \n", 1304 | " \n", 1305 | " \n", 1306 | " \n", 1307 | " \n", 1308 | " \n", 1309 | " \n", 1310 | " \n", 1311 | " \n", 1312 | " \n", 1313 | " \n", 1314 | " \n", 1315 | " \n", 1316 | " \n", 1317 | " \n", 1318 | " \n", 1319 | " \n", 1320 | " \n", 1321 | " \n", 1322 | " \n", 1323 | " \n", 1324 | " \n", 1325 | " \n", 1326 | " \n", 1327 | " \n", 1328 | " \n", 1329 | " \n", 1330 | " \n", 1331 | " \n", 1332 | " \n", 1333 | " \n", 1334 | " \n", 1335 | " \n", 1336 | " \n", 1337 | " \n", 1338 | " \n", 1339 | " \n", 1340 | " \n", 1341 | " \n", 1342 | " \n", 1343 | " \n", 1344 | " \n", 1345 | " \n", 1346 | " \n", 1347 | " \n", 1348 | " \n", 1349 | " \n", 1350 | " \n", 1351 | " \n", 1352 | " \n", 1353 | " \n", 1354 | " \n", 1355 | " \n", 1356 | " \n", 1357 | " \n", 1358 | " \n", 1359 | " \n", 1360 | " \n", 1361 | " \n", 1362 | " \n", 1363 | " \n", 1364 | " \n", 1365 | " \n", 1366 | " \n", 1367 | " \n", 1368 | " \n", 1369 | " \n", 1370 | " \n", 1371 | " \n", 1372 | " \n", 1373 | " \n", 1374 | " \n", 1375 | " \n", 1376 | " \n", 1377 | " \n", 1378 | " \n", 1379 | " \n", 1380 | " \n", 1381 | " \n", 1382 | " \n", 1383 | " \n", 1384 | " \n", 1385 | " \n", 1386 | " \n", 1387 | " \n", 1388 | " \n", 1389 | " \n", 1390 | " \n", 1391 | " \n", 1392 | " \n", 1393 | " \n", 1394 | " \n", 1395 | " \n", 1396 | " \n", 1397 | " \n", 1398 | " \n", 1399 | " \n", 1400 | " \n", 1401 | " \n", 1402 | " \n", 1403 | " \n", 1404 | " \n", 1405 | " \n", 1406 | " \n", 1407 | " \n", 1408 | " \n", 1409 | " \n", 1410 | " \n", 1411 | " \n", 1412 | " \n", 1413 | " \n", 1414 | " \n", 1415 | " \n", 1416 | " \n", 1417 | " \n", 1418 | " \n", 1419 | " \n", 1420 | " \n", 1421 | " \n", 1422 | " \n", 1423 | " \n", 1424 | " \n", 1425 | " \n", 1426 | " \n", 1427 | " \n", 1428 | " \n", 1429 | " \n", 1430 | " \n", 1431 | " \n", 1432 | " \n", 1433 | " \n", 1434 | " \n", 1435 | " \n", 1436 | " \n", 1437 | " \n", 1438 | " \n", 1439 | " \n", 1440 | " \n", 1441 | " \n", 1442 | " \n", 1443 | " \n", 1444 | " \n", 1445 | " \n", 1446 | " \n", 1447 | " \n", 1448 | " \n", 1449 | " \n", 1450 | " \n", 1451 | " \n", 1452 | " \n", 1453 | " \n", 1454 | " \n", 1455 | " \n", 1456 | " \n", 1457 | " \n", 1458 | " \n", 1459 | " \n", 1460 | " \n", 1461 | " \n", 1462 | " \n", 1463 | " \n", 1464 | " \n", 1465 | " \n", 1466 | " \n", 1467 | " \n", 1468 | " \n", 1469 | " \n", 1470 | " \n", 1471 | " \n", 1472 | " \n", 1473 | " \n", 1474 | " \n", 1475 | " \n", 1476 | " \n", 1477 | " \n", 1478 | " \n", 1479 | " \n", 1480 | " \n", 1481 | " \n", 1482 | " \n", 1483 | " \n", 1484 | " \n", 1485 | " \n", 1486 | " \n", 1487 | " \n", 1488 | " \n", 1489 | " \n", 1490 | " \n", 1491 | " \n", 1492 | " \n", 1493 | " \n", 1494 | " \n", 1495 | " \n", 1496 | " \n", 1497 | " \n", 1498 | " \n", 1499 | " \n", 1500 | " \n", 1501 | " \n", 1502 | " \n", 1503 | " \n", 1504 | " \n", 1505 | " \n", 1506 | " \n", 1507 | " \n", 1508 | " \n", 1509 | " \n", 1510 | " \n", 1511 | " \n", 1512 | " \n", 1513 | " \n", 1514 | " \n", 1515 | " \n", 1516 | " \n", 1517 | " \n", 1518 | " \n", 1519 | " \n", 1520 | " \n", 1521 | " \n", 1522 | " \n", 1523 | " \n", 1524 | " \n", 1525 | " \n", 1526 | " \n", 1527 | " \n", 1528 | " \n", 1529 | " \n", 1530 | " \n", 1531 | " \n", 1532 | " \n", 1533 | " \n", 1534 | " \n", 1535 | " \n", 1536 | " \n", 1537 | " \n", 1538 | " \n", 1539 | " \n", 1540 | " \n", 1541 | " \n", 1542 | " \n", 1543 | " \n", 1544 | " \n", 1545 | " \n", 1546 | " \n", 1547 | " \n", 1548 | " \n", 1549 | " \n", 1550 | " \n", 1551 | " \n", 1552 | " \n", 1553 | " \n", 1554 | " \n", 1555 | " \n", 1556 | " \n", 1557 | " \n", 1558 | " \n", 1559 | " \n", 1560 | " \n", 1561 | " \n", 1562 | " \n", 1563 | " \n", 1564 | " \n", 1565 | " \n", 1566 | " \n", 1567 | " \n", 1568 | " \n", 1569 | " \n", 1570 | " \n", 1571 | " \n", 1572 | " \n", 1573 | " \n", 1574 | " \n", 1575 | " \n", 1576 | " \n", 1577 | " \n", 1578 | " \n", 1579 | " \n", 1580 | " \n", 1581 | " \n", 1582 | " \n", 1583 | " \n", 1584 | " \n", 1585 | " \n", 1586 | " \n", 1587 | " \n", 1588 | " \n", 1589 | " \n", 1590 | " \n", 1591 | " \n", 1592 | " \n", 1593 | " \n", 1594 | " \n", 1595 | " \n", 1596 | " \n", 1597 | " \n", 1598 | " \n", 1599 | " \n", 1600 | " \n", 1601 | " \n", 1602 | " \n", 1603 | " \n", 1604 | " \n", 1605 | " \n", 1606 | " \n", 1607 | " \n", 1608 | " \n", 1609 | " \n", 1610 | " \n", 1611 | " \n", 1612 | " \n", 1613 | " \n", 1614 | " \n", 1615 | " \n", 1616 | " \n", 1617 | " \n", 1618 | " \n", 1619 | " \n", 1620 | " \n", 1621 | " \n", 1622 | " \n", 1623 | " \n", 1624 | " \n", 1625 | " \n", 1626 | " \n", 1627 | " \n", 1628 | " \n", 1629 | " \n", 1630 | " \n", 1631 | " \n", 1632 | " \n", 1633 | " \n", 1634 | " \n", 1635 | " \n", 1636 | " \n", 1637 | " \n", 1638 | " \n", 1639 | " \n", 1640 | " \n", 1641 | " \n", 1642 | " \n", 1643 | " \n", 1644 | " \n", 1645 | " \n", 1646 | " \n", 1647 | " \n", 1648 | " \n", 1649 | " \n", 1650 | " \n", 1651 | " \n", 1652 | " \n", 1653 | " \n", 1654 | " \n", 1655 | " \n", 1656 | " \n", 1657 | " \n", 1658 | " \n", 1659 | " \n", 1660 | " \n", 1661 | " \n", 1662 | " \n", 1663 | " \n", 1664 | " \n", 1665 | " \n", 1666 | " \n", 1667 | " \n", 1668 | " \n", 1669 | " \n", 1670 | " \n", 1671 | " \n", 1672 | " \n", 1673 | " \n", 1674 | " \n", 1675 | " \n", 1676 | " \n", 1677 | " \n", 1678 | " \n", 1679 | " \n", 1680 | " \n", 1681 | " \n", 1682 | " \n", 1683 | " \n", 1684 | " \n", 1685 | " \n", 1686 | " \n", 1687 | " \n", 1688 | " \n", 1689 | " \n", 1690 | " \n", 1691 | " \n", 1692 | " \n", 1693 | " \n", 1694 | " \n", 1695 | " \n", 1696 | " \n", 1697 | " \n", 1698 | " \n", 1699 | " \n", 1700 | " \n", 1701 | " \n", 1702 | " \n", 1703 | " \n", 1704 | " \n", 1705 | " \n", 1706 | " \n", 1707 | " \n", 1708 | " \n", 1709 | " \n", 1710 | " \n", 1711 | " \n", 1712 | " \n", 1713 | " \n", 1714 | " \n", 1715 | " \n", 1716 | " \n", 1717 | " \n", 1718 | " \n", 1719 | " \n", 1720 | " \n", 1721 | " \n", 1722 | " \n", 1723 | " \n", 1724 | " \n", 1725 | " \n", 1726 | " \n", 1727 | " \n", 1728 | " \n", 1729 | " \n", 1730 | " \n", 1731 | " \n", 1732 | " \n", 1733 | " \n", 1734 | " \n", 1735 | " \n", 1736 | " \n", 1737 | " \n", 1738 | " \n", 1739 | " \n", 1740 | " \n", 1741 | " \n", 1742 | " \n", 1743 | " \n", 1744 | " \n", 1745 | " \n", 1746 | " \n", 1747 | " \n", 1748 | " \n", 1749 | " \n", 1750 | " \n", 1751 | " \n", 1752 | " \n", 1753 | " \n", 1754 | " \n", 1755 | " \n", 1756 | " \n", 1757 | " \n", 1758 | " \n", 1759 | " \n", 1760 | " \n", 1761 | " \n", 1762 | " \n", 1763 | " \n", 1764 | " \n", 1765 | " \n", 1766 | " \n", 1767 | " \n", 1768 | " \n", 1769 | " \n", 1770 | " \n", 1771 | " \n", 1772 | " \n", 1773 | " \n", 1774 | " \n", 1775 | " \n", 1776 | " \n", 1777 | " \n", 1778 | " \n", 1779 | " \n", 1780 | " \n", 1781 | " \n", 1782 | " \n", 1783 | " \n", 1784 | " \n", 1785 | " \n", 1786 | " \n", 1787 | " \n", 1788 | " \n", 1789 | " \n", 1790 | " \n", 1791 | " \n", 1792 | " \n", 1793 | " \n", 1794 | " \n", 1795 | " \n", 1796 | " \n", 1797 | " \n", 1798 | " \n", 1799 | " \n", 1800 | " \n", 1801 | " \n", 1802 | " \n", 1803 | " \n", 1804 | " \n", 1805 | " \n", 1806 | " \n", 1807 | " \n", 1808 | " \n", 1809 | " \n", 1810 | " \n", 1811 | " \n", 1812 | " \n", 1813 | " \n", 1814 | " \n", 1815 | " \n", 1816 | " \n", 1817 | " \n", 1818 | " \n", 1819 | " \n", 1820 | " \n", 1821 | " \n", 1822 | " \n", 1823 | " \n", 1824 | " \n", 1825 | " \n", 1826 | " \n", 1827 | " \n", 1828 | " \n", 1829 | " \n", 1830 | " \n", 1831 | " \n", 1832 | " \n", 1833 | " \n", 1834 | " \n", 1835 | " \n", 1836 | " \n", 1837 | " \n", 1838 | " \n", 1839 | " \n", 1840 | " \n", 1841 | " \n", 1842 | " \n", 1843 | " \n", 1844 | " \n", 1845 | " \n", 1846 | " \n", 1847 | " \n", 1848 | " \n", 1849 | " \n", 1850 | " \n", 1851 | " \n", 1852 | " \n", 1853 | " \n", 1854 | " \n", 1855 | " \n", 1856 | " \n", 1857 | " \n", 1858 | " \n", 1859 | " \n", 1860 | " \n", 1861 | " \n", 1862 | " \n", 1863 | " \n", 1864 | " \n", 1865 | " \n", 1866 | " \n", 1867 | " \n", 1868 | " \n", 1869 | " \n", 1870 | " \n", 1871 | " \n", 1872 | " \n", 1873 | " \n", 1874 | " \n", 1875 | " \n", 1876 | " \n", 1877 | " \n", 1878 | " \n", 1879 | " \n", 1880 | " \n", 1881 | " \n", 1882 | " \n", 1883 | " \n", 1884 | " \n", 1885 | " \n", 1886 | " \n", 1887 | " \n", 1888 | " \n", 1889 | " \n", 1890 | " \n", 1891 | " \n", 1892 | " \n", 1893 | " \n", 1894 | " \n", 1895 | " \n", 1896 | " \n", 1897 | " \n", 1898 | " \n", 1899 | " \n", 1900 | " \n", 1901 | " \n", 1902 | " \n", 1903 | " \n", 1904 | " \n", 1905 | " \n", 1906 | " \n", 1907 | " \n", 1908 | " \n", 1909 | " \n", 1910 | " \n", 1911 | " \n", 1912 | " \n", 1913 | " \n", 1914 | " \n", 1915 | " \n", 1916 | " \n", 1917 | " \n", 1918 | " \n", 1919 | " \n", 1920 | " \n", 1921 | " \n", 1922 | " \n", 1923 | " \n", 1924 | " \n", 1925 | " \n", 1926 | " \n", 1927 | " \n", 1928 | " \n", 1929 | " \n", 1930 | " \n", 1931 | " \n", 1932 | " \n", 1933 | " \n", 1934 | " \n", 1935 | " \n", 1936 | " \n", 1937 | " \n", 1938 | " \n", 1939 | " \n", 1940 | " \n", 1941 | " \n", 1942 | " \n", 1943 | " \n", 1944 | " \n", 1945 | " \n", 1946 | " \n", 1947 | " \n", 1948 | " \n", 1949 | " \n", 1950 | " \n", 1951 | " \n", 1952 | " \n", 1953 | " \n", 1954 | " \n", 1955 | " \n", 1956 | " \n", 1957 | " \n", 1958 | " \n", 1959 | " \n", 1960 | " \n", 1961 | " \n", 1962 | " \n", 1963 | " \n", 1964 | " \n", 1965 | " \n", 1966 | " \n", 1967 | " \n", 1968 | " \n", 1969 | " \n", 1970 | " \n", 1971 | " \n", 1972 | " \n", 1973 | " \n", 1974 | " \n", 1975 | " \n", 1976 | " \n", 1977 | " \n", 1978 | " \n", 1979 | " \n", 1980 | " \n", 1981 | " \n", 1982 | " \n", 1983 | " \n", 1984 | " \n", 1985 | " \n", 1986 | " \n", 1987 | " \n", 1988 | " \n", 1989 | " \n", 1990 | " \n", 1991 | " \n", 1992 | " \n", 1993 | " \n", 1994 | " \n", 1995 | " \n", 1996 | " \n", 1997 | " \n", 1998 | " \n", 1999 | " \n", 2000 | " \n", 2001 | " \n", 2002 | " \n", 2003 | " \n", 2004 | " \n", 2005 | " \n", 2006 | " \n", 2007 | " \n", 2008 | " \n", 2009 | " \n", 2010 | " \n", 2011 | " \n", 2012 | " \n", 2013 | " \n", 2014 | " \n", 2015 | " \n", 2016 | " \n", 2017 | " \n", 2018 | " \n", 2019 | " \n", 2020 | " \n", 2021 | " \n", 2022 | " \n", 2023 | " \n", 2024 | " \n", 2025 | " \n", 2026 | " \n", 2027 | " \n", 2028 | " \n", 2029 | " \n", 2030 | " \n", 2031 | " \n", 2032 | " \n", 2033 | " \n", 2034 | " \n", 2035 | " \n", 2036 | " \n", 2037 | " \n", 2038 | " \n", 2039 | " \n", 2040 | " \n", 2041 | " \n", 2042 | " \n", 2043 | " \n", 2044 | " \n", 2045 | " \n", 2046 | " \n", 2047 | " \n", 2048 | " \n", 2049 | " \n", 2050 | " \n", 2051 | " \n", 2052 | " \n", 2053 | " \n", 2054 | " \n", 2055 | " \n", 2056 | " \n", 2057 | " \n", 2058 | " \n", 2059 | " \n", 2060 | " \n", 2061 | " \n", 2062 | " \n", 2063 | " \n", 2064 | " \n", 2065 | " \n", 2066 | " \n", 2067 | " \n", 2068 | " \n", 2069 | " \n", 2070 | " \n", 2071 | " \n", 2072 | " \n", 2073 | " \n", 2074 | " \n", 2075 | " \n", 2076 | " \n", 2077 | " \n", 2078 | " \n", 2079 | " \n", 2080 | " \n", 2081 | " \n", 2082 | " \n", 2083 | " \n", 2084 | " \n", 2085 | " \n", 2086 | " \n", 2087 | " \n", 2088 | " \n", 2089 | " \n", 2090 | " \n", 2091 | " \n", 2092 | " \n", 2093 | " \n", 2094 | " \n", 2095 | " \n", 2096 | " \n", 2097 | " \n", 2098 | " \n", 2099 | " \n", 2100 | " \n", 2101 | " \n", 2102 | " \n", 2103 | " \n", 2104 | " \n", 2105 | " \n", 2106 | " \n", 2107 | " \n", 2108 | " \n", 2109 | " \n", 2110 | " \n", 2111 | " \n", 2112 | " \n", 2113 | " \n", 2114 | " \n", 2115 | " \n", 2116 | " \n", 2117 | " \n", 2118 | " \n", 2119 | " \n", 2120 | " \n", 2121 | " \n", 2122 | " \n", 2123 | " \n", 2124 | " \n", 2125 | " \n", 2126 | " \n", 2127 | " \n", 2128 | " \n", 2129 | " \n", 2130 | " \n", 2131 | " \n", 2132 | " \n", 2133 | " \n", 2134 | " \n", 2135 | " \n", 2136 | " \n", 2137 | " \n", 2138 | " \n", 2139 | " \n", 2140 | " \n", 2141 | " \n", 2142 | " \n", 2143 | " \n", 2144 | " \n", 2145 | " \n", 2146 | " \n", 2147 | " \n", 2148 | " \n", 2149 | " \n", 2150 | " \n", 2151 | " \n", 2152 | " \n", 2153 | " \n", 2154 | " \n", 2155 | " \n", 2156 | " \n", 2157 | " \n", 2158 | " \n", 2159 | " \n", 2160 | " \n", 2161 | " \n", 2162 | " \n", 2163 | " \n", 2164 | " \n", 2165 | " \n", 2166 | " \n", 2167 | " \n", 2168 | " \n", 2169 | " \n", 2170 | " \n", 2171 | " \n", 2172 | " \n", 2173 | " \n", 2174 | " \n", 2175 | " \n", 2176 | " \n", 2177 | " \n", 2178 | " \n", 2179 | " \n", 2180 | " \n", 2181 | " \n", 2182 | " \n", 2183 | " \n", 2184 | " \n", 2185 | " \n", 2186 | " \n", 2187 | " \n", 2188 | " \n", 2189 | " \n", 2190 | " \n", 2191 | " \n", 2192 | " \n", 2193 | " \n", 2194 | " \n", 2195 | " \n", 2196 | " \n", 2197 | " \n", 2198 | " \n", 2199 | " \n", 2200 | " \n", 2201 | " \n", 2202 | " \n", 2203 | " \n", 2204 | " \n", 2205 | " \n", 2206 | " \n", 2207 | " \n", 2208 | " \n", 2209 | " \n", 2210 | " \n", 2211 | " \n", 2212 | " \n", 2213 | " \n", 2214 | " \n", 2215 | " \n", 2216 | " \n", 2217 | " \n", 2218 | " \n", 2219 | " \n", 2220 | " \n", 2221 | " \n", 2222 | " \n", 2223 | " \n", 2224 | " \n", 2225 | " \n", 2226 | " \n", 2227 | " \n", 2228 | " \n", 2229 | " \n", 2230 | " \n", 2231 | " \n", 2232 | " \n", 2233 | " \n", 2234 | " \n", 2235 | " \n", 2236 | " \n", 2237 | " \n", 2238 | " \n", 2239 | " \n", 2240 | " \n", 2241 | " \n", 2242 | " \n", 2243 | " \n", 2244 | " \n", 2245 | " \n", 2246 | " \n", 2247 | " \n", 2248 | " \n", 2249 | " \n", 2250 | " \n", 2251 | " \n", 2252 | " \n", 2253 | " \n", 2254 | " \n", 2255 | " \n", 2256 | " \n", 2257 | " \n", 2258 | " \n", 2259 | " \n", 2260 | " \n", 2261 | " \n", 2262 | " \n", 2263 | " \n", 2264 | " \n", 2265 | " \n", 2266 | " \n", 2267 | " \n", 2268 | " \n", 2269 | " \n", 2270 | " \n", 2271 | " \n", 2272 | " \n", 2273 | " \n", 2274 | " \n", 2275 | " \n", 2276 | " \n", 2277 | " \n", 2278 | " \n", 2279 | " \n", 2280 | " \n", 2281 | " \n", 2282 | " \n", 2283 | " \n", 2284 | " \n", 2285 | " \n", 2286 | " \n", 2287 | " \n", 2288 | " \n", 2289 | " \n", 2290 | " \n", 2291 | "
0123456789...441442443444445446447448449450
06610182274...8805229934
16610182274...8805229934
26610182274...8805229934
36610182274...8885229934
46610182274...8805229934
56610182274...8805229931
66610182274...8805229934
76610182274...8805229934
86610182274...8805229934
96610182274...8805229931
106610182274...8805229931
116610182774...8805229934
126610182274...8805229934
136610182274...8805229934
146610182274...8805229934
156610182274...8805229934
166610182274...8805229934
176610182274...8805229931
186610182274...8805229934
196610182274...8805229934
206610182274...8805229934
216610182274...8805229934
225680888574...8865189955
236610182274...8805229934
246610182274...8805229934
256610182274...8805229934
266610182274...8805229934
276610182274...8805229934
286610182274...8805229934
296610182274...8805229934
..................................................................
696610182274...8805229934
706610182274...8805229934
716610182274...8805229934
725680188874...8875180915
736610182274...8805229934
746610182274...8805229934
756610182274...8805229934
766610182274...8805229934
776610182274...8805229934
786610182274...8805229934
796610182274...8805229934
806610182274...8805229934
816610182274...8805229934
826610182274...8805229934
836610182274...8805229934
846680138771...8815283931
856680198574...8845289951
866610182274...8805229934
876610182274...8805229934
886610182274...8805229934
896210112774...1155229952
906610182274...8805229934
916610182274...8805229934
926610182274...8805229934
936610182274...8805229934
946610182274...8805229934
956610182274...8805229934
966610182774...8815229934
976610182274...8805229934
986610182274...8805229934
\n", 2292 | "

99 rows × 451 columns

\n", 2293 | "
" 2294 | ], 2295 | "text/plain": [ 2296 | " 0 1 2 3 4 5 6 7 8 9 ... 441 442 443 444 \\\n", 2297 | "0 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2298 | "1 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2299 | "2 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2300 | "3 6 6 1 0 1 8 2 2 7 4 ... 8 8 8 5 \n", 2301 | "4 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2302 | "5 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2303 | "6 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2304 | "7 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2305 | "8 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2306 | "9 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2307 | "10 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2308 | "11 6 6 1 0 1 8 2 7 7 4 ... 8 8 0 5 \n", 2309 | "12 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2310 | "13 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2311 | "14 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2312 | "15 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2313 | "16 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2314 | "17 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2315 | "18 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2316 | "19 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2317 | "20 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2318 | "21 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2319 | "22 5 6 8 0 8 8 8 5 7 4 ... 8 8 6 5 \n", 2320 | "23 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2321 | "24 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2322 | "25 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2323 | "26 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2324 | "27 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2325 | "28 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2326 | "29 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2327 | ".. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... \n", 2328 | "69 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2329 | "70 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2330 | "71 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2331 | "72 5 6 8 0 1 8 8 8 7 4 ... 8 8 7 5 \n", 2332 | "73 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2333 | "74 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2334 | "75 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2335 | "76 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2336 | "77 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2337 | "78 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2338 | "79 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2339 | "80 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2340 | "81 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2341 | "82 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2342 | "83 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2343 | "84 6 6 8 0 1 3 8 7 7 1 ... 8 8 1 5 \n", 2344 | "85 6 6 8 0 1 9 8 5 7 4 ... 8 8 4 5 \n", 2345 | "86 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2346 | "87 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2347 | "88 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2348 | "89 6 2 1 0 1 1 2 7 7 4 ... 1 1 5 5 \n", 2349 | "90 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2350 | "91 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2351 | "92 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2352 | "93 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2353 | "94 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2354 | "95 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2355 | "96 6 6 1 0 1 8 2 7 7 4 ... 8 8 1 5 \n", 2356 | "97 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2357 | "98 6 6 1 0 1 8 2 2 7 4 ... 8 8 0 5 \n", 2358 | "\n", 2359 | " 445 446 447 448 449 450 \n", 2360 | "0 2 2 9 9 3 4 \n", 2361 | "1 2 2 9 9 3 4 \n", 2362 | "2 2 2 9 9 3 4 \n", 2363 | "3 2 2 9 9 3 4 \n", 2364 | "4 2 2 9 9 3 4 \n", 2365 | "5 2 2 9 9 3 1 \n", 2366 | "6 2 2 9 9 3 4 \n", 2367 | "7 2 2 9 9 3 4 \n", 2368 | "8 2 2 9 9 3 4 \n", 2369 | "9 2 2 9 9 3 1 \n", 2370 | "10 2 2 9 9 3 1 \n", 2371 | "11 2 2 9 9 3 4 \n", 2372 | "12 2 2 9 9 3 4 \n", 2373 | "13 2 2 9 9 3 4 \n", 2374 | "14 2 2 9 9 3 4 \n", 2375 | "15 2 2 9 9 3 4 \n", 2376 | "16 2 2 9 9 3 4 \n", 2377 | "17 2 2 9 9 3 1 \n", 2378 | "18 2 2 9 9 3 4 \n", 2379 | "19 2 2 9 9 3 4 \n", 2380 | "20 2 2 9 9 3 4 \n", 2381 | "21 2 2 9 9 3 4 \n", 2382 | "22 1 8 9 9 5 5 \n", 2383 | "23 2 2 9 9 3 4 \n", 2384 | "24 2 2 9 9 3 4 \n", 2385 | "25 2 2 9 9 3 4 \n", 2386 | "26 2 2 9 9 3 4 \n", 2387 | "27 2 2 9 9 3 4 \n", 2388 | "28 2 2 9 9 3 4 \n", 2389 | "29 2 2 9 9 3 4 \n", 2390 | ".. ... ... ... ... ... ... \n", 2391 | "69 2 2 9 9 3 4 \n", 2392 | "70 2 2 9 9 3 4 \n", 2393 | "71 2 2 9 9 3 4 \n", 2394 | "72 1 8 0 9 1 5 \n", 2395 | "73 2 2 9 9 3 4 \n", 2396 | "74 2 2 9 9 3 4 \n", 2397 | "75 2 2 9 9 3 4 \n", 2398 | "76 2 2 9 9 3 4 \n", 2399 | "77 2 2 9 9 3 4 \n", 2400 | "78 2 2 9 9 3 4 \n", 2401 | "79 2 2 9 9 3 4 \n", 2402 | "80 2 2 9 9 3 4 \n", 2403 | "81 2 2 9 9 3 4 \n", 2404 | "82 2 2 9 9 3 4 \n", 2405 | "83 2 2 9 9 3 4 \n", 2406 | "84 2 8 3 9 3 1 \n", 2407 | "85 2 8 9 9 5 1 \n", 2408 | "86 2 2 9 9 3 4 \n", 2409 | "87 2 2 9 9 3 4 \n", 2410 | "88 2 2 9 9 3 4 \n", 2411 | "89 2 2 9 9 5 2 \n", 2412 | "90 2 2 9 9 3 4 \n", 2413 | "91 2 2 9 9 3 4 \n", 2414 | "92 2 2 9 9 3 4 \n", 2415 | "93 2 2 9 9 3 4 \n", 2416 | "94 2 2 9 9 3 4 \n", 2417 | "95 2 2 9 9 3 4 \n", 2418 | "96 2 2 9 9 3 4 \n", 2419 | "97 2 2 9 9 3 4 \n", 2420 | "98 2 2 9 9 3 4 \n", 2421 | "\n", 2422 | "[99 rows x 451 columns]" 2423 | ] 2424 | }, 2425 | "execution_count": 475, 2426 | "metadata": {}, 2427 | "output_type": "execute_result" 2428 | } 2429 | ], 2430 | "source": [ 2431 | "pd.DataFrame(forest_predictions)" 2432 | ] 2433 | }, 2434 | { 2435 | "cell_type": "code", 2436 | "execution_count": 97, 2437 | "metadata": { 2438 | "collapsed": false 2439 | }, 2440 | "outputs": [], 2441 | "source": [ 2442 | "from sklearn import __version__" 2443 | ] 2444 | }, 2445 | { 2446 | "cell_type": "code", 2447 | "execution_count": 98, 2448 | "metadata": { 2449 | "collapsed": false 2450 | }, 2451 | "outputs": [ 2452 | { 2453 | "data": { 2454 | "text/plain": [ 2455 | "'0.17.1'" 2456 | ] 2457 | }, 2458 | "execution_count": 98, 2459 | "metadata": {}, 2460 | "output_type": "execute_result" 2461 | } 2462 | ], 2463 | "source": [ 2464 | "__version__" 2465 | ] 2466 | }, 2467 | { 2468 | "cell_type": "code", 2469 | "execution_count": null, 2470 | "metadata": { 2471 | "collapsed": true 2472 | }, 2473 | "outputs": [], 2474 | "source": [] 2475 | } 2476 | ], 2477 | "metadata": { 2478 | "anaconda-cloud": {}, 2479 | "kernelspec": { 2480 | "display_name": "Python [Root]", 2481 | "language": "python", 2482 | "name": "Python [Root]" 2483 | }, 2484 | "language_info": { 2485 | "codemirror_mode": { 2486 | "name": "ipython", 2487 | "version": 3 2488 | }, 2489 | "file_extension": ".py", 2490 | "mimetype": "text/x-python", 2491 | "name": "python", 2492 | "nbconvert_exporter": "python", 2493 | "pygments_lexer": "ipython3", 2494 | "version": "3.5.2" 2495 | } 2496 | }, 2497 | "nbformat": 4, 2498 | "nbformat_minor": 0 2499 | } 2500 | -------------------------------------------------------------------------------- /subsampling/evolved-forest - Update levels after each row's evaluation-Multi-objectives.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": false 7 | }, 8 | "source": [ 9 | "### Experiment: Single Objective Variance of True Probablity\n", 10 | "\n", 11 | "#### Aim\n", 12 | "\n", 13 | "Each row is provided as marks which will be allotted to the **individual** if it solves that row. Each row has marks = **pop_size**.\n", 14 | "\n", 15 | "If one individual solves a problem then the marks allotted to that row will decrease so that other inidividuals can focus on other rows for gaining marks. But the marks will not decresase beyond **40% of pop_size**\n", 16 | "\n", 17 | "My only concern is that in last when it becomes an ensemble will there be enough votes for the ensemble to predict?\n", 18 | "\n", 19 | "#### How does it make sure the accuracy is also increasing?\n", 20 | "\n", 21 | "\n", 22 | "#### Critism" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 1, 28 | "metadata": { 29 | "collapsed": true 30 | }, 31 | "outputs": [], 32 | "source": [ 33 | "import operator\n", 34 | "import itertools\n", 35 | "import numpy as np\n", 36 | "import seaborn as sb\n", 37 | "\n", 38 | "from deap import algorithms\n", 39 | "from deap import base\n", 40 | "from deap import creator\n", 41 | "from deap import tools\n", 42 | "from deap import gp\n", 43 | "\n", 44 | "from sklearn.tree import DecisionTreeClassifier\n", 45 | "from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier\n", 46 | "from sklearn.datasets import load_digits\n", 47 | "from sklearn.cross_validation import train_test_split\n", 48 | "\n", 49 | "import matplotlib.pyplot as plt\n", 50 | "\n", 51 | "np.seterr(all='raise')\n", 52 | "\n", 53 | "digits = load_digits()\n", 54 | "digit_features, digit_labels = digits.data, digits.target\n", 55 | "X_train, X_test, y_train, y_test = train_test_split(digit_features, digit_labels, stratify=digit_labels,train_size=0.75, test_size=0.25)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 2, 61 | "metadata": { 62 | "collapsed": false 63 | }, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "Base DecisionTreeClassifier accuracy: 0.851441241685\n", 70 | "Base RandomForestClassifier accuracy: 0.942350332594\n", 71 | "Base GradientBoostingClassifier accuracy: 0.955654101996\n", 72 | "\n" 73 | ] 74 | } 75 | ], 76 | "source": [ 77 | "# The exploration of the dataset by benchmark algorithms\n", 78 | "clf = DecisionTreeClassifier(random_state=34092)\n", 79 | "clf.fit(X_train, y_train)\n", 80 | "pred_DTC = clf.predict(X_test)\n", 81 | "print('Base DecisionTreeClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 82 | "\n", 83 | "clf = RandomForestClassifier(random_state=34092)\n", 84 | "clf.fit(X_train, y_train)\n", 85 | "pred_RFC = clf.predict(X_test)\n", 86 | "print('Base RandomForestClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 87 | "\n", 88 | "clf = GradientBoostingClassifier(random_state=34092)\n", 89 | "clf.fit(X_train, y_train)\n", 90 | "pred_GBC = clf.predict(X_test)\n", 91 | "print('Base GradientBoostingClassifier accuracy: {}'.format(clf.score(X_test, y_test)))\n", 92 | "\n", 93 | "print('')" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 3, 99 | "metadata": { 100 | "collapsed": false 101 | }, 102 | "outputs": [], 103 | "source": [ 104 | "max_marks = 100\n", 105 | "min_marks = 0.33*max_marks\n", 106 | "diff_global_marks = np.ones(y_test.shape[0])\n", 107 | "diff_global_marks = diff_global_marks*max_marks" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 4, 113 | "metadata": { 114 | "collapsed": true 115 | }, 116 | "outputs": [], 117 | "source": [ 118 | "def predict_unseen(population):\n", 119 | " forest_predictions = []\n", 120 | " for ind_num, individual in enumerate(population):\n", 121 | " func = toolbox.compile(expr=individual)\n", 122 | " \n", 123 | " \n", 124 | " sample_counts = [int(func(*record)) for record in X_train]\n", 125 | " sample_counts = [max(min(sample_count, 10), 0) for sample_count in sample_counts]\n", 126 | " sample = []\n", 127 | " for sample_index, sample_count in enumerate(sample_counts):\n", 128 | " sample.extend([sample_index] * sample_count)\n", 129 | " sample = np.array(sample)\n", 130 | "\n", 131 | " if len(sample) == 0:\n", 132 | " return 1e-20, 1e-20\n", 133 | "\n", 134 | " clf = DecisionTreeClassifier(random_state=34092)\n", 135 | " clf.fit(X_train[sample], y_train[sample])\n", 136 | " predictions = clf.predict(X_test)\n", 137 | " forest_predictions.append(predictions)\n", 138 | " \n", 139 | " from collections import Counter\n", 140 | " from sklearn.metrics import accuracy_score\n", 141 | " \n", 142 | " y_pred = np.array([Counter(instance_forest_predictions).most_common(1)[0][0] for instance_forest_predictions in zip(*forest_predictions)])\n", 143 | " #np.sum(y_test == y_pred) / len(y_test)\n", 144 | " print \"Accuracy->\"+str(np.sum(y_test == y_pred)*100/ len(y_test))" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 5, 150 | "metadata": { 151 | "collapsed": false 152 | }, 153 | "outputs": [], 154 | "source": [ 155 | "# defined a new primitive set for strongly typed GP\n", 156 | "pset = gp.PrimitiveSetTyped('MAIN', itertools.repeat(float, digit_features.shape[1]), bool, 'Feature')\n", 157 | "\n", 158 | "# boolean operators\n", 159 | "pset.addPrimitive(operator.and_, [bool, bool], bool)\n", 160 | "pset.addPrimitive(operator.or_, [bool, bool], bool)\n", 161 | "pset.addPrimitive(operator.not_, [bool], bool)\n", 162 | "\n", 163 | "# floating point operators\n", 164 | "# Define a protected division function\n", 165 | "def protectedDiv(left, right):\n", 166 | " try: return left / right\n", 167 | " except (ZeroDivisionError, FloatingPointError): return 1.\n", 168 | "\n", 169 | "pset.addPrimitive(operator.add, [float, float], float)\n", 170 | "pset.addPrimitive(operator.sub, [float, float], float)\n", 171 | "pset.addPrimitive(operator.mul, [float, float], float)\n", 172 | "pset.addPrimitive(protectedDiv, [float, float], float)\n", 173 | "\n", 174 | "# logic operators\n", 175 | "# Define a new if-then-else function\n", 176 | "def if_then_else(in1, output1, output2):\n", 177 | " if in1: return output1\n", 178 | " else: return output2\n", 179 | "\n", 180 | "pset.addPrimitive(operator.lt, [float, float], bool)\n", 181 | "pset.addPrimitive(operator.eq, [float, float], bool)\n", 182 | "pset.addPrimitive(if_then_else, [bool, float, float], float)\n", 183 | "\n", 184 | "# terminals\n", 185 | "pset.addTerminal(False, bool)\n", 186 | "pset.addTerminal(True, bool)\n", 187 | "for val in np.arange(-10., 11.):\n", 188 | " pset.addTerminal(val, float)\n", 189 | "\n", 190 | "creator.create('FitnessMax', base.Fitness, weights=(1.0, 1.0))\n", 191 | "creator.create('Individual', gp.PrimitiveTree, fitness=creator.FitnessMax)\n", 192 | "\n", 193 | "toolbox = base.Toolbox()\n", 194 | "toolbox.register('expr', gp.genHalfAndHalf, pset=pset, min_=1, max_=3)\n", 195 | "toolbox.register('individual', tools.initIterate, creator.Individual, toolbox.expr)\n", 196 | "toolbox.register('population', tools.initRepeat, list, toolbox.individual)\n", 197 | "toolbox.register('compile', gp.compile, pset=pset)" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 6, 203 | "metadata": { 204 | "collapsed": true 205 | }, 206 | "outputs": [], 207 | "source": [ 208 | "def evaluate_individual(individual):\n", 209 | " global diff_global_marks\n", 210 | " # Transform the tree expression into a callable function\n", 211 | " func = toolbox.compile(expr=individual)\n", 212 | " \n", 213 | " sample_counts = [int(func(*record)) for record in X_train]\n", 214 | " sample_counts = [max(min(sample_count, 10), 0) for sample_count in sample_counts]\n", 215 | " sample = []\n", 216 | " for sample_index, sample_count in enumerate(sample_counts):\n", 217 | " sample.extend([sample_index] * sample_count)\n", 218 | " sample = np.array(sample)\n", 219 | " \n", 220 | " if len(sample) == 0:\n", 221 | " return 1e-20, 1e-20\n", 222 | " \n", 223 | " clf = DecisionTreeClassifier(random_state=34092)\n", 224 | " clf.fit(X_train[sample], y_train[sample])\n", 225 | " #score = clf.score(X_test, y_test)\n", 226 | " t_pred = clf.predict(X_test)\n", 227 | " total_marks = np.sum((t_pred==y_test)*diff_global_marks)\n", 228 | " accuracy = np.sum((t_pred==y_test))\n", 229 | " \n", 230 | " # Updating the diff_marks\n", 231 | " bool_ = 1*(t_pred==y_test)\n", 232 | " diff_global_marks = diff_global_marks-bool_\n", 233 | " diff_global_marks[diff_global_marks94\n", 371 | "60 \t100 \t4905.95\t44 \t4571.13\t12804\n", 372 | "100\n", 373 | "61 \t100 \t4842.22\t1e-20\t4526.76\t12804\n", 374 | "100\n", 375 | "62 \t100 \t4856.34\t1e-20\t4492.76\t12738\n", 376 | "100\n", 377 | "63 \t100 \t4820.22\t1e-20\t4526.59\t12771\n", 378 | "100\n", 379 | "64 \t100 \t4878.99\t1e-20\t4410.82\t12771\n", 380 | "100\n", 381 | "65 \t100 \t4849.8 \t1e-20\t4148.17\t12804\n", 382 | "100\n", 383 | "66 \t100 \t4882.3 \t1e-20\t4139.67\t12837\n", 384 | "100\n", 385 | "67 \t100 \t4560.35\t1e-20\t3737.45\t12870\n", 386 | "100\n", 387 | "68 \t100 \t4436.52\t1e-20\t3687.13\t12870\n", 388 | "100\n", 389 | "69 \t100 \t4564.05\t1e-20\t3831.97\t12705\n", 390 | "100\n", 391 | "70 \t100 \t4574.68\t1e-20\t3576.8 \t12672\n", 392 | "100\n", 393 | "71 \t100 \t4540.07\t1e-20\t3693.93\t12705\n", 394 | "100\n", 395 | "72 \t100 \t4491.23\t1e-20\t3462.9 \t12936\n", 396 | "100\n", 397 | "73 \t100 \t4492.62\t1e-20\t3756.49\t12936\n", 398 | "100\n", 399 | "74 \t100 \t4319.84\t1e-20\t3503.19\t12936\n", 400 | "100\n", 401 | "75 \t100 \t4229.23\t1e-20\t3209.6 \t12936\n", 402 | "100\n", 403 | "76 \t100 \t4172.69\t1e-20\t3108.28\t12936\n", 404 | "100\n", 405 | "77 \t100 \t4066.68\t1e-20\t2929.95\t12672\n", 406 | "100\n", 407 | "78 \t100 \t4087.76\t1e-20\t2879.12\t12672\n", 408 | "100\n", 409 | "79 \t100 \t4156.32\t1e-20\t2807.04\t12672\n", 410 | "100\n", 411 | "80 \t100 \t3914.17\t1e-20\t2542.69\t12870\n", 412 | "100\n", 413 | "81 \t100 \t3759.1 \t1e-20\t2315.4 \t12672\n", 414 | "100\n", 415 | "82 \t100 \t4021.36\t1e-20\t2645.71\t12672\n", 416 | "100\n", 417 | "83 \t100 \t4202.02\t1e-20\t3084.65\t12672\n", 418 | "100\n", 419 | "84 \t100 \t3988.59\t1e-20\t2885.07\t12837\n", 420 | "100\n", 421 | "85 \t100 \t3641.16\t1e-20\t2606.78\t12837\n", 422 | "100\n", 423 | "86 \t100 \t3342.05\t1e-20\t2305.88\t12903\n", 424 | "100\n", 425 | "87 \t100 \t3553.17\t1e-20\t2358.41\t12672\n", 426 | "100\n", 427 | "88 \t100 \t3719.91\t1e-20\t2378.81\t12672\n", 428 | "100\n", 429 | "89 \t100 \t3808.91\t1e-20\t2518.04\t12672\n", 430 | "100\n", 431 | "90 \t100 \t4203.15\t1e-20\t2821.49\t12672\n", 432 | "100\n", 433 | "91 \t100 \t3982.32\t1e-20\t2442.05\t12672\n", 434 | "100\n", 435 | "92 \t100 \t3972.39\t1e-20\t2344.3 \t12672\n", 436 | "100\n", 437 | "93 \t100 \t3735.17\t1e-20\t2094.57\t12771\n", 438 | "100\n", 439 | "94 \t100 \t3811.62\t1e-20\t2279.87\t12672\n", 440 | "100\n", 441 | "95 \t100 \t3569.64\t1e-20\t2213.74\t12837\n", 442 | "100\n", 443 | "96 \t100 \t3579.59\t1e-20\t2242.3 \t12672\n", 444 | "100\n", 445 | "97 \t100 \t3549.97\t1e-20\t2201.84\t12672\n", 446 | "100\n", 447 | "98 \t100 \t3638.23\t1e-20\t2374.39\t12870\n", 448 | "100\n", 449 | "99 \t100 \t3785.66\t1e-20\t2575.16\t12705\n", 450 | "100\n", 451 | "100\t100 \t3599.07\t1e-20\t2327.47\t12705\n" 452 | ] 453 | }, 454 | { 455 | "ename": "SyntaxError", 456 | "evalue": "'return' outside function (, line 76)", 457 | "output_type": "error", 458 | "traceback": [ 459 | "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m76\u001b[0m\n\u001b[1;33m return population, logbook\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m 'return' outside function\n" 460 | ] 461 | } 462 | ], 463 | "source": [ 464 | "toolbox.register('evaluate', evaluate_individual)\n", 465 | "#toolbox.register('select', tools.selTournament, tournsize=3)\n", 466 | "toolbox.register(\"select\", tools.selNSGA2)\n", 467 | "toolbox.register('mate', gp.cxOnePoint)\n", 468 | "toolbox.register('expr_mut', gp.genFull, min_=0, max_=3)\n", 469 | "toolbox.register('mutate', gp.mutUniform, expr=toolbox.expr_mut, pset=pset)\n", 470 | "\n", 471 | "population = toolbox.population(n=max_marks)\n", 472 | "halloffame = tools.HallOfFame(1)\n", 473 | "stats = tools.Statistics(lambda ind: ind.fitness.values)\n", 474 | "stats.register('std', np.std)\n", 475 | "stats.register('min', np.min)\n", 476 | "stats.register('avg', np.mean)\n", 477 | "stats.register('max', np.max)\n", 478 | "\n", 479 | "cxpb = 0.5\n", 480 | "mutpb = 0.5\n", 481 | "lambda_ = 100\n", 482 | "mu = max_marks\n", 483 | "ngen = 100\n", 484 | "verbose = True\n", 485 | "\n", 486 | "logbook = tools.Logbook()\n", 487 | "logbook.header = ['gen', 'nevals'] + (stats.fields if stats else [])\n", 488 | "\n", 489 | "\n", 490 | "# Evaluate the individuals with an invalid fitness\n", 491 | "invalid_ind = [ind for ind in population if not ind.fitness.valid]\n", 492 | "fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)\n", 493 | "for ind, fit in zip(invalid_ind, fitnesses):\n", 494 | " ind.fitness.values = fit\n", 495 | "\n", 496 | "if halloffame is not None:\n", 497 | " halloffame.update(population)\n", 498 | "\n", 499 | "logbook = tools.Logbook()\n", 500 | "logbook.header = ['gen', 'nevals'] + (stats.fields if stats else [])\n", 501 | "\n", 502 | "record = stats.compile(population) if stats is not None else {}\n", 503 | "logbook.record(gen=0, nevals=len(invalid_ind), **record)\n", 504 | "if verbose:\n", 505 | " print logbook.stream\n", 506 | "\n", 507 | "# Begin the generational process\n", 508 | "global diff_global_marks\n", 509 | "all_marks = []\n", 510 | "all_marks.append(diff_global_marks)\n", 511 | "\n", 512 | "for gen in range(1, ngen + 1):\n", 513 | " # Vary the population\n", 514 | " offspring = algorithms.varOr(population, toolbox, lambda_, cxpb, mutpb)\n", 515 | "\n", 516 | " # Evaluate the individuals with an invalid fitness\n", 517 | " invalid_ind = [ind for ind in offspring if not ind.fitness.valid]\n", 518 | " fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)\n", 519 | " for ind, fit in zip(invalid_ind, fitnesses):\n", 520 | " ind.fitness.values = fit\n", 521 | "\n", 522 | " # Update the hall of fame with the generated individuals\n", 523 | " if halloffame is not None:\n", 524 | " halloffame.update(offspring)\n", 525 | "\n", 526 | " # Select the next generation population\n", 527 | " population[:] = toolbox.select(offspring, mu)\n", 528 | " print len(population)\n", 529 | " predict_unseen(population)\n", 530 | " \n", 531 | " # Just updating the all_marks array which has all the changed values\n", 532 | " all_marks.append(diff_global_marks)\n", 533 | " \n", 534 | " # Update the statistics with the new population\n", 535 | " record = stats.compile(population) if stats is not None else {}\n", 536 | " logbook.record(gen=gen, nevals=len(invalid_ind), **record)\n", 537 | " if verbose:\n", 538 | " print logbook.stream\n", 539 | " #return population, logbook\n", 540 | "\n", 541 | "str(halloffame[0])" 542 | ] 543 | }, 544 | { 545 | "cell_type": "code", 546 | "execution_count": 13, 547 | "metadata": { 548 | "collapsed": false 549 | }, 550 | "outputs": [ 551 | { 552 | "ename": "NameError", 553 | "evalue": "name 'sample' is not defined", 554 | "output_type": "error", 555 | "traceback": [ 556 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 557 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 558 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0msample\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 559 | "\u001b[1;31mNameError\u001b[0m: name 'sample' is not defined" 560 | ] 561 | } 562 | ], 563 | "source": [] 564 | }, 565 | { 566 | "cell_type": "code", 567 | "execution_count": null, 568 | "metadata": { 569 | "collapsed": true 570 | }, 571 | "outputs": [], 572 | "source": [ 573 | "marks = pd.DataFrame(all_marks[0])" 574 | ] 575 | }, 576 | { 577 | "cell_type": "code", 578 | "execution_count": null, 579 | "metadata": { 580 | "collapsed": false 581 | }, 582 | "outputs": [], 583 | "source": [ 584 | "marks.columns = [str(1)]" 585 | ] 586 | }, 587 | { 588 | "cell_type": "code", 589 | "execution_count": null, 590 | "metadata": { 591 | "collapsed": false 592 | }, 593 | "outputs": [], 594 | "source": [ 595 | "marks_ = pd.DataFrame()\n", 596 | "for i in range(0,len(all_marks)):\n", 597 | " if(i==0):\n", 598 | " marks_ = pd.DataFrame(all_marks[0])\n", 599 | " else:\n", 600 | " if(type(all_marks[i])!=float):\n", 601 | " temp_ = pd.DataFrame(all_marks[i])\n", 602 | " temp_.columns = [i]\n", 603 | " marks_ = pd.concat([marks_,temp_],axis=1)" 604 | ] 605 | }, 606 | { 607 | "cell_type": "code", 608 | "execution_count": null, 609 | "metadata": { 610 | "collapsed": false 611 | }, 612 | "outputs": [], 613 | "source": [ 614 | "%matplotlib inline" 615 | ] 616 | }, 617 | { 618 | "cell_type": "code", 619 | "execution_count": null, 620 | "metadata": { 621 | "collapsed": false 622 | }, 623 | "outputs": [], 624 | "source": [ 625 | "plt.plot(marks_[0])" 626 | ] 627 | }, 628 | { 629 | "cell_type": "code", 630 | "execution_count": null, 631 | "metadata": { 632 | "collapsed": false 633 | }, 634 | "outputs": [], 635 | "source": [ 636 | "forest_predictions = []\n", 637 | "\n", 638 | "for ind_num, individual in enumerate(population):\n", 639 | " func = toolbox.compile(expr=individual)\n", 640 | " subsample = np.array([func(*record) for record in X_train])\n", 641 | " \n", 642 | " if X_train[subsample].shape[0] == 0:\n", 643 | " continue\n", 644 | " \n", 645 | " clf = DecisionTreeClassifier(random_state=34092)\n", 646 | " clf.fit(X_train[subsample], y_train[subsample])\n", 647 | " predictions = clf.predict(X_test)\n", 648 | " forest_predictions.append(predictions)" 649 | ] 650 | }, 651 | { 652 | "cell_type": "code", 653 | "execution_count": null, 654 | "metadata": { 655 | "collapsed": false, 656 | "scrolled": false 657 | }, 658 | "outputs": [], 659 | "source": [ 660 | "from collections import Counter\n", 661 | "from sklearn.metrics import accuracy_score\n", 662 | "\n", 663 | "y_pred = np.array(\n", 664 | " [Counter(instance_forest_predictions).most_common(1)[0][0] for instance_forest_predictions in zip(*forest_predictions)])\n", 665 | "#np.sum(y_test == y_pred) / len(y_test)\n", 666 | "np.sum(y_test == y_pred)*100/ len(y_test)" 667 | ] 668 | }, 669 | { 670 | "cell_type": "code", 671 | "execution_count": null, 672 | "metadata": { 673 | "collapsed": false 674 | }, 675 | "outputs": [], 676 | "source": [ 677 | "func = toolbox.compile(expr=halloffame[0])\n", 678 | "subsample = np.array([func(*record) for record in X_train])" 679 | ] 680 | }, 681 | { 682 | "cell_type": "code", 683 | "execution_count": null, 684 | "metadata": { 685 | "collapsed": false 686 | }, 687 | "outputs": [], 688 | "source": [ 689 | "subsample" 690 | ] 691 | }, 692 | { 693 | "cell_type": "code", 694 | "execution_count": null, 695 | "metadata": { 696 | "collapsed": false 697 | }, 698 | "outputs": [], 699 | "source": [ 700 | "print halloffame[0]" 701 | ] 702 | }, 703 | { 704 | "cell_type": "code", 705 | "execution_count": 22, 706 | "metadata": { 707 | "collapsed": false 708 | }, 709 | "outputs": [ 710 | { 711 | "data": { 712 | "text/plain": [ 713 | "1" 714 | ] 715 | }, 716 | "execution_count": 22, 717 | "metadata": {}, 718 | "output_type": "execute_result" 719 | } 720 | ], 721 | "source": [ 722 | "chk" 723 | ] 724 | }, 725 | { 726 | "cell_type": "code", 727 | "execution_count": 15, 728 | "metadata": { 729 | "collapsed": false 730 | }, 731 | "outputs": [ 732 | { 733 | "ename": "SyntaxError", 734 | "evalue": "unexpected EOF while parsing (, line 1)", 735 | "output_type": "error", 736 | "traceback": [ 737 | "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m type(Integer((0.5*100))\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n" 738 | ] 739 | } 740 | ], 741 | "source": [ 742 | "(0.5*100)" 743 | ] 744 | }, 745 | { 746 | "cell_type": "code", 747 | "execution_count": 21, 748 | "metadata": { 749 | "collapsed": false 750 | }, 751 | "outputs": [], 752 | "source": [ 753 | "chk = 1;\n" 754 | ] 755 | }, 756 | { 757 | "cell_type": "code", 758 | "execution_count": null, 759 | "metadata": { 760 | "collapsed": true 761 | }, 762 | "outputs": [], 763 | "source": [] 764 | } 765 | ], 766 | "metadata": { 767 | "kernelspec": { 768 | "display_name": "Python 2", 769 | "language": "python", 770 | "name": "python2" 771 | }, 772 | "language_info": { 773 | "codemirror_mode": { 774 | "name": "ipython", 775 | "version": 2 776 | }, 777 | "file_extension": ".py", 778 | "mimetype": "text/x-python", 779 | "name": "python", 780 | "nbconvert_exporter": "python", 781 | "pygments_lexer": "ipython2", 782 | "version": "2.7.9" 783 | } 784 | }, 785 | "nbformat": 4, 786 | "nbformat_minor": 0 787 | } 788 | -------------------------------------------------------------------------------- /subspacing/dataset_describe.py: -------------------------------------------------------------------------------- 1 | """ 2 | Methods to describe attriubutes in a dataset. The last column 3 | of a dataset is assumed to be the dependent variable. 4 | 5 | Methods range from but not restricted to: 6 | - Description of dataset as a whole 7 | - Description of individual attributes 8 | - Description of inter-relation between attributes. 9 | 10 | Contact: Harsh Nisar GH: harshnisar 11 | """ 12 | 13 | import pandas as pd 14 | import numpy as np 15 | from sklearn.preprocessing import OneHotEncoder, LabelEncoder 16 | from sklearn.decomposition import PCA 17 | 18 | from scipy.stats import kurtosis, skew 19 | class Dataset: 20 | """ 21 | Initialize the dataset and give user the option to set some 22 | defaults eg. names of categorical columns 23 | 24 | All public methods will provide one value per dataset. 25 | Private methods are for internal use. 26 | 27 | prediction_type = {'regression'|'classification'} 28 | """ 29 | df = None 30 | df_encoded = None 31 | categorical_cols = None 32 | dependent_col = None 33 | prediction_type = None 34 | independent_col = None 35 | def __init__(self, df, prediction_type = None, dependent_col = None,categorical_cols = None): 36 | 37 | self.df = df 38 | self._set_dependent_col(dependent_col) 39 | self._set_categorical_columns(categorical_cols) 40 | self._set_prediction_type(prediction_type) 41 | 42 | self.independent_col = list(set(self.df.columns.tolist()) - set([self.dependent_col])) 43 | self._categorical_column_encoder() 44 | 45 | 46 | def _set_dependent_col(self, dependent_col): 47 | """ if nothing given, set the last column in the frame as 48 | the dependent column.""" 49 | 50 | if dependent_col == None: 51 | self.dependent_col = self.df.columns.tolist()[-1] 52 | elif dependent_col in self.df.columns.tolist(): 53 | self.dependent_col = dependent_col 54 | else: 55 | raise ValueError 56 | 57 | def _set_prediction_type(self, prediction_type): 58 | """ See the dtype of the dependent_col and return 59 | either regression or classification 60 | """ 61 | if prediction_type == None: 62 | if self.dependent_col in self.df._get_numeric_data().columns.tolist(): 63 | self.prediction_type = 'regression' 64 | else: 65 | self.prediction_type = 'classification' 66 | else: 67 | self.prediction_type = prediction_type 68 | 69 | def _set_categorical_columns(self, categorical_cols): 70 | #TODO: Need to test if the columns exist in the df 71 | #TODO: Add logic in case user doesn't specify the cols 72 | if categorical_cols == None: 73 | num_cols = self.df._get_numeric_data().columns 74 | cat_cols = list(set(self.df.columns) - set(num_cols) - set([self.dependent_col])) 75 | self.categorical_cols = cat_cols 76 | ## empty list in case of no categorical columns or categorical columns are 77 | ## already label encoded, as in the case of Randal's data. 78 | ## Assumption: In case of pre-processed data, all columns would be preprocessed 79 | ## and not just some. Hence, proceed with heuristics only if previous code 80 | ## gave zero categorical_cols 81 | # print cat_cols 82 | if cat_cols == []: 83 | possible_cat_cols = [] 84 | threshold_unique = 0.001*self.df.shape[0] 85 | # print threshold_unique 86 | for col in list(set(self.df.columns) - set([self.dependent_col])): 87 | unique_col = list(self.df[col].unique()) 88 | unique_col.sort() 89 | # print col, len(unique_col) 90 | if len(unique_col) < threshold_unique: 91 | possible_cat_cols.append(col) 92 | continue 93 | # print unique_col == range(0, len(unique_col), 1) 94 | # print isinstance(self.df[col][0], np.integer) 95 | # If unique values represent intergers from 0 to N, then there 96 | # is a high chance they were LabelEncoded using sklearn. 97 | # This heaveily relies on the way experiment datasets were encoded. 98 | # Not recommended for normal usage. 99 | 100 | if ((unique_col == range(0, len(unique_col), 1)) & (isinstance(self.df.iloc[0][col], np.integer))): 101 | possible_cat_cols.append(col) 102 | continue 103 | self.categorical_cols = list(set(possible_cat_cols)) 104 | else: 105 | self.categorical_cols = categorical_cols 106 | 107 | 108 | def _categorical_column_encoder(self): 109 | """ Assumes all categorical variables are nominal and not 110 | ordinal """ 111 | categorical_cols = self.categorical_cols 112 | 113 | self.df_encoded = self.df.copy() 114 | 115 | for col in categorical_cols: 116 | if len(self.df_encoded[col].unique())<=2: 117 | #this means, binary :- LabelEncode 118 | self.df_encoded[col] = LabelEncoder().fit_transform(self.df_encoded[col]) 119 | else: 120 | # nominal - so make dummy" 121 | self.df_encoded = pd.get_dummies(self.df_encoded, columns=[col]) 122 | 123 | 124 | def n_rows(self): 125 | return self.df.shape[0] 126 | 127 | def n_columns(self): 128 | """ Including dependent variable """ 129 | return self.df.shape[1] 130 | 131 | def ratio_rowcol(self): 132 | """ rows/col including dependent variable """ 133 | return self.df.shape[0]/self.df.shape[1] 134 | 135 | def n_categorical(self): 136 | """number of categorical variables excluding the dependent.""" 137 | #todo: can be converted to ratio by total number of columns. 138 | return len(self.categorical_cols) 139 | 140 | def n_numerical(self): 141 | """number of categorical variables excluding the dependent.""" 142 | #todo: can be converted to ratio by total number of columns. 143 | return self.n_columns() - self.n_categorical() - 1 144 | 145 | def n_classes(self): 146 | """number of classes in the dependent columns. Only applicable 147 | for classfication problems. Returns NaN otherwise """ 148 | 149 | if self.prediction_type == 'classification': 150 | return len(self.df[self.dependent_col].unique()) 151 | else: 152 | return np.nan 153 | 154 | ## Post-encoding dimensional stats. 155 | #todo: n_cols_post_encoding 156 | #todo: ratop_rowcol_post_encoding 157 | 158 | 159 | #---------------------------------------------------------------------- 160 | # Correlation related 161 | corr_with_dependent = None 162 | 163 | def _get_corr_with_dependent(self): 164 | """Called from init. Sets up data for correlation related meta-features. 165 | #todo: take-call - Should I make different classes/modules for 166 | different types of meta-features? Eg. Correlation, Entropy""" 167 | 168 | #Correlation with dependent variable only make sense for regression problems 169 | if self.prediction_type == 'regression': 170 | if self.corr_with_dependent!=None: 171 | return self.corr_with_dependent 172 | else: 173 | self.corr_with_dependent = self.df_encoded.corr()[self.dependent_col] 174 | self.corr_with_dependent = self.corr_with_dependent.loc[self.corr_with_dependent.index!=self.dependent_col] 175 | return self.corr_with_dependent 176 | 177 | def corr_with_dependent_abs_max(self): 178 | """ max absolute pearson correlation with dependent variable 179 | returns np.nan for classificaiton problems. Uses df_encoded 180 | ie dataframe with categorical columns encoded automatically. 181 | """ 182 | if self.prediction_type == 'classification': 183 | return np.nan 184 | else: 185 | abs_corr_with_dependent = self._get_corr_with_dependent().abs() 186 | return abs_corr_with_dependent.max() 187 | 188 | def corr_with_dependent_abs_min(self): 189 | """ min absolute pearson correlation with dependent variable 190 | returns np.nan for classificaiton problems. Uses df_encoded 191 | ie dataframe with categorical columns encoded automatically. 192 | """ 193 | if self.prediction_type == 'classification': 194 | return np.nan 195 | else: 196 | abs_corr_with_dependent = self._get_corr_with_dependent().abs() 197 | return abs_corr_with_dependent.min() 198 | 199 | 200 | def corr_with_dependent_abs_mean(self): 201 | """ mean absolute pearson correlation with dependent variable 202 | returns np.nan for classificaiton problems. Uses df_encoded 203 | ie dataframe with categorical columns encoded automatically. 204 | """ 205 | if self.prediction_type == 'classification': 206 | return np.nan 207 | else: 208 | abs_corr_with_dependent = self._get_corr_with_dependent().abs() 209 | return abs_corr_with_dependent.mean() 210 | 211 | def corr_with_dependent_abs_median(self): 212 | """ median absolute pearson correlation with dependent variable 213 | returns np.nan for classificaiton problems. Uses df_encoded 214 | ie dataframe with categorical columns encoded automatically. 215 | """ 216 | if self.prediction_type == 'classification': 217 | return np.nan 218 | else: 219 | abs_corr_with_dependent = self._get_corr_with_dependent().abs() 220 | return abs_corr_with_dependent.median() 221 | 222 | 223 | 224 | def corr_with_dependent_abs_std(self): 225 | """ std absolute pearson correlation with dependent variable 226 | returns np.nan for classificaiton problems. Uses df_encoded 227 | ie dataframe with categorical columns encoded automatically. 228 | """ 229 | if self.prediction_type == 'classification': 230 | return np.nan 231 | else: 232 | abs_corr_with_dependent = self._get_corr_with_dependent().abs() 233 | return abs_corr_with_dependent.std(ddof = 1) 234 | 235 | 236 | 237 | def corr_with_dependent_abs_25p(self): 238 | """ 25p absolute pearson correlation with dependent variable 239 | returns np.nan for classificaiton problems. Uses df_encoded 240 | ie dataframe with categorical columns encoded automatically. 241 | """ 242 | if self.prediction_type == 'classification': 243 | return np.nan 244 | else: 245 | abs_corr_with_dependent = self._get_corr_with_dependent().abs() 246 | return np.nanpercentile(abs_corr_with_dependent, 25) 247 | 248 | 249 | 250 | def corr_with_dependent_abs_75p(self): 251 | """ 75p absolute pearson correlation with dependent variable 252 | returns np.nan for classificaiton problems. Uses df_encoded 253 | ie dataframe with categorical columns encoded automatically. 254 | """ 255 | if self.prediction_type == 'classification': 256 | return np.nan 257 | else: 258 | abs_corr_with_dependent = self._get_corr_with_dependent().abs() 259 | return np.nanpercentile(abs_corr_with_dependent, 75) 260 | 261 | #todo: try kurtosis and skew for correl values without abs. 262 | 263 | def corr_with_dependent_abs_kurtosis(self): 264 | """ kurtosis of absolute pearson correlation with dependent variable 265 | returns np.nan for classificaiton problems. Uses df_encoded 266 | ie dataframe with categorical columns encoded automatically. 267 | """ 268 | from scipy.stats import kurtosis 269 | if self.prediction_type == 'classification': 270 | return np.nan 271 | else: 272 | abs_corr_with_dependent = self._get_corr_with_dependent().abs() 273 | return kurtosis(abs_corr_with_dependent, bias = False) 274 | 275 | def corr_with_dependent_abs_skew(self): 276 | """ skew of absolute pearson correlation with dependent variable 277 | returns np.nan for classificaiton problems. Uses df_encoded 278 | ie dataframe with categorical columns encoded automatically. 279 | """ 280 | if self.prediction_type == 'classification': 281 | return np.nan 282 | else: 283 | abs_corr_with_dependent = self._get_corr_with_dependent().abs() 284 | return skew(abs_corr_with_dependent, bias = False) 285 | 286 | #---------------------------------------------------------------------- 287 | # Class probablity related 288 | class_probablities = None 289 | def _get_class_probablity(self): 290 | if self.class_probablities is None: 291 | dependent_col = self.df[self.dependent_col] 292 | class_counts = dependent_col.value_counts() 293 | self.class_probablities = class_counts/self.n_rows() 294 | return self.class_probablities 295 | else: 296 | return self.class_probablities 297 | 298 | def class_prob_min(self): 299 | if self.prediction_type=='regression': 300 | return np.nan 301 | else: 302 | class_probablities = self._get_class_probablity() 303 | return class_probablities.min() 304 | 305 | def class_prob_max(self): 306 | if self.prediction_type=='regression': 307 | return np.nan 308 | else: 309 | class_probablities = self._get_class_probablity() 310 | return class_probablities.max() 311 | 312 | def class_prob_std(self): 313 | if self.prediction_type=='regression': 314 | return np.nan 315 | else: 316 | class_probablities = self._get_class_probablity() 317 | return class_probablities.std(ddof = 1) 318 | 319 | def class_prob_mean(self): 320 | if self.prediction_type=='regression': 321 | return np.nan 322 | else: 323 | class_probablities = self._get_class_probablity() 324 | return class_probablities.mean() 325 | 326 | def class_prob_median(self): 327 | if self.prediction_type=='regression': 328 | return np.nan 329 | else: 330 | class_probablities = self._get_class_probablity() 331 | return class_probablities.median() 332 | 333 | #todo: add kurtosis and skew here too. Classes will be usually less, so 334 | #may not make sense. 335 | 336 | 337 | #---------------------------------------------------------------------- 338 | # Symbols related - All the categorical columns 339 | 340 | symbol_counts_dict = None 341 | def _get_symbols_per_category(self): 342 | """ 343 | Sets an dictionary with number of symbols per categorical 344 | column using categorical_cols info. 345 | """ 346 | 347 | 348 | if self.symbol_counts_dict == None: 349 | self.symbol_counts_dict = {} 350 | for column in self.categorical_cols: 351 | self.symbol_counts_dict[column] = self.df[column].dropna().unique().shape[0] 352 | return self.symbol_counts_dict 353 | else: 354 | return self.symbol_counts_dict 355 | 356 | def symbols_mean(self): 357 | """ Average symbols per columns """ 358 | 359 | symbol_counts_dict = self._get_symbols_per_category() 360 | ## None is for checking empty, no categorical columns 361 | 362 | if not symbol_counts_dict: 363 | return np.nan 364 | symbol_counts = symbol_counts_dict.values() 365 | 366 | return np.nanmean(symbol_counts) 367 | 368 | 369 | def symbols_std(self): 370 | """ std of symbols per columns """ 371 | symbol_counts_dict = self._get_symbols_per_category() 372 | ## None is for checking empty, no categorical columns 373 | if not symbol_counts_dict: 374 | return np.nan 375 | symbol_counts = symbol_counts_dict.values() 376 | 377 | return np.nanstd(symbol_counts, ddof = 1) 378 | 379 | 380 | def symbols_min(self): 381 | """ Average symbols per columns """ 382 | symbol_counts_dict = self._get_symbols_per_category() 383 | ## None is for checking empty, no categorical columns 384 | if not symbol_counts_dict: 385 | return np.nan 386 | symbol_counts = symbol_counts_dict.values() 387 | 388 | return np.min(symbol_counts) 389 | 390 | def symbols_max(self): 391 | """ Average symbols per columns """ 392 | symbol_counts_dict = self._get_symbols_per_category() 393 | ## None is for checking empty, no categorical columns 394 | 395 | if not symbol_counts_dict: 396 | return np.nan 397 | symbol_counts = symbol_counts_dict.values() 398 | 399 | return np.max(symbol_counts) 400 | 401 | def symbols_sum(self): 402 | """ Sum of symbols per column """ 403 | symbol_counts_dict = self._get_symbols_per_category() 404 | ## None is for checking empty, no categorical columns 405 | if not symbol_counts_dict: 406 | return np.nan 407 | 408 | symbol_counts = symbol_counts_dict.values() 409 | 410 | return np.sum(symbol_counts) 411 | 412 | def symbols_skew(self): 413 | from scipy.stats import skew 414 | symbol_counts_dict = self._get_symbols_per_category() 415 | ## None is for checking empty, no categorical columns 416 | if not symbol_counts_dict: 417 | return np.nan 418 | 419 | symbol_counts = symbol_counts_dict.values() 420 | 421 | return skew(symbol_counts, bias = False) 422 | 423 | def symbols_kurtosis(self): 424 | from scipy.stats import kurtosis 425 | symbol_counts_dict = self._get_symbols_per_category() 426 | ## None is for checking empty, no categorical columns 427 | if not symbol_counts_dict: 428 | return np.nan 429 | 430 | symbol_counts = symbol_counts_dict.values() 431 | 432 | return kurtosis(symbol_counts, bias = False) 433 | 434 | 435 | 436 | 437 | ##todo: Note we can evaluate symbol probabilities too. 438 | 439 | #---------------------------------------------------------------------- 440 | # Kustosis related - For all non-categorical columns 441 | kurtosis_dict = None 442 | def _get_kurtosis_per_num_column(self): 443 | """Sets an dictionary with kurtosis per numerical column""" 444 | 445 | if self.kurtosis_dict == None: 446 | self.kurtosis_dict = {} 447 | numerical_cols = list(set(self.independent_col) - set(self.categorical_cols)) 448 | for column in numerical_cols: 449 | self.kurtosis_dict[column] = kurtosis(self.df[column].dropna(), bias = False) 450 | return self.kurtosis_dict 451 | else: 452 | return self.kurtosis_dict 453 | 454 | def kurtosis_mean(self): 455 | """ Mean kurtosis per columns """ 456 | 457 | kurtosis_dict = self._get_kurtosis_per_num_column() 458 | ## None is for checking empty, no categorical columns 459 | 460 | if not kurtosis_dict: 461 | return np.nan 462 | 463 | kurtosisses = kurtosis_dict.values() 464 | 465 | return np.nanmean(kurtosisses) 466 | 467 | def kurtosis_median(self): 468 | """ Median kurtosis per columns """ 469 | 470 | kurtosis_dict = self._get_kurtosis_per_num_column() 471 | ## None is for checking empty, no categorical columns 472 | 473 | if not kurtosis_dict: 474 | return np.nan 475 | 476 | kurtosisses = kurtosis_dict.values() 477 | 478 | return np.nanmedian(kurtosisses) 479 | 480 | 481 | def kurtosis_min(self): 482 | """ Min kurtosis per columns """ 483 | 484 | kurtosis_dict = self._get_kurtosis_per_num_column() 485 | ## None is for checking empty, no categorical columns 486 | 487 | if not kurtosis_dict: 488 | return np.nan 489 | 490 | kurtosisses = kurtosis_dict.values() 491 | 492 | return np.min(kurtosisses) 493 | 494 | 495 | def kurtosis_max(self): 496 | """ Max kurtosis per columns """ 497 | 498 | kurtosis_dict = self._get_kurtosis_per_num_column() 499 | ## None is for checking empty, no categorical columns 500 | 501 | if not kurtosis_dict: 502 | return np.nan 503 | 504 | kurtosisses = kurtosis_dict.values() 505 | 506 | return np.max(kurtosisses) 507 | 508 | 509 | def kurtosis_std(self): 510 | """ STD of kurtosis per columns """ 511 | 512 | kurtosis_dict = self._get_kurtosis_per_num_column() 513 | ## None is for checking empty, no categorical columns 514 | 515 | if not kurtosis_dict: 516 | return np.nan 517 | 518 | kurtosisses = kurtosis_dict.values() 519 | 520 | return np.nanstd(kurtosisses) 521 | 522 | 523 | def kurtosis_kurtosis(self): 524 | """ Kurtosis of kurtosis per columns """ 525 | 526 | kurtosis_dict = self._get_kurtosis_per_num_column() 527 | ## None is for checking empty, no categorical columns 528 | 529 | if not kurtosis_dict: 530 | return np.nan 531 | 532 | kurtosisses = kurtosis_dict.values() 533 | 534 | return kurtosis(kurtosisses, bias = False) 535 | 536 | 537 | def kurtosis_skew(self): 538 | """ skew of kurtosis per columns """ 539 | 540 | kurtosis_dict = self._get_kurtosis_per_num_column() 541 | ## None is for checking empty, no categorical columns 542 | 543 | if not kurtosis_dict: 544 | return np.nan 545 | 546 | kurtosisses = kurtosis_dict.values() 547 | 548 | return skew(kurtosisses, bias = False) 549 | 550 | #---------------------------------------------------------------------- 551 | # Skew related - For all non-categorical columns 552 | 553 | skew_dict = None 554 | def _get_skew_per_num_column(self): 555 | """Sets an dictionary with skew measure per numerical column""" 556 | 557 | if self.skew_dict == None: 558 | self.skew_dict = {} 559 | numerical_cols = list(set(self.independent_col) - set(self.categorical_cols)) 560 | for column in numerical_cols: 561 | self.skew_dict[column] = skew(self.df[column].dropna(), bias = False) 562 | return self.skew_dict 563 | else: 564 | return self.skew_dict 565 | 566 | def skew_mean(self): 567 | """ Mean skew in all numerical columns """ 568 | 569 | skew_dict = self._get_skew_per_num_column() 570 | ## None is for checking empty, no categorical columns 571 | 572 | if not skew_dict: 573 | return np.nan 574 | 575 | skews = skew_dict.values() 576 | 577 | return np.nanmean(skews) 578 | 579 | 580 | 581 | def skew_median(self): 582 | """ Median skew in all numerical columns """ 583 | 584 | skew_dict = self._get_skew_per_num_column() 585 | ## None is for checking empty, no categorical columns 586 | 587 | if not skew_dict: 588 | return np.nan 589 | 590 | skews = skew_dict.values() 591 | 592 | return np.nanmedian(skews) 593 | 594 | 595 | 596 | def skew_min(self): 597 | """ Min skew in all numerical columns """ 598 | 599 | skew_dict = self._get_skew_per_num_column() 600 | ## None is for checking empty, no categorical columns 601 | 602 | if not skew_dict: 603 | return np.nan 604 | 605 | skews = skew_dict.values() 606 | 607 | return np.min(skews) 608 | 609 | 610 | def skew_max(self): 611 | """ Min skew in all numerical columns """ 612 | 613 | skew_dict = self._get_skew_per_num_column() 614 | ## None is for checking empty, no categorical columns 615 | 616 | if not skew_dict: 617 | return np.nan 618 | 619 | skews = skew_dict.values() 620 | 621 | return np.max(skews) 622 | 623 | 624 | def skew_std(self): 625 | """ std skew in all numerical columns """ 626 | 627 | skew_dict = self._get_skew_per_num_column() 628 | ## None is for checking empty, no categorical columns 629 | 630 | if not skew_dict: 631 | return np.nan 632 | 633 | skews = skew_dict.values() 634 | 635 | return np.nanstd(skews) 636 | 637 | 638 | def skew_kurtosis(self): 639 | """ kurtosis of skew in all numerical columns """ 640 | 641 | skew_dict = self._get_skew_per_num_column() 642 | ## None is for checking empty, no categorical columns 643 | 644 | if not skew_dict: 645 | return np.nan 646 | 647 | skews = skew_dict.values() 648 | 649 | return kurtosis(skews, bias = False) 650 | 651 | def skew_skew(self): 652 | """ skew of skew in all numerical columns """ 653 | 654 | skew_dict = self._get_skew_per_num_column() 655 | ## None is for checking empty, no categorical columns 656 | 657 | if not skew_dict: 658 | return np.nan 659 | 660 | skews = skew_dict.values() 661 | 662 | return skew(skews, bias = False) 663 | 664 | 665 | 666 | #---------------------------------------------------------------------- 667 | # PCA 668 | 669 | _pca_components = None 670 | 671 | def _get_pca_components(self): 672 | """ Should work on dataframe with categorical variables encoded""" 673 | if self._pca_components != False: 674 | try: 675 | clf = PCA(copy = True) 676 | 677 | clf.fit(self.df_encoded[self.df_encoded.columns.drop(self.dependent_col)]) 678 | self._pca_components = clf 679 | return self._pca_components 680 | except Exception, e: 681 | print e.message, '\t Could not process PCA' 682 | self._pca_components = False 683 | return self._pca_components 684 | else: 685 | return self._pca_components 686 | 687 | 688 | def pca_fraction_95(self): 689 | pca_compenents = self._get_pca_components() 690 | 691 | if pca_compenents!=False: 692 | sum_variance = 0 693 | min_idx = 0 694 | for idx, ratio in enumerate(pca_compenents.explained_variance_ratio_): 695 | sum_variance = sum_variance + ratio 696 | min_idx = min_idx + 1 697 | if sum_variance >= 0.95: 698 | return float(min_idx)/len(pca_compenents.explained_variance_ratio_) 699 | else: 700 | continue 701 | return 1 702 | 703 | else: 704 | return np.nan 705 | 706 | #TODO: in effect, mean, max, min, std etc stats can be done on the variance explained ratios. 707 | # I feel they will be useful. 708 | 709 | #---------------------------------------------------------------------- 710 | # Entropy of the dependent variable - Classification 711 | 712 | def entropy_dependent(self): 713 | """ Only for Classification problems for now """ 714 | 715 | if self.prediction_type == 'classification': 716 | class_probablities = self._get_class_probablity() 717 | entropy_bench = -1 * class_probablities * np.log(class_probablities) 718 | entropy = entropy_bench.sum() 719 | self.entropy_ = entropy 720 | return entropy 721 | 722 | else: 723 | return np.nan 724 | 725 | 726 | 727 | def diversity_fraction(self): 728 | """ Only for Classification problems for now """ 729 | 730 | if self.prediction_type == 'classification': 731 | class_probablities = self._get_class_probablity() 732 | entropy_bench = -1 * class_probablities * np.log(class_probablities) 733 | entropy = entropy_bench.sum() 734 | 735 | diversity = np.e**entropy 736 | diversity_fraction = diversity/class_probablities.shape[0] 737 | return diversity_fraction 738 | else: 739 | return np.nan 740 | 741 | #TODO: Can do plain diveristy too without any normalization. 742 | -------------------------------------------------------------------------------- /subspacing/dataset_describe.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EvoML/evolved-forests/7572d5bcf38cfed643bcd42f9f3461aa7b102f17/subspacing/dataset_describe.pyc --------------------------------------------------------------------------------