<jupyter_start><jupyter_text>Plotting the decision boundary<jupyter_code>plt.figure(figsize=(10,8))
plt.scatter(X[:, 0], X[:, 1], c=y, s=50)
xmin, xmax = X[:, 0].min() - 1, X[:, 0].max() + 1
ymin, ymax = X[:, 1].min() - 1, X[:, 1].max() + 1
h = 0.02
xx, yy = np.meshgrid(np.arange(xmin, xmax, h), np.arange(ymin, ymax, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.figure(figsize=(10, 8))
plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired, s=50)
from sklearn.datasets import make_circles
X, y = make_circles(n_samples=1000, factor=.3, noise=.05)
rand_ix = np.arange(1000)
np.random.shuffle(rand_ix)
X = X[rand_ix, :]
y = y[rand_ix]
plt.figure(figsize=(10, 8))
plt.scatter(X[:, 0], X[:, 1], c=y)<jupyter_output><empty_output><jupyter_text>Introduction to kernel methods<jupyter_code>clf = LinearSVC()
x_train, y_train = X[:900, :], y[:900]
x_test, y_test = X[900:, :], y[900:]
clf.fit(x_train, y_train)
prediction = clf.predict(x_test)
print accuracy_score(y_test, prediction)
print recall_score(y_test, prediction)
xmin, xmax = X[:, 0].min() - 1, X[:, 0].max() + 1
ymin, ymax = X[:, 1].min() - 1, X[:, 1].max() + 1
h = 0.02
xx, yy = np.meshgrid(np.arange(xmin, xmax, h), np.arange(ymin, ymax, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.figure(figsize=(10, 8))
plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired, s=50)
from sklearn.decomposition import KernelPCA
kpca = KernelPCA(kernel="rbf", gamma=5)
x_kpca = kpca.fit_transform(X)
plt.figure(figsize=(10, 8))
plt.scatter(x_kpca[:, 0], x_kpca[:, 1], c=y)
clf = LinearSVC()
x_train, y_train = x_kpca[:900, :2], y[:900]
x_test, y_test = x_kpca[900:, :2], y[900:]
clf.fit(x_train, y_train)
prediction = clf.predict(x_test)
print accuracy_score(y_test, prediction)
print recall_score(y_test, prediction)
xmin, xmax = x_kpca[:, 0].min() - 1, x_kpca[:, 0].max() + 1
ymin, ymax = x_kpca[:, 1].min() - 1, x_kpca[:, 1].max() + 1
h = 0.02
xx, yy = np.meshgrid(np.arange(xmin, xmax, h), np.arange(ymin, ymax, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.figure(figsize=(10, 8))
plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
plt.scatter(x_kpca[:, 0], x_kpca[:, 1], c=y, cmap=plt.cm.Paired, s=50)
from sklearn.svm import SVC
clf = SVC(kernel="rbf")
x_train, y_train = X[:900, :], y[:900]
x_test, y_test = X[900:, :], y[900:]
clf.fit(x_train, y_train)
prediction = clf.predict(x_test)
print accuracy_score(y_test, prediction)
print recall_score(y_test, prediction)
xmin, xmax = X[:, 0].min() - 1, X[:, 0].max() + 1
ymin, ymax = X[:, 1].min() - 1, X[:, 1].max() + 1
h = 0.02
xx, yy = np.meshgrid(np.arange(xmin, xmax, h), np.arange(ymin, ymax, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.figure(figsize=(10, 8))
plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired, s=50)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22930978083087994, 'fraction_numerical': 0.04808635917566242, 'mean_word_length': 5.410901467505241, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '46089', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1464, 'n_words': 297, 'path': 'notebooks/1_metrics_decision_boundaries.ipynb', 'repo_name': 'jaidevd/its_sklearn', 'size': '3057'}