Scikit-Learn 0.19 expects lists in Pipelines, not tuples
This commit is contained in:
@@ -1035,11 +1035,11 @@
|
|||||||
" polybig_features = PolynomialFeatures(degree=degree, include_bias=False)\n",
|
" polybig_features = PolynomialFeatures(degree=degree, include_bias=False)\n",
|
||||||
" std_scaler = StandardScaler()\n",
|
" std_scaler = StandardScaler()\n",
|
||||||
" lin_reg = LinearRegression()\n",
|
" lin_reg = LinearRegression()\n",
|
||||||
" polynomial_regression = Pipeline((\n",
|
" polynomial_regression = Pipeline([\n",
|
||||||
" (\"poly_features\", polybig_features),\n",
|
" (\"poly_features\", polybig_features),\n",
|
||||||
" (\"std_scaler\", std_scaler),\n",
|
" (\"std_scaler\", std_scaler),\n",
|
||||||
" (\"lin_reg\", lin_reg),\n",
|
" (\"lin_reg\", lin_reg),\n",
|
||||||
" ))\n",
|
" ])\n",
|
||||||
" polynomial_regression.fit(X, y)\n",
|
" polynomial_regression.fit(X, y)\n",
|
||||||
" y_newbig = polynomial_regression.predict(X_new)\n",
|
" y_newbig = polynomial_regression.predict(X_new)\n",
|
||||||
" plt.plot(X_new, y_newbig, style, label=str(degree), linewidth=width)\n",
|
" plt.plot(X_new, y_newbig, style, label=str(degree), linewidth=width)\n",
|
||||||
@@ -1148,10 +1148,10 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"from sklearn.pipeline import Pipeline\n",
|
"from sklearn.pipeline import Pipeline\n",
|
||||||
"\n",
|
"\n",
|
||||||
"polynomial_regression = Pipeline((\n",
|
"polynomial_regression = Pipeline([\n",
|
||||||
" (\"poly_features\", PolynomialFeatures(degree=10, include_bias=False)),\n",
|
" (\"poly_features\", PolynomialFeatures(degree=10, include_bias=False)),\n",
|
||||||
" (\"lin_reg\", LinearRegression()),\n",
|
" (\"lin_reg\", LinearRegression()),\n",
|
||||||
" ))\n",
|
" ])\n",
|
||||||
"\n",
|
"\n",
|
||||||
"plot_learning_curves(polynomial_regression, X, y)\n",
|
"plot_learning_curves(polynomial_regression, X, y)\n",
|
||||||
"plt.axis([0, 80, 0, 3]) # not shown\n",
|
"plt.axis([0, 80, 0, 3]) # not shown\n",
|
||||||
@@ -1209,11 +1209,11 @@
|
|||||||
" for alpha, style in zip(alphas, (\"b-\", \"g--\", \"r:\")):\n",
|
" for alpha, style in zip(alphas, (\"b-\", \"g--\", \"r:\")):\n",
|
||||||
" model = model_class(alpha, **model_kargs) if alpha > 0 else LinearRegression()\n",
|
" model = model_class(alpha, **model_kargs) if alpha > 0 else LinearRegression()\n",
|
||||||
" if polynomial:\n",
|
" if polynomial:\n",
|
||||||
" model = Pipeline((\n",
|
" model = Pipeline([\n",
|
||||||
" (\"poly_features\", PolynomialFeatures(degree=10, include_bias=False)),\n",
|
" (\"poly_features\", PolynomialFeatures(degree=10, include_bias=False)),\n",
|
||||||
" (\"std_scaler\", StandardScaler()),\n",
|
" (\"std_scaler\", StandardScaler()),\n",
|
||||||
" (\"regul_reg\", model),\n",
|
" (\"regul_reg\", model),\n",
|
||||||
" ))\n",
|
" ])\n",
|
||||||
" model.fit(X, y)\n",
|
" model.fit(X, y)\n",
|
||||||
" y_new_regul = model.predict(X_new)\n",
|
" y_new_regul = model.predict(X_new)\n",
|
||||||
" lw = 2 if alpha > 0 else 1\n",
|
" lw = 2 if alpha > 0 else 1\n",
|
||||||
@@ -1444,10 +1444,10 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"X_train, X_val, y_train, y_val = train_test_split(X[:50], y[:50].ravel(), test_size=0.5, random_state=10)\n",
|
"X_train, X_val, y_train, y_val = train_test_split(X[:50], y[:50].ravel(), test_size=0.5, random_state=10)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"poly_scaler = Pipeline((\n",
|
"poly_scaler = Pipeline([\n",
|
||||||
" (\"poly_features\", PolynomialFeatures(degree=90, include_bias=False)),\n",
|
" (\"poly_features\", PolynomialFeatures(degree=90, include_bias=False)),\n",
|
||||||
" (\"std_scaler\", StandardScaler()),\n",
|
" (\"std_scaler\", StandardScaler()),\n",
|
||||||
" ))\n",
|
" ])\n",
|
||||||
"\n",
|
"\n",
|
||||||
"X_train_poly_scaled = poly_scaler.fit_transform(X_train)\n",
|
"X_train_poly_scaled = poly_scaler.fit_transform(X_train)\n",
|
||||||
"X_val_poly_scaled = poly_scaler.transform(X_val)\n",
|
"X_val_poly_scaled = poly_scaler.transform(X_val)\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user