Skip to content

Commit

Permalink
minor polish on pipeline stuff, use bunch instead of dictionary on na…
Browse files Browse the repository at this point in the history
…med_steps
  • Loading branch information
amueller committed May 3, 2018
1 parent 0259ecc commit c417bda
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions notebooks/02 Pipelines.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
" # iterate over all but the final step\n",
" # transform the data\n",
" X_transformed = step[1].transform(X_transformed)\n",
" # fit the last step\n",
" # predict using the last step\n",
" return self.steps[-1][1].predict(X_transformed)"
]
},
Expand Down Expand Up @@ -313,7 +313,7 @@
"# fit the pipeline defined above to the cancer dataset\n",
"pipe.fit(cancer.data)\n",
"# extract the first two principal components from the \"pca\" step\n",
"components = pipe.named_steps[\"pca\"].components_\n",
"components = pipe.named_steps.pca.components_\n",
"print(components.shape)"
]
},
Expand Down Expand Up @@ -380,16 +380,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(grid.best_estimator_.named_steps[\"logisticregression\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(grid.best_estimator_.named_steps[\"logisticregression\"].coef_)"
"print(grid.best_estimator_.named_steps.logisticregression)"
]
},
{
Expand All @@ -398,7 +389,7 @@
"metadata": {},
"outputs": [],
"source": [
"grid.best_estimator_.named_steps.logisticregression.coef_"
"print(grid.best_estimator_.named_steps.logisticregression.coef_)"
]
},
{
Expand Down Expand Up @@ -524,9 +515,7 @@
"metadata": {},
"outputs": [],
"source": [
"param_grid = [{'regressor': [DecisionTreeRegressor()], 'regressor__max_depth': [2, 3, 4]},\n",
" {'regressor': [Ridge()], 'regressor__alpha': [0.1, 1]}\n",
" ]"
"grid.best_params_"
]
},
{
Expand All @@ -535,7 +524,9 @@
"metadata": {},
"outputs": [],
"source": [
"grid.best_params_"
"param_grid = [{'regressor': [DecisionTreeRegressor()], 'regressor__max_depth': [2, 3, 4]},\n",
" {'regressor': [Ridge()], 'regressor__alpha': [0.1, 1]}\n",
" ]"
]
},
{
Expand All @@ -544,7 +535,7 @@
"source": [
"# Exercise\n",
"\n",
"Load the bike dataset from notebook 1. Create a pipline using one-hot-encoding, scaling, and polynomial features and a linear regression model (like ridge or lasso).\n",
"Load the adult. Create a pipline using scaling, and polynomial features and a linear classifier.\n",
"\n",
"Search over the best options for the polynomial features together with the regularization of a linear model."
]
Expand Down Expand Up @@ -574,7 +565,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
"version": "3.6.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit c417bda

Please sign in to comment.