Created
September 23, 2015 08:30
-
-
Save anonymous/95b65991e96f5361404c 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": 7, | |
"metadata": { | |
"collapsed": false, | |
"scrolled": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[mean: 0.95960, std: 0.03299, params: {'rf__n_estimators': 10},\n", | |
" mean: 0.95973, std: 0.04439, params: {'rf__n_estimators': 100}]" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from sklearn.base import BaseEstimator, TransformerMixin\n", | |
"from sklearn.datasets import load_iris\n", | |
"from sklearn.ensemble import RandomForestClassifier\n", | |
"from sklearn.grid_search import GridSearchCV\n", | |
"from sklearn.pipeline import Pipeline\n", | |
"\n", | |
"iris = load_iris()\n", | |
"\n", | |
"X = iris[\"data\"]\n", | |
"y = iris[\"target\"]\n", | |
"\n", | |
"class DummyTransformer(BaseEstimator, TransformerMixin):\n", | |
" def fit(self, X, y=None):\n", | |
" return self\n", | |
" def transform(self, X):\n", | |
" return X\n", | |
"\n", | |
"cv = GridSearchCV(estimator=Pipeline(steps=[('dummy', DummyTransformer()),\n", | |
" ('rf', RandomForestClassifier())]),\n", | |
" param_grid={\"rf__n_estimators\": [10, 100]},\n", | |
" scoring=\"f1_weighted\",\n", | |
" cv=10,\n", | |
" n_jobs=2) # n_jobs = 1 works fine, but setting n_jobs = 2 makes the script run forever... :-(\n", | |
"cv.fit(X, y)\n", | |
"\n", | |
"cv.grid_scores_" | |
] | |
} | |
], | |
"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.4.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment