From d6fe8475fb15f8c4f56bccf3a2988fd9816f7df8 Mon Sep 17 00:00:00 2001 From: sveneschlbeck Date: Sun, 21 Nov 2021 15:01:21 +0100 Subject: [PATCH 1/4] Changed number of components to make example execution faster --- examples/kernel_approximation/plot_scalable_poly_kernels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/kernel_approximation/plot_scalable_poly_kernels.py b/examples/kernel_approximation/plot_scalable_poly_kernels.py index 21c55fe016889..1e1e2f8bb0ea7 100644 --- a/examples/kernel_approximation/plot_scalable_poly_kernels.py +++ b/examples/kernel_approximation/plot_scalable_poly_kernels.py @@ -99,7 +99,7 @@ # compensate for the stochastic nature of :class:`PolynomialCountSketch`. n_runs = 3 -for n_components in [250, 500, 1000, 2000]: +for n_components in [250, 450, 850, 1750]: ps_lsvm_time = 0 ps_lsvm_score = 0 @@ -156,7 +156,7 @@ # but its training time is much larger and, most importantly, will grow # much faster if the number of training samples increases. -N_COMPONENTS = [250, 500, 1000, 2000] +N_COMPONENTS = [250, 450, 850, 1750] fig, ax = plt.subplots(figsize=(7, 7)) ax.scatter( From 341d5d9b808d58c0eaee0d538f2717972d5f0ad0 Mon Sep 17 00:00:00 2001 From: Sven Eschlbeck <66701689+sveneschlbeck@users.noreply.github.com> Date: Sun, 21 Nov 2021 15:12:55 +0100 Subject: [PATCH 2/4] Update plot_scalable_poly_kernels.py Corrected a typo in the original file. It read ``featrues`` instead of ``features`` --- examples/kernel_approximation/plot_scalable_poly_kernels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/kernel_approximation/plot_scalable_poly_kernels.py b/examples/kernel_approximation/plot_scalable_poly_kernels.py index 1e1e2f8bb0ea7..bc915fa1d9ec4 100644 --- a/examples/kernel_approximation/plot_scalable_poly_kernels.py +++ b/examples/kernel_approximation/plot_scalable_poly_kernels.py @@ -148,7 +148,7 @@ ksvm_score = 100 * ksvm.score(X_test, y_test) results["KSVM"] = {"time": ksvm_time, "score": ksvm_score} -print(f"Kernel-SVM score on raw featrues: {ksvm_score:.2f}%") +print(f"Kernel-SVM score on raw features: {ksvm_score:.2f}%") # %% # Finally, plot the results of the different methods against their training From f41de288db6e089eb0a4972d4ca2393dab86fa59 Mon Sep 17 00:00:00 2001 From: Sven Eschlbeck <66701689+sveneschlbeck@users.noreply.github.com> Date: Mon, 22 Nov 2021 19:56:19 +0100 Subject: [PATCH 3/4] Update examples/kernel_approximation/plot_scalable_poly_kernels.py Co-authored-by: Guillaume Lemaitre --- examples/kernel_approximation/plot_scalable_poly_kernels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/kernel_approximation/plot_scalable_poly_kernels.py b/examples/kernel_approximation/plot_scalable_poly_kernels.py index bc915fa1d9ec4..d865870105558 100644 --- a/examples/kernel_approximation/plot_scalable_poly_kernels.py +++ b/examples/kernel_approximation/plot_scalable_poly_kernels.py @@ -99,7 +99,7 @@ # compensate for the stochastic nature of :class:`PolynomialCountSketch`. n_runs = 3 -for n_components in [250, 450, 850, 1750]: +for n_components in [250, 450, 650, 1350]: ps_lsvm_time = 0 ps_lsvm_score = 0 From 92f8532be312a7204c3adf8110b798c8214bfe48 Mon Sep 17 00:00:00 2001 From: Jordan Silke <51223540+jsilke@users.noreply.github.com> Date: Sat, 19 Mar 2022 19:03:05 -0400 Subject: [PATCH 4/4] Move and revert N_COMPONENTS. Reduce n_runs and update documentation. Adjust spacing and fix a typo. --- .../plot_scalable_poly_kernels.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/kernel_approximation/plot_scalable_poly_kernels.py b/examples/kernel_approximation/plot_scalable_poly_kernels.py index d865870105558..e1ad883dd6517 100644 --- a/examples/kernel_approximation/plot_scalable_poly_kernels.py +++ b/examples/kernel_approximation/plot_scalable_poly_kernels.py @@ -64,11 +64,10 @@ X_train = mm.fit_transform(X_train) X_test = mm.transform(X_test) - # %% # As a baseline, train a linear SVM on the original features and print the # accuracy. We also measure and store accuracies and training times to -# plot them latter. +# plot them later. results = {} @@ -95,11 +94,14 @@ # polynomial kernel of degree four would have approximately 8.5 million # features (precisely, 54^4). Thanks to :class:`PolynomialCountSketch`, we can # condense most of the discriminative information of that feature space into a -# much more compact representation. We repeat the experiment 5 times to -# compensate for the stochastic nature of :class:`PolynomialCountSketch`. +# much more compact representation. While we run the experiment only a single time +# (`n_runs` = 1) in this example, in practice one should repeat the experiment several +# times to compensate for the stochastic nature of :class:`PolynomialCountSketch`. + +n_runs = 1 +N_COMPONENTS = [250, 500, 1000, 2000] -n_runs = 3 -for n_components in [250, 450, 650, 1350]: +for n_components in N_COMPONENTS: ps_lsvm_time = 0 ps_lsvm_score = 0 @@ -156,8 +158,6 @@ # but its training time is much larger and, most importantly, will grow # much faster if the number of training samples increases. -N_COMPONENTS = [250, 450, 850, 1750] - fig, ax = plt.subplots(figsize=(7, 7)) ax.scatter( [ @@ -181,6 +181,7 @@ label="Linear SVM + PolynomialCountSketch", c="blue", ) + for n_components in N_COMPONENTS: ax.scatter( [