Created
July 7, 2016 14:00
-
-
Save mtzl/262b902ae96e469485214de76bab5797 to your computer and use it in GitHub Desktop.
This file contains 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": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"from sklearn import datasets\n", | |
"from sklearn.model_selection import MultiModelSearch\n", | |
"\n", | |
"#iris = datasets.load_iris()\n", | |
"#X = iris.data\n", | |
"#y = iris.target\n", | |
"X, y = datasets.make_moons(n_samples=1000, noise=0.5)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"from sklearn.ensemble import (ExtraTreesClassifier, RandomForestClassifier, \n", | |
" AdaBoostClassifier, GradientBoostingClassifier)\n", | |
"from sklearn.svm import SVC\n", | |
"\n", | |
"models = { \n", | |
" 'ExtraTreesClassifier': ExtraTreesClassifier(),\n", | |
" 'RandomForestClassifier': RandomForestClassifier(),\n", | |
" 'AdaBoostClassifier': AdaBoostClassifier(),\n", | |
" 'GradientBoostingClassifier': GradientBoostingClassifier(),\n", | |
" 'SVC': SVC(),\n", | |
"}\n", | |
"\n", | |
"param_sets = { \n", | |
" 'ExtraTreesClassifier': { 'n_estimators': [16, 32] },\n", | |
" 'RandomForestClassifier': { 'n_estimators': [16, 32] },\n", | |
" 'AdaBoostClassifier': { 'n_estimators': [16, 32] },\n", | |
" 'GradientBoostingClassifier': { 'n_estimators': [16, 32], 'learning_rate': [0.8, 1.0] },\n", | |
" 'SVC': [\n", | |
" {'kernel': ['linear'], 'C': [1, 10]},\n", | |
" {'kernel': ['rbf'], 'C': [1, 10], 'gamma': [0.001, 0.0001]},\n", | |
" ]\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"AdaBoostClassifier(algorithm='SAMME.R', base_estimator=None,\n", | |
" learning_rate=1.0, n_estimators=16, random_state=None)\n" | |
] | |
} | |
], | |
"source": [ | |
"multi_grid = MultiModelSearch(models, param_sets, \n", | |
" scoring='accuracy', n_jobs=-1,\n", | |
" )\n", | |
"multi_grid.fit(X, y)\n", | |
"\n", | |
"print(multi_grid.best_estimator_)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'AdaBoostClassifier': {'param_n_estimators': masked_array(data = [16 32],\n", | |
" mask = [False False],\n", | |
" fill_value = ?),\n", | |
" 'params': ({'n_estimators': 16}, {'n_estimators': 32}),\n", | |
" 'test_mean_score': array([ 0.803, 0.796]),\n", | |
" 'test_rank_score': array([1, 2], dtype=int32),\n", | |
" 'test_split0_score': array([ 0.81736527, 0.79341317]),\n", | |
" 'test_split1_score': array([ 0.79640719, 0.7994012 ]),\n", | |
" 'test_split2_score': array([ 0.79518072, 0.79518072]),\n", | |
" 'test_std_score': array([ 0.01018532, 0.00251428])},\n", | |
" 'ExtraTreesClassifier': {'param_n_estimators': masked_array(data = [16 32],\n", | |
" mask = [False False],\n", | |
" fill_value = ?),\n", | |
" 'params': ({'n_estimators': 16}, {'n_estimators': 32}),\n", | |
" 'test_mean_score': array([ 0.779, 0.772]),\n", | |
" 'test_rank_score': array([1, 2], dtype=int32),\n", | |
" 'test_split0_score': array([ 0.79041916, 0.79041916]),\n", | |
" 'test_split1_score': array([ 0.76946108, 0.75449102]),\n", | |
" 'test_split2_score': array([ 0.77710843, 0.77108434]),\n", | |
" 'test_std_score': array([ 0.00866785, 0.01469645])},\n", | |
" 'GradientBoostingClassifier': {'param_learning_rate': masked_array(data = [0.8 0.8 1.0 1.0],\n", | |
" mask = [False False False False],\n", | |
" fill_value = ?),\n", | |
" 'param_n_estimators': masked_array(data = [16 32 16 32],\n", | |
" mask = [False False False False],\n", | |
" fill_value = ?),\n", | |
" 'params': ({'learning_rate': 0.8, 'n_estimators': 16},\n", | |
" {'learning_rate': 0.8, 'n_estimators': 32},\n", | |
" {'learning_rate': 1.0, 'n_estimators': 16},\n", | |
" {'learning_rate': 1.0, 'n_estimators': 32}),\n", | |
" 'test_mean_score': array([ 0.791, 0.766, 0.775, 0.759]),\n", | |
" 'test_rank_score': array([1, 3, 2, 4], dtype=int32),\n", | |
" 'test_split0_score': array([ 0.77844311, 0.77844311, 0.7754491 , 0.76047904]),\n", | |
" 'test_split1_score': array([ 0.7754491 , 0.75449102, 0.77844311, 0.75449102]),\n", | |
" 'test_split2_score': array([ 0.81927711, 0.76506024, 0.77108434, 0.76204819]),\n", | |
" 'test_std_score': array([ 0.01997249, 0.00981057, 0.00301949, 0.00325668])},\n", | |
" 'RandomForestClassifier': {'param_n_estimators': masked_array(data = [16 32],\n", | |
" mask = [False False],\n", | |
" fill_value = ?),\n", | |
" 'params': ({'n_estimators': 16}, {'n_estimators': 32}),\n", | |
" 'test_mean_score': array([ 0.779, 0.783]),\n", | |
" 'test_rank_score': array([2, 1], dtype=int32),\n", | |
" 'test_split0_score': array([ 0.79341317, 0.79341317]),\n", | |
" 'test_split1_score': array([ 0.76347305, 0.76946108]),\n", | |
" 'test_split2_score': array([ 0.78012048, 0.78614458]),\n", | |
" 'test_std_score': array([ 0.01226069, 0.01003608])},\n", | |
" 'SVC': {'param_C': masked_array(data = [1 10 1 1 10 10],\n", | |
" mask = [False False False False False False],\n", | |
" fill_value = ?),\n", | |
" 'param_gamma': masked_array(data = [-- -- 0.001 0.0001 0.001 0.0001],\n", | |
" mask = [ True True False False False False],\n", | |
" fill_value = ?),\n", | |
" 'param_kernel': masked_array(data = ['linear' 'linear' 'rbf' 'rbf' 'rbf' 'rbf'],\n", | |
" mask = [False False False False False False],\n", | |
" fill_value = ?),\n", | |
" 'params': ({'C': 1, 'kernel': 'linear'},\n", | |
" {'C': 10, 'kernel': 'linear'},\n", | |
" {'C': 1, 'gamma': 0.001, 'kernel': 'rbf'},\n", | |
" {'C': 1, 'gamma': 0.0001, 'kernel': 'rbf'},\n", | |
" {'C': 10, 'gamma': 0.001, 'kernel': 'rbf'},\n", | |
" {'C': 10, 'gamma': 0.0001, 'kernel': 'rbf'}),\n", | |
" 'test_mean_score': array([ 0.799, 0.799, 0.769, 0.773, 0.789, 0.77 ]),\n", | |
" 'test_rank_score': array([1, 1, 6, 4, 3, 5], dtype=int32),\n", | |
" 'test_split0_score': array([ 0.79041916, 0.79041916, 0.74850299, 0.78143713, 0.77844311,\n", | |
" 0.74850299]),\n", | |
" 'test_split1_score': array([ 0.80239521, 0.80239521, 0.77844311, 0.75748503, 0.79640719,\n", | |
" 0.78143713]),\n", | |
" 'test_split2_score': array([ 0.80421687, 0.80421687, 0.78012048, 0.78012048, 0.79216867,\n", | |
" 0.78012048]),\n", | |
" 'test_std_score': array([ 0.00612197, 0.00612197, 0.01453145, 0.01100033, 0.00767349,\n", | |
" 0.01523296])}}" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"multi_grid._results" | |
] | |
} | |
], | |
"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