Skip to content

Commit

Permalink
Set dual=True in LinearSVC and LinearSVR to avoid warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ageron committed Nov 14, 2023
1 parent de0eb33 commit a5baa85
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions 05_support_vector_machines.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,13 @@
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note: the default value for the `dual` hyperparameter of the `LinearSVC` and `LinearSVR` estimators will change from `True` to `\"auto\"` in Scikit-Learn 1.4, so I set `dual=True` throughout this notebook to ensure the output of this notebook remains unchanged."
]
},
{
"cell_type": "code",
"execution_count": 8,
Expand Down Expand Up @@ -387,7 +394,7 @@
"y = (iris.target == 2) # Iris virginica\n",
"\n",
"svm_clf = make_pipeline(StandardScaler(),\n",
" LinearSVC(C=1, random_state=42))\n",
" LinearSVC(C=1, dual=True, random_state=42))\n",
"svm_clf.fit(X, y)"
]
},
Expand Down Expand Up @@ -454,8 +461,8 @@
"# extra code – this cell generates and saves Figure 5–4\n",
"\n",
"scaler = StandardScaler()\n",
"svm_clf1 = LinearSVC(C=1, max_iter=10_000, random_state=42)\n",
"svm_clf2 = LinearSVC(C=100, max_iter=10_000, random_state=42)\n",
"svm_clf1 = LinearSVC(C=1, max_iter=10_000, dual=True, random_state=42)\n",
"svm_clf2 = LinearSVC(C=100, max_iter=10_000, dual=True, random_state=42)\n",
"\n",
"scaled_svm_clf1 = make_pipeline(scaler, svm_clf1)\n",
"scaled_svm_clf2 = make_pipeline(scaler, svm_clf2)\n",
Expand Down Expand Up @@ -595,7 +602,7 @@
"polynomial_svm_clf = make_pipeline(\n",
" PolynomialFeatures(degree=3),\n",
" StandardScaler(),\n",
" LinearSVC(C=10, max_iter=10_000, random_state=42)\n",
" LinearSVC(C=10, max_iter=10_000, dual=True, random_state=42)\n",
")\n",
"polynomial_svm_clf.fit(X, y)"
]
Expand Down Expand Up @@ -932,7 +939,7 @@
"y = 4 + 3 * X[:, 0] + np.random.randn(50)\n",
"\n",
"svm_reg = make_pipeline(StandardScaler(),\n",
" LinearSVR(epsilon=0.5, random_state=42))\n",
" LinearSVR(epsilon=0.5, dual=True, random_state=42))\n",
"svm_reg.fit(X, y)"
]
},
Expand Down Expand Up @@ -978,7 +985,7 @@
" plt.axis(axes)\n",
"\n",
"svm_reg2 = make_pipeline(StandardScaler(),\n",
" LinearSVR(epsilon=1.2, random_state=42))\n",
" LinearSVR(epsilon=1.2, dual=True, random_state=42))\n",
"svm_reg2.fit(X, y)\n",
"\n",
"svm_reg._support = find_support_vectors(svm_reg, X, y)\n",
Expand Down Expand Up @@ -1566,7 +1573,7 @@
"scaler = StandardScaler()\n",
"X_scaled = scaler.fit_transform(X)\n",
"\n",
"lin_clf = LinearSVC(loss=\"hinge\", C=C, random_state=42).fit(X_scaled, y)\n",
"lin_clf = LinearSVC(loss=\"hinge\", C=C, dual=True, random_state=42).fit(X_scaled, y)\n",
"svc_clf = SVC(kernel=\"linear\", C=C).fit(X_scaled, y)\n",
"sgd_clf = SGDClassifier(alpha=alpha, random_state=42).fit(X_scaled, y)"
]
Expand Down Expand Up @@ -1975,7 +1982,7 @@
}
],
"source": [
"lin_clf = LinearSVC(random_state=42)\n",
"lin_clf = LinearSVC(dual=True, random_state=42)\n",
"lin_clf.fit(X_train, y_train)"
]
},
Expand Down Expand Up @@ -2011,7 +2018,7 @@
}
],
"source": [
"lin_clf = LinearSVC(max_iter=1_000_000, random_state=42)\n",
"lin_clf = LinearSVC(max_iter=1_000_000, dual=True, random_state=42)\n",
"lin_clf.fit(X_train, y_train)"
]
},
Expand Down Expand Up @@ -2090,7 +2097,7 @@
],
"source": [
"lin_clf = make_pipeline(StandardScaler(),\n",
" LinearSVC(random_state=42))\n",
" LinearSVC(dual=True, random_state=42))\n",
"lin_clf.fit(X_train, y_train)"
]
},
Expand Down Expand Up @@ -2347,7 +2354,7 @@
"source": [
"from sklearn.svm import LinearSVR\n",
"\n",
"lin_svr = make_pipeline(StandardScaler(), LinearSVR(random_state=42))\n",
"lin_svr = make_pipeline(StandardScaler(), LinearSVR(dual=True, random_state=42))\n",
"lin_svr.fit(X_train, y_train)"
]
},
Expand Down Expand Up @@ -2377,7 +2384,7 @@
],
"source": [
"lin_svr = make_pipeline(StandardScaler(),\n",
" LinearSVR(max_iter=5000, random_state=42))\n",
" LinearSVR(max_iter=5000, dual=True, random_state=42))\n",
"lin_svr.fit(X_train, y_train)"
]
},
Expand Down

0 comments on commit a5baa85

Please sign in to comment.