Created
April 19, 2016 19:13
-
-
Save rhiever/c1ca759456410cad3dda06ca80cd72b6 to your computer and use it in GitHub Desktop.
How to create TPOT individuals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Creating TPOT pipelines by hand is tricky, so I recommend using the following technique." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[<deap.gp.Primitive at 0x1139a5c28>, <deap.gp.Terminal at 0x1139a6a68>]" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from tpot import TPOT\n", | |
"\n", | |
"# Create a TPOT object with a fixed random_state so it is reproducible\n", | |
"my_tpot = TPOT(random_state=42)\n", | |
"\n", | |
"# Create a new TPOT individual\n", | |
"individual = my_tpot._toolbox.individual()\n", | |
"individual" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'_robust_scaler(ARG0)'" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# String representation of that individual\n", | |
"str(individual)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'_random_forest(_knnc(_random_forest(ARG0, 93), sub(13, 31)), add(add(68, 57), add(54, 23)))'" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Keep creating new TPOT individuals until a good test case is generated\n", | |
"while 'random_forest' not in str(individual):\n", | |
" individual = my_tpot._toolbox.individual()\n", | |
"\n", | |
"str(individual)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'_binarizer(_random_forest(_polynomial_features(ARG0), add(15, 58)), _div(mul(27, 82), mul(76, 2)))'" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Another example\n", | |
"while 'random_forest' not in str(individual) or 'polynomial_features' not in str(individual):\n", | |
" individual = my_tpot._toolbox.individual()\n", | |
"\n", | |
"str(individual)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment