From 59c4209103b14ae0209cd6cf59dfbc3d29d76213 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Wed, 4 May 2016 17:34:42 -0400 Subject: [PATCH 01/37] Fix: Replace pylab with matplotlib.pyplot #6754 - one instance of 22 occurrences of pylab replaced with matplotlib.pyplot - bench_glm.py now free of pylab references - code executes properly --- benchmarks/bench_glm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/bench_glm.py b/benchmarks/bench_glm.py index 598ba5fe2a95d..fbbf44487ecef 100644 --- a/benchmarks/bench_glm.py +++ b/benchmarks/bench_glm.py @@ -12,7 +12,7 @@ if __name__ == '__main__': - import pylab as pl + import matplotlib.pyplot as pl n_iter = 40 From 0e08eab7af81ba8f457a935bf00a56efdc587f1f Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Thu, 5 May 2016 19:41:59 -0400 Subject: [PATCH 02/37] Fix: Replace pylab with matplotlib.pyplot #6754 - one instance of 21 remaining occurrences of pylab replaced with matplotlib.pyplot - bench_glmnet.py now free of pylab references - code does not execute for extraneous reason: ImportError: No module named glmnet.elastic_net --- benchmarks/bench_glmnet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmarks/bench_glmnet.py b/benchmarks/bench_glmnet.py index 4b9c35040c526..8082f5796128c 100644 --- a/benchmarks/bench_glmnet.py +++ b/benchmarks/bench_glmnet.py @@ -47,8 +47,8 @@ def bench(factory, X, Y, X_test, Y_test, ref_coef): if __name__ == '__main__': from glmnet.elastic_net import Lasso as GlmnetLasso from sklearn.linear_model import Lasso as ScikitLasso - # Delayed import of pylab - import pylab as pl + # Delayed import of matplotlib.pyplot + import matplotlib.pyplot as pl scikit_results = [] glmnet_results = [] From 0ac6c7d9e25bfd090e6415130cddcbba82877f6a Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Thu, 5 May 2016 19:48:22 -0400 Subject: [PATCH 03/37] Fix: Replace pylab with matplotlib.pyplot #6754 - one instance of 19 occurrences of pylab replaced with matplotlib.pyplot - bench_lasso.py now free of pylab references - code executes properly --- benchmarks/bench_lasso.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/bench_lasso.py b/benchmarks/bench_lasso.py index 7934fe1fdb0ba..5b2be67d78e76 100644 --- a/benchmarks/bench_lasso.py +++ b/benchmarks/bench_lasso.py @@ -59,7 +59,7 @@ def compute_bench(alpha, n_samples, n_features, precompute): if __name__ == '__main__': from sklearn.linear_model import Lasso, LassoLars - import pylab as pl + import matplotlib.pyplot as pl alpha = 0.01 # regularization parameter From e8f9efce8aa615752b134027b3e113b9132b01fc Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Thu, 5 May 2016 19:51:14 -0400 Subject: [PATCH 04/37] Fix: Replace pylab with matplotlib.pyplot #6754 - one instance of 18 occurrences of pylab replaced with matplotlib.pyplot - bench_plot_neighbors.py now free of pylab references - code executes properly --- benchmarks/bench_plot_neighbors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/bench_plot_neighbors.py b/benchmarks/bench_plot_neighbors.py index d163fb46b7193..2e6c1a49b80a1 100644 --- a/benchmarks/bench_plot_neighbors.py +++ b/benchmarks/bench_plot_neighbors.py @@ -4,7 +4,7 @@ from time import time import numpy as np -import pylab as pl +import matplotlib.pyplot as pl from matplotlib import ticker from sklearn import neighbors, datasets From 4786962c5f93204143dba7b768cc92d6fabe0e8d Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Thu, 5 May 2016 19:54:55 -0400 Subject: [PATCH 05/37] Fix: Replace pylab with matplotlib.pyplot #6754 - one instance of 17 occurrences of pylab replaced with matplotlib.pyplot - bench_plot_omp_lars.py now free of pylab references - code does not execute for extraneous reasons: - File "bench_plot_omp_lars.py", line 111, in - ax = fig.add_subplot(1, 2, i) - ValueError: num must be 1 <= num <= 2, not 0 - line 111 should probably be ax = fig.add_subplot(1, 2, i+1) --- benchmarks/bench_plot_omp_lars.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/bench_plot_omp_lars.py b/benchmarks/bench_plot_omp_lars.py index debc3c3be4567..df36d0e19141c 100644 --- a/benchmarks/bench_plot_omp_lars.py +++ b/benchmarks/bench_plot_omp_lars.py @@ -105,7 +105,7 @@ def compute_bench(samples_range, features_range): results = compute_bench(samples_range, features_range) max_time = max(np.max(t) for t in results.values()) - import pylab as pl + import matplotlib.pyplot as pl fig = pl.figure('scikit-learn OMP vs. LARS benchmark results') for i, (label, timings) in enumerate(sorted(results.iteritems())): ax = fig.add_subplot(1, 2, i) From 361957fe47e5e2947bbec832a0f64bad2d7c7ca2 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Fri, 6 May 2016 11:36:48 -0400 Subject: [PATCH 06/37] Fix: Replace pylab with matplotlib.pyplot #6754 - bench_plot_parallel_pairwise.py now free of pylab references - code executes properly --- benchmarks/bench_plot_parallel_pairwise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/bench_plot_parallel_pairwise.py b/benchmarks/bench_plot_parallel_pairwise.py index c17f42d7ca5eb..34619679faf40 100644 --- a/benchmarks/bench_plot_parallel_pairwise.py +++ b/benchmarks/bench_plot_parallel_pairwise.py @@ -2,7 +2,7 @@ # License: BSD 3 clause import time -import pylab as pl +import matplotlib.pyplot as pl from sklearn.utils import check_random_state from sklearn.metrics.pairwise import pairwise_distances From 28c946ba6e444cbbff5da2491e35cc740314f4cf Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Fri, 6 May 2016 17:06:04 -0400 Subject: [PATCH 07/37] Fix: Replace pylab with matplotlib.pyplot #6754 - bench_plot_ward.py now free of pylab references - code executes properly --- benchmarks/bench_plot_ward.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/bench_plot_ward.py b/benchmarks/bench_plot_ward.py index 0159cc5232f08..c06fb01707fa1 100644 --- a/benchmarks/bench_plot_ward.py +++ b/benchmarks/bench_plot_ward.py @@ -6,7 +6,7 @@ import numpy as np from scipy.cluster import hierarchy -import pylab as pl +import matplotlib.pyplot as pl from sklearn.cluster import AgglomerativeClustering From 9e4052020ec3ff480ae9c6970def08f9b1830ac2 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Fri, 6 May 2016 17:09:02 -0400 Subject: [PATCH 08/37] Fix: Replace pylab with matplotlib.pyplot #6754 - bench_sgd_regression.py now free of pylab references - code executes properly --- benchmarks/bench_sgd_regression.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/bench_sgd_regression.py b/benchmarks/bench_sgd_regression.py index 63e3e4c51846b..c8902bf867ab0 100644 --- a/benchmarks/bench_sgd_regression.py +++ b/benchmarks/bench_sgd_regression.py @@ -11,7 +11,7 @@ # License: BSD 3 clause import numpy as np -import pylab as pl +import matplotlib.pyplot as pl import gc From 41bb9997651800e6f2d34c0610c5f35016f726ef Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Fri, 6 May 2016 17:14:01 -0400 Subject: [PATCH 09/37] Fix: Replace pylab with matplotlib.pyplot #6754 - bench_tree.py now free of pylab references - code executes properly --- benchmarks/bench_tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/bench_tree.py b/benchmarks/bench_tree.py index ca97cf9be275b..bc22411d18082 100644 --- a/benchmarks/bench_tree.py +++ b/benchmarks/bench_tree.py @@ -14,7 +14,7 @@ of the number of dimensions. """ import numpy as np -import pylab as pl +import matplotlib.pyplot as pl import gc from datetime import datetime From 5c2e9f59263402a45158e1156816a2aef461b560 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 18:46:33 -0400 Subject: [PATCH 10/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_glm.py clean --- benchmarks/bench_glm.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/benchmarks/bench_glm.py b/benchmarks/bench_glm.py index fbbf44487ecef..660c208402b7d 100644 --- a/benchmarks/bench_glm.py +++ b/benchmarks/bench_glm.py @@ -12,7 +12,7 @@ if __name__ == '__main__': - import matplotlib.pyplot as pl + import matplotlib.pyplot as plt n_iter = 40 @@ -46,13 +46,13 @@ lasso.fit(X, Y) time_lasso[i] = total_seconds(datetime.now() - start) - pl.figure('scikit-learn GLM benchmark results') - pl.xlabel('Dimensions') - pl.ylabel('Time (s)') - pl.plot(dimensions, time_ridge, color='r') - pl.plot(dimensions, time_ols, color='g') - pl.plot(dimensions, time_lasso, color='b') + plt.figure('scikit-learn GLM benchmark results') + plt.xlabel('Dimensions') + plt.ylabel('Time (s)') + plt.plot(dimensions, time_ridge, color='r') + plt.plot(dimensions, time_ols, color='g') + plt.plot(dimensions, time_lasso, color='b') - pl.legend(['Ridge', 'OLS', 'LassoLars'], loc='upper left') - pl.axis('tight') - pl.show() + plt.legend(['Ridge', 'OLS', 'LassoLars'], loc='upper left') + plt.axis('tight') + plt.show() From a4c26922e52e2d4f46767591c7f4cbfa9a05e2e5 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 18:52:50 -0400 Subject: [PATCH 11/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_glm.py clean of pl - code does not execute for extraneous reasons --- benchmarks/bench_glmnet.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/benchmarks/bench_glmnet.py b/benchmarks/bench_glmnet.py index 8082f5796128c..b05971ba1ff20 100644 --- a/benchmarks/bench_glmnet.py +++ b/benchmarks/bench_glmnet.py @@ -48,7 +48,7 @@ def bench(factory, X, Y, X_test, Y_test, ref_coef): from glmnet.elastic_net import Lasso as GlmnetLasso from sklearn.linear_model import Lasso as ScikitLasso # Delayed import of matplotlib.pyplot - import matplotlib.pyplot as pl + import matplotlib.pyplot as plt scikit_results = [] glmnet_results = [] @@ -76,15 +76,15 @@ def bench(factory, X, Y, X_test, Y_test, ref_coef): print("benchmarking glmnet: ") glmnet_results.append(bench(GlmnetLasso, X, Y, X_test, Y_test, coef_)) - pl.clf() + plt.clf() xx = range(0, n * step, step) - pl.title('Lasso regression on sample dataset (%d features)' % n_features) - pl.plot(xx, scikit_results, 'b-', label='scikit-learn') - pl.plot(xx, glmnet_results, 'r-', label='glmnet') - pl.legend() - pl.xlabel('number of samples to classify') - pl.ylabel('Time (s)') - pl.show() + plt.title('Lasso regression on sample dataset (%d features)' % n_features) + plt.plot(xx, scikit_results, 'b-', label='scikit-learn') + plt.plot(xx, glmnet_results, 'r-', label='glmnet') + plt.legend() + plt.xlabel('number of samples to classify') + plt.ylabel('Time (s)') + plt.show() # now do a benchmark where the number of points is fixed # and the variable is the number of features @@ -117,12 +117,12 @@ def bench(factory, X, Y, X_test, Y_test, ref_coef): glmnet_results.append(bench(GlmnetLasso, X, Y, X_test, Y_test, coef_)) xx = np.arange(100, 100 + n * step, step) - pl.figure('scikit-learn vs. glmnet benchmark results') - pl.title('Regression in high dimensional spaces (%d samples)' % n_samples) - pl.plot(xx, scikit_results, 'b-', label='scikit-learn') - pl.plot(xx, glmnet_results, 'r-', label='glmnet') - pl.legend() - pl.xlabel('number of features') - pl.ylabel('Time (s)') - pl.axis('tight') - pl.show() + plt.figure('scikit-learn vs. glmnet benchmark results') + plt.title('Regression in high dimensional spaces (%d samples)' % n_samples) + plt.plot(xx, scikit_results, 'b-', label='scikit-learn') + plt.plot(xx, glmnet_results, 'r-', label='glmnet') + plt.legend() + plt.xlabel('number of features') + plt.ylabel('Time (s)') + plt.axis('tight') + plt.show() From 86533f86bcdfc4994d14a37922ce0ee64a31a684 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 19:08:27 -0400 Subject: [PATCH 12/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_lasso.py clean of pl - code executes properly --- benchmarks/bench_lasso.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/benchmarks/bench_lasso.py b/benchmarks/bench_lasso.py index 5b2be67d78e76..97bc8ecdf51cf 100644 --- a/benchmarks/bench_lasso.py +++ b/benchmarks/bench_lasso.py @@ -59,7 +59,7 @@ def compute_bench(alpha, n_samples, n_features, precompute): if __name__ == '__main__': from sklearn.linear_model import Lasso, LassoLars - import matplotlib.pyplot as pl + import matplotlib.pyplot as plt alpha = 0.01 # regularization parameter @@ -68,28 +68,28 @@ def compute_bench(alpha, n_samples, n_features, precompute): lasso_results, lars_lasso_results = compute_bench(alpha, list_n_samples, [n_features], precompute=True) - pl.figure('scikit-learn LASSO benchmark results') - pl.subplot(211) - pl.plot(list_n_samples, lasso_results, 'b-', + plt.figure('scikit-learn LASSO benchmark results') + plt.subplot(211) + plt.plot(list_n_samples, lasso_results, 'b-', label='Lasso') - pl.plot(list_n_samples, lars_lasso_results, 'r-', + plt.plot(list_n_samples, lars_lasso_results, 'r-', label='LassoLars') - pl.title('precomputed Gram matrix, %d features, alpha=%s' % (n_features, alpha)) - pl.legend(loc='upper left') - pl.xlabel('number of samples') - pl.ylabel('Time (s)') - pl.axis('tight') + plt.title('precomputed Gram matrix, %d features, alpha=%s' % (n_features, alpha)) + plt.legend(loc='upper left') + plt.xlabel('number of samples') + plt.ylabel('Time (s)') + plt.axis('tight') n_samples = 2000 list_n_features = np.linspace(500, 3000, 5).astype(np.int) lasso_results, lars_lasso_results = compute_bench(alpha, [n_samples], list_n_features, precompute=False) - pl.subplot(212) - pl.plot(list_n_features, lasso_results, 'b-', label='Lasso') - pl.plot(list_n_features, lars_lasso_results, 'r-', label='LassoLars') - pl.title('%d samples, alpha=%s' % (n_samples, alpha)) - pl.legend(loc='upper left') - pl.xlabel('number of features') - pl.ylabel('Time (s)') - pl.axis('tight') - pl.show() + plt.subplot(212) + plt.plot(list_n_features, lasso_results, 'b-', label='Lasso') + plt.plot(list_n_features, lars_lasso_results, 'r-', label='LassoLars') + plt.title('%d samples, alpha=%s' % (n_samples, alpha)) + plt.legend(loc='upper left') + plt.xlabel('number of features') + plt.ylabel('Time (s)') + plt.axis('tight') + plt.show() From 531b770f0a50ec282a5fbeca12bbcc4d321c659a Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 19:12:09 -0400 Subject: [PATCH 13/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_plot_neighbors.py clean of pl - code executes properly --- benchmarks/bench_plot_neighbors.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/benchmarks/bench_plot_neighbors.py b/benchmarks/bench_plot_neighbors.py index 2e6c1a49b80a1..8b862017653e1 100644 --- a/benchmarks/bench_plot_neighbors.py +++ b/benchmarks/bench_plot_neighbors.py @@ -4,7 +4,7 @@ from time import time import numpy as np -import matplotlib.pyplot as pl +import matplotlib.pyplot as plt from matplotlib import ticker from sklearn import neighbors, datasets @@ -106,7 +106,7 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11), k_results_build[algorithm][i] = (t1 - t0) k_results_query[algorithm][i] = (t2 - t1) - pl.figure(figsize=(8, 11)) + plt.figure(figsize=(8, 11)) for (sbplt, vals, quantity, build_time, query_time) in [(311, Nrange, 'N', @@ -118,8 +118,8 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11), (313, krange, 'k', k_results_build, k_results_query)]: - ax = pl.subplot(sbplt, yscale='log') - pl.grid(True) + ax = plt.subplot(sbplt, yscale='log') + plt.grid(True) tick_vals = [] tick_labels = [] @@ -131,21 +131,21 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11), xvals = 0.1 + i * (1 + len(vals)) + np.arange(len(vals)) width = 0.8 - c_bar = pl.bar(xvals, build_time[alg] - bottom, + c_bar = plt.bar(xvals, build_time[alg] - bottom, width, bottom, color='r') - q_bar = pl.bar(xvals, query_time[alg], + q_bar = plt.bar(xvals, query_time[alg], width, build_time[alg], color='b') tick_vals += list(xvals + 0.5 * width) tick_labels += ['%i' % val for val in vals] - pl.text((i + 0.02) / len(algorithms), 0.98, alg, + plt.text((i + 0.02) / len(algorithms), 0.98, alg, transform=ax.transAxes, ha='left', va='top', bbox=dict(facecolor='w', edgecolor='w', alpha=0.5)) - pl.ylabel('Time (s)') + plt.ylabel('Time (s)') ax.xaxis.set_major_locator(ticker.FixedLocator(tick_vals)) ax.xaxis.set_major_formatter(ticker.FixedFormatter(tick_labels)) @@ -166,20 +166,20 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11), descr_string = descr_string[:-2] - pl.text(1.01, 0.5, title_string, + plt.text(1.01, 0.5, title_string, transform=ax.transAxes, rotation=-90, ha='left', va='center', fontsize=20) - pl.text(0.99, 0.5, descr_string, + plt.text(0.99, 0.5, descr_string, transform=ax.transAxes, rotation=-90, ha='right', va='center') - pl.gcf().suptitle("%s data set" % dataset.capitalize(), fontsize=16) + plt.gcf().suptitle("%s data set" % dataset.capitalize(), fontsize=16) - pl.figlegend((c_bar, q_bar), ('construction', 'N-point query'), + plt.figlegend((c_bar, q_bar), ('construction', 'N-point query'), 'upper right') if __name__ == '__main__': barplot_neighbors(dataset='digits') barplot_neighbors(dataset='dense') - pl.show() + plt.show() From f3276aad3a6cf92464130783f06c4663ad7a1b8a Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 19:42:45 -0400 Subject: [PATCH 14/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_plot_omp_lars.py clean of pl - code does not execute for extraneous reasons --- benchmarks/bench_plot_omp_lars.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/benchmarks/bench_plot_omp_lars.py b/benchmarks/bench_plot_omp_lars.py index df36d0e19141c..10d77e7fc6330 100644 --- a/benchmarks/bench_plot_omp_lars.py +++ b/benchmarks/bench_plot_omp_lars.py @@ -105,19 +105,19 @@ def compute_bench(samples_range, features_range): results = compute_bench(samples_range, features_range) max_time = max(np.max(t) for t in results.values()) - import matplotlib.pyplot as pl - fig = pl.figure('scikit-learn OMP vs. LARS benchmark results') + import matplotlib.pyplot as plt + fig = plt.figure('scikit-learn OMP vs. LARS benchmark results') for i, (label, timings) in enumerate(sorted(results.iteritems())): ax = fig.add_subplot(1, 2, i) vmax = max(1 - timings.min(), -1 + timings.max()) - pl.matshow(timings, fignum=False, vmin=1 - vmax, vmax=1 + vmax) + plt.matshow(timings, fignum=False, vmin=1 - vmax, vmax=1 + vmax) ax.set_xticklabels([''] + map(str, samples_range)) ax.set_yticklabels([''] + map(str, features_range)) - pl.xlabel('n_samples') - pl.ylabel('n_features') - pl.title(label) - - pl.subplots_adjust(0.1, 0.08, 0.96, 0.98, 0.4, 0.63) - ax = pl.axes([0.1, 0.08, 0.8, 0.06]) - pl.colorbar(cax=ax, orientation='horizontal') - pl.show() + plt.xlabel('n_samples') + plt.ylabel('n_features') + plt.title(label) + + plt.subplots_adjust(0.1, 0.08, 0.96, 0.98, 0.4, 0.63) + ax = plt.axes([0.1, 0.08, 0.8, 0.06]) + plt.colorbar(cax=ax, orientation='horizontal') + plt.show() From 57126a13464ed348e2fc1ef264f25e4075969891 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 20:13:56 -0400 Subject: [PATCH 15/37] fix: Fix bug that prevented graphs from displaying --- benchmarks/bench_plot_omp_lars.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/bench_plot_omp_lars.py b/benchmarks/bench_plot_omp_lars.py index 10d77e7fc6330..58d350af539a1 100644 --- a/benchmarks/bench_plot_omp_lars.py +++ b/benchmarks/bench_plot_omp_lars.py @@ -108,7 +108,7 @@ def compute_bench(samples_range, features_range): import matplotlib.pyplot as plt fig = plt.figure('scikit-learn OMP vs. LARS benchmark results') for i, (label, timings) in enumerate(sorted(results.iteritems())): - ax = fig.add_subplot(1, 2, i) + ax = fig.add_subplot(1, 2, i+1) vmax = max(1 - timings.min(), -1 + timings.max()) plt.matshow(timings, fignum=False, vmin=1 - vmax, vmax=1 + vmax) ax.set_xticklabels([''] + map(str, samples_range)) From 3cd9786d1a5007416000f471c6e26e57d765e014 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 20:17:39 -0400 Subject: [PATCH 16/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_plot_parallel_pairwise.py clean of pl - code executes properly --- benchmarks/bench_plot_parallel_pairwise.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/benchmarks/bench_plot_parallel_pairwise.py b/benchmarks/bench_plot_parallel_pairwise.py index 34619679faf40..e844ea06e1f53 100644 --- a/benchmarks/bench_plot_parallel_pairwise.py +++ b/benchmarks/bench_plot_parallel_pairwise.py @@ -2,7 +2,7 @@ # License: BSD 3 clause import time -import matplotlib.pyplot as pl +import matplotlib.pyplot as plt from sklearn.utils import check_random_state from sklearn.metrics.pairwise import pairwise_distances @@ -25,13 +25,13 @@ def plot(func): func(X, n_jobs=-1) multi_core.append(time.time() - start) - pl.figure('scikit-learn parallel %s benchmark results' % func.__name__) - pl.plot(sample_sizes, one_core, label="one core") - pl.plot(sample_sizes, multi_core, label="multi core") - pl.xlabel('n_samples') - pl.ylabel('Time (s)') - pl.title('Parallel %s' % func.__name__) - pl.legend() + plt.figure('scikit-learn parallel %s benchmark results' % func.__name__) + plt.plot(sample_sizes, one_core, label="one core") + plt.plot(sample_sizes, multi_core, label="multi core") + plt.xlabel('n_samples') + plt.ylabel('Time (s)') + plt.title('Parallel %s' % func.__name__) + plt.legend() def euclidean_distances(X, n_jobs): return pairwise_distances(X, metric="euclidean", n_jobs=n_jobs) @@ -41,4 +41,4 @@ def rbf_kernels(X, n_jobs): plot(euclidean_distances) plot(rbf_kernels) -pl.show() +plt.show() From 22bb3b813389a483762648c924997e7febd264bc Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 20:20:23 -0400 Subject: [PATCH 17/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_plot_ward.py clean of pl - code executes properly --- benchmarks/bench_plot_ward.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/benchmarks/bench_plot_ward.py b/benchmarks/bench_plot_ward.py index c06fb01707fa1..be93d6d2508e9 100644 --- a/benchmarks/bench_plot_ward.py +++ b/benchmarks/bench_plot_ward.py @@ -6,7 +6,7 @@ import numpy as np from scipy.cluster import hierarchy -import matplotlib.pyplot as pl +import matplotlib.pyplot as plt from sklearn.cluster import AgglomerativeClustering @@ -31,13 +31,13 @@ ratio = scikits_time / scipy_time -pl.figure("scikit-learn Ward's method benchmark results") -pl.imshow(np.log(ratio), aspect='auto', origin="lower") -pl.colorbar() -pl.contour(ratio, levels=[1, ], colors='k') -pl.yticks(range(len(n_features)), n_features.astype(np.int)) -pl.ylabel('N features') -pl.xticks(range(len(n_samples)), n_samples.astype(np.int)) -pl.xlabel('N samples') -pl.title("Scikit's time, in units of scipy time (log)") -pl.show() +plt.figure("scikit-learn Ward's method benchmark results") +plt.imshow(np.log(ratio), aspect='auto', origin="lower") +plt.colorbar() +plt.contour(ratio, levels=[1, ], colors='k') +plt.yticks(range(len(n_features)), n_features.astype(np.int)) +plt.ylabel('N features') +plt.xticks(range(len(n_samples)), n_samples.astype(np.int)) +plt.xlabel('N samples') +plt.title("Scikit's time, in units of scipy time (log)") +plt.show() From 5868f4b048db1314f162d344a9798e2771a68bd0 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 20:23:15 -0400 Subject: [PATCH 18/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_sgd_regression.py clean of pl - code executes properly --- benchmarks/bench_sgd_regression.py | 44 +++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/benchmarks/bench_sgd_regression.py b/benchmarks/bench_sgd_regression.py index c8902bf867ab0..1fe0507a84ae8 100644 --- a/benchmarks/bench_sgd_regression.py +++ b/benchmarks/bench_sgd_regression.py @@ -11,7 +11,7 @@ # License: BSD 3 clause import numpy as np -import matplotlib.pyplot as pl +import matplotlib.pyplot as plt import gc @@ -113,39 +113,39 @@ # Plot results i = 0 m = len(list_n_features) - pl.figure('scikit-learn SGD regression benchmark results', + plt.figure('scikit-learn SGD regression benchmark results', figsize=(5 * 2, 4 * m)) for j in range(m): - pl.subplot(m, 2, i + 1) - pl.plot(list_n_samples, np.sqrt(elnet_results[:, j, 0]), + plt.subplot(m, 2, i + 1) + plt.plot(list_n_samples, np.sqrt(elnet_results[:, j, 0]), label="ElasticNet") - pl.plot(list_n_samples, np.sqrt(sgd_results[:, j, 0]), + plt.plot(list_n_samples, np.sqrt(sgd_results[:, j, 0]), label="SGDRegressor") - pl.plot(list_n_samples, np.sqrt(asgd_results[:, j, 0]), + plt.plot(list_n_samples, np.sqrt(asgd_results[:, j, 0]), label="A-SGDRegressor") - pl.plot(list_n_samples, np.sqrt(ridge_results[:, j, 0]), + plt.plot(list_n_samples, np.sqrt(ridge_results[:, j, 0]), label="Ridge") - pl.legend(prop={"size": 10}) - pl.xlabel("n_train") - pl.ylabel("RMSE") - pl.title("Test error - %d features" % list_n_features[j]) + plt.legend(prop={"size": 10}) + plt.xlabel("n_train") + plt.ylabel("RMSE") + plt.title("Test error - %d features" % list_n_features[j]) i += 1 - pl.subplot(m, 2, i + 1) - pl.plot(list_n_samples, np.sqrt(elnet_results[:, j, 1]), + plt.subplot(m, 2, i + 1) + plt.plot(list_n_samples, np.sqrt(elnet_results[:, j, 1]), label="ElasticNet") - pl.plot(list_n_samples, np.sqrt(sgd_results[:, j, 1]), + plt.plot(list_n_samples, np.sqrt(sgd_results[:, j, 1]), label="SGDRegressor") - pl.plot(list_n_samples, np.sqrt(asgd_results[:, j, 1]), + plt.plot(list_n_samples, np.sqrt(asgd_results[:, j, 1]), label="A-SGDRegressor") - pl.plot(list_n_samples, np.sqrt(ridge_results[:, j, 1]), + plt.plot(list_n_samples, np.sqrt(ridge_results[:, j, 1]), label="Ridge") - pl.legend(prop={"size": 10}) - pl.xlabel("n_train") - pl.ylabel("Time [sec]") - pl.title("Training time - %d features" % list_n_features[j]) + plt.legend(prop={"size": 10}) + plt.xlabel("n_train") + plt.ylabel("Time [sec]") + plt.title("Training time - %d features" % list_n_features[j]) i += 1 - pl.subplots_adjust(hspace=.30) + plt.subplots_adjust(hspace=.30) - pl.show() + plt.show() From 9fb52902a7f78f16859e76f4228cfe85aa092264 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 20:41:15 -0400 Subject: [PATCH 19/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_tree.py clean of pl - code executes properly --- benchmarks/bench_tree.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/benchmarks/bench_tree.py b/benchmarks/bench_tree.py index bc22411d18082..8a0af26d4c221 100644 --- a/benchmarks/bench_tree.py +++ b/benchmarks/bench_tree.py @@ -14,7 +14,7 @@ of the number of dimensions. """ import numpy as np -import matplotlib.pyplot as pl +import matplotlib.pyplot as plt import gc from datetime import datetime @@ -84,14 +84,14 @@ def bench_scikit_tree_regressor(X, Y): bench_scikit_tree_regressor(X, Y) xx = range(0, n * step, step) - pl.figure('scikit-learn tree benchmark results') - pl.subplot(211) - pl.title('Learning with varying number of samples') - pl.plot(xx, scikit_classifier_results, 'g-', label='classification') - pl.plot(xx, scikit_regressor_results, 'r-', label='regression') - pl.legend(loc='upper left') - pl.xlabel('number of samples') - pl.ylabel('Time (s)') + plt.figure('scikit-learn tree benchmark results') + plt.subplot(211) + plt.title('Learning with varying number of samples') + plt.plot(xx, scikit_classifier_results, 'g-', label='classification') + plt.plot(xx, scikit_regressor_results, 'r-', label='regression') + plt.legend(loc='upper left') + plt.xlabel('number of samples') + plt.ylabel('Time (s)') scikit_classifier_results = [] scikit_regressor_results = [] @@ -113,12 +113,12 @@ def bench_scikit_tree_regressor(X, Y): bench_scikit_tree_regressor(X, Y) xx = np.arange(start_dim, start_dim + n * step, step) - pl.subplot(212) - pl.title('Learning in high dimensional spaces') - pl.plot(xx, scikit_classifier_results, 'g-', label='classification') - pl.plot(xx, scikit_regressor_results, 'r-', label='regression') - pl.legend(loc='upper left') - pl.xlabel('number of dimensions') - pl.ylabel('Time (s)') - pl.axis('tight') - pl.show() + plt.subplot(212) + plt.title('Learning in high dimensional spaces') + plt.plot(xx, scikit_classifier_results, 'g-', label='classification') + plt.plot(xx, scikit_regressor_results, 'r-', label='regression') + plt.legend(loc='upper left') + plt.xlabel('number of dimensions') + plt.ylabel('Time (s)') + plt.axis('tight') + plt.show() From 2df3acdbb744459b5641636f963b494a9f5c0a50 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 20:43:41 -0400 Subject: [PATCH 20/37] docs: removed pylab references from comments --- .../skeletons/exercise_01_language_train_model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/tutorial/text_analytics/skeletons/exercise_01_language_train_model.py b/doc/tutorial/text_analytics/skeletons/exercise_01_language_train_model.py index 51649840d9049..d1651b5985a7c 100644 --- a/doc/tutorial/text_analytics/skeletons/exercise_01_language_train_model.py +++ b/doc/tutorial/text_analytics/skeletons/exercise_01_language_train_model.py @@ -46,9 +46,9 @@ cm = metrics.confusion_matrix(y_test, y_predicted) print(cm) -#import pylab as pl -#pl.matshow(cm, cmap=pl.cm.jet) -#pl.show() +#import matplotlib.pyplot as plt +#t.matshow(cm, cmap=plt.cm.jet) +#plt.show() # Predict the result on some short new sentences: sentences = [ From 9df92250e88ec7bc18b03e68b533007342fc1abd Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 20:46:32 -0400 Subject: [PATCH 21/37] docs: removed all pylab references - replaced with matplotlib.pyplot - pl --> plt --- .../statistical_inference/supervised_learning.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/tutorial/statistical_inference/supervised_learning.rst b/doc/tutorial/statistical_inference/supervised_learning.rst index d5e69e15dd0f4..e431d0fea3420 100644 --- a/doc/tutorial/statistical_inference/supervised_learning.rst +++ b/doc/tutorial/statistical_inference/supervised_learning.rst @@ -212,15 +212,15 @@ induces high variance: >>> test = np.c_[ 0, 2].T >>> regr = linear_model.LinearRegression() - >>> import pylab as pl # doctest: +SKIP - >>> pl.figure() # doctest: +SKIP + >>> import matplotlib as plt # doctest: +SKIP + >>> plt.figure() # doctest: +SKIP >>> np.random.seed(0) >>> for _ in range(6): # doctest: +SKIP ... this_X = .1*np.random.normal(size=(2, 1)) + X ... regr.fit(this_X, y) - ... pl.plot(test, regr.predict(test)) # doctest: +SKIP - ... pl.scatter(this_X, y, s=3) # doctest: +SKIP + ... plt.plot(test, regr.predict(test)) # doctest: +SKIP + ... plt.scatter(this_X, y, s=3) # doctest: +SKIP @@ -238,14 +238,14 @@ regression: >>> regr = linear_model.Ridge(alpha=.1) - >>> pl.figure() # doctest: +SKIP + >>> plt.figure() # doctest: +SKIP >>> np.random.seed(0) >>> for _ in range(6): # doctest: +SKIP ... this_X = .1*np.random.normal(size=(2, 1)) + X ... regr.fit(this_X, y) - ... pl.plot(test, regr.predict(test)) # doctest: +SKIP - ... pl.scatter(this_X, y, s=3) # doctest: +SKIP + ... plt.plot(test, regr.predict(test)) # doctest: +SKIP + ... plt.scatter(this_X, y, s=3) # doctest: +SKIP This is an example of **bias/variance tradeoff**: the larger the ridge ``alpha`` parameter, the higher the bias and the lower the variance. From 82c08accdada2603bacefd10077617227bc5ac7c Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 20:50:11 -0400 Subject: [PATCH 22/37] docs: removed pylab references from comments - replaced with matplotlib.pyplot - pl --> plt --- .../solutions/exercise_01_language_train_model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/tutorial/text_analytics/solutions/exercise_01_language_train_model.py b/doc/tutorial/text_analytics/solutions/exercise_01_language_train_model.py index 869cfbee2565d..f4e15774711b9 100644 --- a/doc/tutorial/text_analytics/solutions/exercise_01_language_train_model.py +++ b/doc/tutorial/text_analytics/solutions/exercise_01_language_train_model.py @@ -54,9 +54,9 @@ cm = metrics.confusion_matrix(y_test, y_predicted) print(cm) -#import pylab as pl -#pl.matshow(cm, cmap=pl.cm.jet) -#pl.show() +#import matlotlib.pyplot as plt +#plt.matshow(cm, cmap=plt.cm.jet) +#plt.show() # Predict the result on some short new sentences: sentences = [ From 32d574edfb67ee265672389506ccb04747727cf0 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Sun, 8 May 2016 20:51:01 -0400 Subject: [PATCH 23/37] docs: removed all pylab references - replaced with matplotlib.pyplot - pl --> plt --- doc/tutorial/statistical_inference/settings.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/tutorial/statistical_inference/settings.rst b/doc/tutorial/statistical_inference/settings.rst index fead00cf952fb..3537151d0144d 100644 --- a/doc/tutorial/statistical_inference/settings.rst +++ b/doc/tutorial/statistical_inference/settings.rst @@ -29,7 +29,7 @@ these arrays is the **samples** axis, while the second is the When the data is not initially in the ``(n_samples, n_features)`` shape, it needs to be preprocessed in order to be used by scikit-learn. -.. topic:: An example of reshaping data would be the digits dataset +.. topic:: An example of reshaping data would be the digits dataset .. image:: ../../auto_examples/datasets/images/plot_digits_last_image_001.png :target: ../../auto_examples/datasets/plot_digits_last_image.html @@ -42,8 +42,8 @@ needs to be preprocessed in order to be used by scikit-learn. >>> digits = datasets.load_digits() >>> digits.images.shape (1797, 8, 8) - >>> import pylab as pl #doctest: +SKIP - >>> pl.imshow(digits.images[-1], cmap=pl.cm.gray_r) #doctest: +SKIP + >>> import matplotlib.pyplot as plt #doctest: +SKIP + >>> plt.imshow(digits.images[-1], cmap=plt.cm.gray_r) #doctest: +SKIP To use this dataset with the scikit, we transform each 8x8 image into a @@ -89,4 +89,3 @@ parameters are attributes of the estimator object ending by an underscore:: >>> estimator.estimated_param_ #doctest: +SKIP - From 4f0bb781fd7840d5e6fd23993e601e1cc5ddacd4 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 10:54:05 -0400 Subject: [PATCH 24/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - mlcomp_sparse_document_classification.py clean of pl --- examples/text/mlcomp_sparse_document_classification.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/text/mlcomp_sparse_document_classification.py b/examples/text/mlcomp_sparse_document_classification.py index c1d2631453d9c..52f9267f3f0eb 100644 --- a/examples/text/mlcomp_sparse_document_classification.py +++ b/examples/text/mlcomp_sparse_document_classification.py @@ -44,7 +44,7 @@ import os import numpy as np import scipy.sparse as sp -import pylab as pl +import matplotlib.pyplot as pl from sklearn.datasets import load_mlcomp from sklearn.feature_extraction.text import TfidfVectorizer From 4b97a0744983e40d98777f2601b59aecf5a60bbc Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 10:58:40 -0400 Subject: [PATCH 25/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - plot_gpr_noisy_targets.py clean of pl - code does not execute for extraneous reasons - File "examples/gaussian_process/plot_gpr_noisy_targets.py", line 31, in - from sklearn.gaussian_process import GaussianProcessRegressor - ImportError: cannot import name GaussianProcessRegressor --- .../plot_gpr_noisy_targets.py | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/gaussian_process/plot_gpr_noisy_targets.py b/examples/gaussian_process/plot_gpr_noisy_targets.py index 329d0384b40ea..01e3fcb826602 100644 --- a/examples/gaussian_process/plot_gpr_noisy_targets.py +++ b/examples/gaussian_process/plot_gpr_noisy_targets.py @@ -26,7 +26,7 @@ # Licence: BSD 3 clause import numpy as np -from matplotlib import pyplot as pl +from matplotlib import pyplot as plt from sklearn.gaussian_process import GaussianProcessRegressor from sklearn.gaussian_process.kernels import RBF, ConstantKernel as C @@ -61,18 +61,18 @@ def f(x): # Plot the function, the prediction and the 95% confidence interval based on # the MSE -fig = pl.figure() -pl.plot(x, f(x), 'r:', label=u'$f(x) = x\,\sin(x)$') -pl.plot(X, y, 'r.', markersize=10, label=u'Observations') -pl.plot(x, y_pred, 'b-', label=u'Prediction') -pl.fill(np.concatenate([x, x[::-1]]), +fig = plt.figure() +plt.plot(x, f(x), 'r:', label=u'$f(x) = x\,\sin(x)$') +plt.plot(X, y, 'r.', markersize=10, label=u'Observations') +plt.plot(x, y_pred, 'b-', label=u'Prediction') +plt.fill(np.concatenate([x, x[::-1]]), np.concatenate([y_pred - 1.9600 * sigma, (y_pred + 1.9600 * sigma)[::-1]]), alpha=.5, fc='b', ec='None', label='95% confidence interval') -pl.xlabel('$x$') -pl.ylabel('$f(x)$') -pl.ylim(-10, 20) -pl.legend(loc='upper left') +plt.xlabel('$x$') +plt.ylabel('$f(x)$') +plt.ylim(-10, 20) +plt.legend(loc='upper left') # ---------------------------------------------------------------------- # now the noisy case @@ -97,17 +97,17 @@ def f(x): # Plot the function, the prediction and the 95% confidence interval based on # the MSE -fig = pl.figure() -pl.plot(x, f(x), 'r:', label=u'$f(x) = x\,\sin(x)$') -pl.errorbar(X.ravel(), y, dy, fmt='r.', markersize=10, label=u'Observations') -pl.plot(x, y_pred, 'b-', label=u'Prediction') -pl.fill(np.concatenate([x, x[::-1]]), +fig = plt.figure() +plt.plot(x, f(x), 'r:', label=u'$f(x) = x\,\sin(x)$') +plt.errorbar(X.ravel(), y, dy, fmt='r.', markersize=10, label=u'Observations') +plt.plot(x, y_pred, 'b-', label=u'Prediction') +plt.fill(np.concatenate([x, x[::-1]]), np.concatenate([y_pred - 1.9600 * sigma, (y_pred + 1.9600 * sigma)[::-1]]), alpha=.5, fc='b', ec='None', label='95% confidence interval') -pl.xlabel('$x$') -pl.ylabel('$f(x)$') -pl.ylim(-10, 20) -pl.legend(loc='upper left') +plt.xlabel('$x$') +plt.ylabel('$f(x)$') +plt.ylim(-10, 20) +plt.legend(loc='upper left') -pl.show() +plt.show() From 4207d90e9708518b03d0ee0bf602208d1b6581fe Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 11:04:08 -0400 Subject: [PATCH 26/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - plot_gpc_isoprobability.py clean of pl - code does not execute for extraneous reasons - File "examples/gaussian_process/plot_gpc_isoprobability.py", line 24, in - from sklearn.gaussian_process import GaussianProcessClassifier - ImportError: cannot import name GaussianProcessClassifier --- .../plot_gpc_isoprobability.py | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/gaussian_process/plot_gpc_isoprobability.py b/examples/gaussian_process/plot_gpc_isoprobability.py index 21b3a010bf2f3..922dc350d0cb7 100644 --- a/examples/gaussian_process/plot_gpc_isoprobability.py +++ b/examples/gaussian_process/plot_gpc_isoprobability.py @@ -18,7 +18,7 @@ import numpy as np -from matplotlib import pyplot as pl +from matplotlib import pyplot as plt from matplotlib import cm from sklearn.gaussian_process import GaussianProcessClassifier @@ -64,39 +64,39 @@ def g(x): y_prob = y_prob.reshape((res, res)) # Plot the probabilistic classification iso-values -fig = pl.figure(1) +fig = plt.figure(1) ax = fig.gca() ax.axes.set_aspect('equal') -pl.xticks([]) -pl.yticks([]) +plt.xticks([]) +plt.yticks([]) ax.set_xticklabels([]) ax.set_yticklabels([]) -pl.xlabel('$x_1$') -pl.ylabel('$x_2$') +plt.xlabel('$x_1$') +plt.ylabel('$x_2$') -cax = pl.imshow(y_prob, cmap=cm.gray_r, alpha=0.8, +cax = plt.imshow(y_prob, cmap=cm.gray_r, alpha=0.8, extent=(-lim, lim, -lim, lim)) -norm = pl.matplotlib.colors.Normalize(vmin=0., vmax=0.9) -cb = pl.colorbar(cax, ticks=[0., 0.2, 0.4, 0.6, 0.8, 1.], norm=norm) +norm = plt.matplotlib.colors.Normalize(vmin=0., vmax=0.9) +cb = plt.colorbar(cax, ticks=[0., 0.2, 0.4, 0.6, 0.8, 1.], norm=norm) cb.set_label('${\\rm \mathbb{P}}\left[\widehat{G}(\mathbf{x}) \leq 0\\right]$') -pl.clim(0, 1) +plt.clim(0, 1) -pl.plot(X[y <= 0, 0], X[y <= 0, 1], 'r.', markersize=12) +plt.plot(X[y <= 0, 0], X[y <= 0, 1], 'r.', markersize=12) -pl.plot(X[y > 0, 0], X[y > 0, 1], 'b.', markersize=12) +plt.plot(X[y > 0, 0], X[y > 0, 1], 'b.', markersize=12) -cs = pl.contour(x1, x2, y_true, [0.], colors='k', linestyles='dashdot') +cs = plt.contour(x1, x2, y_true, [0.], colors='k', linestyles='dashdot') -cs = pl.contour(x1, x2, y_prob, [0.666], colors='b', +cs = plt.contour(x1, x2, y_prob, [0.666], colors='b', linestyles='solid') -pl.clabel(cs, fontsize=11) +plt.clabel(cs, fontsize=11) -cs = pl.contour(x1, x2, y_prob, [0.5], colors='k', +cs = plt.contour(x1, x2, y_prob, [0.5], colors='k', linestyles='dashed') -pl.clabel(cs, fontsize=11) +plt.clabel(cs, fontsize=11) -cs = pl.contour(x1, x2, y_prob, [0.334], colors='r', +cs = plt.contour(x1, x2, y_prob, [0.334], colors='r', linestyles='solid') -pl.clabel(cs, fontsize=11) +plt.clabel(cs, fontsize=11) -pl.show() +plt.show() From 2582513fe34fb66ddf68a4fb7f4cda9f7138da75 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 11:07:32 -0400 Subject: [PATCH 27/37] docs: removed all pylab references - replaced with matplotlib.pyplot - pl --> plt --- sklearn/datasets/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sklearn/datasets/base.py b/sklearn/datasets/base.py index 27e890a87bc45..4c1fe553f7115 100644 --- a/sklearn/datasets/base.py +++ b/sklearn/datasets/base.py @@ -415,10 +415,10 @@ def load_digits(n_class=10): >>> digits = load_digits() >>> print(digits.data.shape) (1797, 64) - >>> import pylab as pl #doctest: +SKIP - >>> pl.gray() #doctest: +SKIP - >>> pl.matshow(digits.images[0]) #doctest: +SKIP - >>> pl.show() #doctest: +SKIP + >>> import matplotlib.pyplot as plt #doctest: +SKIP + >>> plt.gray() #doctest: +SKIP + >>> plt.matshow(digits.images[0]) #doctest: +SKIP + >>> plt.show() #doctest: +SKIP """ module_path = dirname(__file__) data = np.loadtxt(join(module_path, 'data', 'digits.csv.gz'), From 918ed5814488fe93e92e38fd90cb635e12fe37a0 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 11:10:22 -0400 Subject: [PATCH 28/37] docs: removed all pylab references - replaced with matplotlib.pyplot --- doc/datasets/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/datasets/index.rst b/doc/datasets/index.rst index fb97a16fc9b8a..49d056902c392 100644 --- a/doc/datasets/index.rst +++ b/doc/datasets/index.rst @@ -93,7 +93,7 @@ and pipeline on 2D data. The default coding of images is based on the ``uint8`` dtype to spare memory. Often machine learning algorithms work best if the input is converted to a floating point representation first. Also, - if you plan to use ``pylab.imshow`` don't forget to scale to the range + if you plan to use ``matplotlib.pyplpt.imshow`` don't forget to scale to the range 0 - 1 as done in the following example. .. topic:: Examples: From af2631837e90639318c5eb1e63ca6a7dd50a7f45 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 11:14:41 -0400 Subject: [PATCH 29/37] refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - plot_sparse_coding.py clean of pl - code executes properly --- examples/decomposition/plot_sparse_coding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/decomposition/plot_sparse_coding.py b/examples/decomposition/plot_sparse_coding.py index 7a3704c9fefde..408eedbdbaa4b 100644 --- a/examples/decomposition/plot_sparse_coding.py +++ b/examples/decomposition/plot_sparse_coding.py @@ -17,7 +17,7 @@ print(__doc__) import numpy as np -import matplotlib.pylab as plt +import matplotlib.pyplot as plt from sklearn.decomposition import SparseCoder From 45514eed086970dda46bf89006c312dbf2cf1cbb Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 11:17:02 -0400 Subject: [PATCH 30/37] docs: removed all pylab references - replaced with matplotlib.pyplot --- sklearn/ensemble/partial_dependence.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/ensemble/partial_dependence.py b/sklearn/ensemble/partial_dependence.py index 3b1756ba73d09..0f0fcd9cab552 100644 --- a/sklearn/ensemble/partial_dependence.py +++ b/sklearn/ensemble/partial_dependence.py @@ -208,10 +208,10 @@ def plot_partial_dependence(gbrt, X, features, feature_names=None, ax : Matplotlib axis object, default None An axis object onto which the plots will be drawn. line_kw : dict - Dict with keywords passed to the ``pylab.plot`` call. + Dict with keywords passed to the ``matplotlib.pyplot.plot`` call. For one-way partial dependence plots. contour_kw : dict - Dict with keywords passed to the ``pylab.plot`` call. + Dict with keywords passed to the ``matplotlib.pyplot.plot`` call. For two-way partial dependence plots. fig_kw : dict Dict with keywords passed to the figure() call. From 93482ade8473a7ed1a7ac47aa2316cdee1d80947 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 11:18:03 -0400 Subject: [PATCH 31/37] docs: removed all pylab references - replaced with matplotlib.pyplot --- examples/classification/plot_digits_classification.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/classification/plot_digits_classification.py b/examples/classification/plot_digits_classification.py index d9c2b570336a7..3d21ee591c319 100644 --- a/examples/classification/plot_digits_classification.py +++ b/examples/classification/plot_digits_classification.py @@ -27,7 +27,7 @@ # The data that we are interested in is made of 8x8 images of digits, let's # have a look at the first 4 images, stored in the `images` attribute of the # dataset. If we were working from image files, we could load them using -# pylab.imread. Note that each image must have the same size. For these +# matplotlib.pyplot.imread. Note that each image must have the same size. For these # images, we know which digit they represent: it is given in the 'target' of # the dataset. images_and_labels = list(zip(digits.images, digits.target)) From 0f82942266c440f32a4cdff77aa6d81f86af1669 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 22:33:52 -0400 Subject: [PATCH 32/37] style: Indent properly --- benchmarks/bench_lasso.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmarks/bench_lasso.py b/benchmarks/bench_lasso.py index 97bc8ecdf51cf..7ed774ad2e790 100644 --- a/benchmarks/bench_lasso.py +++ b/benchmarks/bench_lasso.py @@ -74,7 +74,8 @@ def compute_bench(alpha, n_samples, n_features, precompute): label='Lasso') plt.plot(list_n_samples, lars_lasso_results, 'r-', label='LassoLars') - plt.title('precomputed Gram matrix, %d features, alpha=%s' % (n_features, alpha)) + plt.title('precomputed Gram matrix, %d features, alpha=%s' % (n_features, + alpha)) plt.legend(loc='upper left') plt.xlabel('number of samples') plt.ylabel('Time (s)') From 409500602ad8a4d64b2f41fb1f7892fb072c0fc9 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 22:57:43 -0400 Subject: [PATCH 33/37] style: indent properly --- benchmarks/bench_plot_neighbors.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/benchmarks/bench_plot_neighbors.py b/benchmarks/bench_plot_neighbors.py index 8b862017653e1..411c408791fd2 100644 --- a/benchmarks/bench_plot_neighbors.py +++ b/benchmarks/bench_plot_neighbors.py @@ -132,18 +132,18 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11), width = 0.8 c_bar = plt.bar(xvals, build_time[alg] - bottom, - width, bottom, color='r') + width, bottom, color='r') q_bar = plt.bar(xvals, query_time[alg], - width, build_time[alg], color='b') + width, build_time[alg], color='b') tick_vals += list(xvals + 0.5 * width) tick_labels += ['%i' % val for val in vals] plt.text((i + 0.02) / len(algorithms), 0.98, alg, - transform=ax.transAxes, - ha='left', - va='top', - bbox=dict(facecolor='w', edgecolor='w', alpha=0.5)) + transform=ax.transAxes, + ha='left', + va='top', + bbox=dict(facecolor='w', edgecolor='w', alpha=0.5)) plt.ylabel('Time (s)') @@ -167,17 +167,17 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11), descr_string = descr_string[:-2] plt.text(1.01, 0.5, title_string, - transform=ax.transAxes, rotation=-90, - ha='left', va='center', fontsize=20) + transform=ax.transAxes, rotation=-90, + ha='left', va='center', fontsize=20) plt.text(0.99, 0.5, descr_string, - transform=ax.transAxes, rotation=-90, - ha='right', va='center') + transform=ax.transAxes, rotation=-90, + ha='right', va='center') plt.gcf().suptitle("%s data set" % dataset.capitalize(), fontsize=16) plt.figlegend((c_bar, q_bar), ('construction', 'N-point query'), - 'upper right') + 'upper right') if __name__ == '__main__': barplot_neighbors(dataset='digits') From fd9407e16b452fbca9c0ecf15964b701597c4564 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 22:59:55 -0400 Subject: [PATCH 34/37] style: Indent properly --- benchmarks/bench_sgd_regression.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/benchmarks/bench_sgd_regression.py b/benchmarks/bench_sgd_regression.py index 1fe0507a84ae8..fc862b85a0e56 100644 --- a/benchmarks/bench_sgd_regression.py +++ b/benchmarks/bench_sgd_regression.py @@ -114,17 +114,17 @@ i = 0 m = len(list_n_features) plt.figure('scikit-learn SGD regression benchmark results', - figsize=(5 * 2, 4 * m)) + figsize=(5 * 2, 4 * m)) for j in range(m): plt.subplot(m, 2, i + 1) plt.plot(list_n_samples, np.sqrt(elnet_results[:, j, 0]), - label="ElasticNet") + label="ElasticNet") plt.plot(list_n_samples, np.sqrt(sgd_results[:, j, 0]), - label="SGDRegressor") + label="SGDRegressor") plt.plot(list_n_samples, np.sqrt(asgd_results[:, j, 0]), - label="A-SGDRegressor") + label="A-SGDRegressor") plt.plot(list_n_samples, np.sqrt(ridge_results[:, j, 0]), - label="Ridge") + label="Ridge") plt.legend(prop={"size": 10}) plt.xlabel("n_train") plt.ylabel("RMSE") @@ -133,13 +133,13 @@ plt.subplot(m, 2, i + 1) plt.plot(list_n_samples, np.sqrt(elnet_results[:, j, 1]), - label="ElasticNet") + label="ElasticNet") plt.plot(list_n_samples, np.sqrt(sgd_results[:, j, 1]), - label="SGDRegressor") + label="SGDRegressor") plt.plot(list_n_samples, np.sqrt(asgd_results[:, j, 1]), - label="A-SGDRegressor") + label="A-SGDRegressor") plt.plot(list_n_samples, np.sqrt(ridge_results[:, j, 1]), - label="Ridge") + label="Ridge") plt.legend(prop={"size": 10}) plt.xlabel("n_train") plt.ylabel("Time [sec]") From 6ad9fc67a867db9bc4988b5239f1788b8cbad525 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 23:02:27 -0400 Subject: [PATCH 35/37] docs: Add missing .pyplot --- doc/tutorial/statistical_inference/supervised_learning.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorial/statistical_inference/supervised_learning.rst b/doc/tutorial/statistical_inference/supervised_learning.rst index e431d0fea3420..5a0397b24acd4 100644 --- a/doc/tutorial/statistical_inference/supervised_learning.rst +++ b/doc/tutorial/statistical_inference/supervised_learning.rst @@ -212,7 +212,7 @@ induces high variance: >>> test = np.c_[ 0, 2].T >>> regr = linear_model.LinearRegression() - >>> import matplotlib as plt # doctest: +SKIP + >>> import matplotlib.pyplot as plt # doctest: +SKIP >>> plt.figure() # doctest: +SKIP >>> np.random.seed(0) From d327902390f5ccb1b0c21be28614f91dafc84a56 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 23:06:36 -0400 Subject: [PATCH 36/37] docs: Fix typo --- .../skeletons/exercise_01_language_train_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorial/text_analytics/skeletons/exercise_01_language_train_model.py b/doc/tutorial/text_analytics/skeletons/exercise_01_language_train_model.py index d1651b5985a7c..0b56cfc10d837 100644 --- a/doc/tutorial/text_analytics/skeletons/exercise_01_language_train_model.py +++ b/doc/tutorial/text_analytics/skeletons/exercise_01_language_train_model.py @@ -47,7 +47,7 @@ print(cm) #import matplotlib.pyplot as plt -#t.matshow(cm, cmap=plt.cm.jet) +#plt.matshow(cm, cmap=plt.cm.jet) #plt.show() # Predict the result on some short new sentences: From 040b365646800f414440e413966a184c0dca1a30 Mon Sep 17 00:00:00 2001 From: Robert Lutz Date: Mon, 9 May 2016 23:18:18 -0400 Subject: [PATCH 37/37] style: Indent properly --- benchmarks/bench_plot_neighbors.py | 18 +++++++++--------- benchmarks/bench_sgd_regression.py | 18 +++++++++--------- .../plot_gpc_isoprobability.py | 8 ++++---- .../gaussian_process/plot_gpr_noisy_targets.py | 12 ++++++------ 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/benchmarks/bench_plot_neighbors.py b/benchmarks/bench_plot_neighbors.py index 411c408791fd2..19bd22a7157a5 100644 --- a/benchmarks/bench_plot_neighbors.py +++ b/benchmarks/bench_plot_neighbors.py @@ -140,10 +140,10 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11), tick_labels += ['%i' % val for val in vals] plt.text((i + 0.02) / len(algorithms), 0.98, alg, - transform=ax.transAxes, - ha='left', - va='top', - bbox=dict(facecolor='w', edgecolor='w', alpha=0.5)) + transform=ax.transAxes, + ha='left', + va='top', + bbox=dict(facecolor='w', edgecolor='w', alpha=0.5)) plt.ylabel('Time (s)') @@ -167,17 +167,17 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11), descr_string = descr_string[:-2] plt.text(1.01, 0.5, title_string, - transform=ax.transAxes, rotation=-90, - ha='left', va='center', fontsize=20) + transform=ax.transAxes, rotation=-90, + ha='left', va='center', fontsize=20) plt.text(0.99, 0.5, descr_string, - transform=ax.transAxes, rotation=-90, - ha='right', va='center') + transform=ax.transAxes, rotation=-90, + ha='right', va='center') plt.gcf().suptitle("%s data set" % dataset.capitalize(), fontsize=16) plt.figlegend((c_bar, q_bar), ('construction', 'N-point query'), - 'upper right') + 'upper right') if __name__ == '__main__': barplot_neighbors(dataset='digits') diff --git a/benchmarks/bench_sgd_regression.py b/benchmarks/bench_sgd_regression.py index fc862b85a0e56..e66f656114760 100644 --- a/benchmarks/bench_sgd_regression.py +++ b/benchmarks/bench_sgd_regression.py @@ -114,17 +114,17 @@ i = 0 m = len(list_n_features) plt.figure('scikit-learn SGD regression benchmark results', - figsize=(5 * 2, 4 * m)) + figsize=(5 * 2, 4 * m)) for j in range(m): plt.subplot(m, 2, i + 1) plt.plot(list_n_samples, np.sqrt(elnet_results[:, j, 0]), - label="ElasticNet") + label="ElasticNet") plt.plot(list_n_samples, np.sqrt(sgd_results[:, j, 0]), - label="SGDRegressor") + label="SGDRegressor") plt.plot(list_n_samples, np.sqrt(asgd_results[:, j, 0]), - label="A-SGDRegressor") + label="A-SGDRegressor") plt.plot(list_n_samples, np.sqrt(ridge_results[:, j, 0]), - label="Ridge") + label="Ridge") plt.legend(prop={"size": 10}) plt.xlabel("n_train") plt.ylabel("RMSE") @@ -133,13 +133,13 @@ plt.subplot(m, 2, i + 1) plt.plot(list_n_samples, np.sqrt(elnet_results[:, j, 1]), - label="ElasticNet") + label="ElasticNet") plt.plot(list_n_samples, np.sqrt(sgd_results[:, j, 1]), - label="SGDRegressor") + label="SGDRegressor") plt.plot(list_n_samples, np.sqrt(asgd_results[:, j, 1]), - label="A-SGDRegressor") + label="A-SGDRegressor") plt.plot(list_n_samples, np.sqrt(ridge_results[:, j, 1]), - label="Ridge") + label="Ridge") plt.legend(prop={"size": 10}) plt.xlabel("n_train") plt.ylabel("Time [sec]") diff --git a/examples/gaussian_process/plot_gpc_isoprobability.py b/examples/gaussian_process/plot_gpc_isoprobability.py index 922dc350d0cb7..64eeba6d649fd 100644 --- a/examples/gaussian_process/plot_gpc_isoprobability.py +++ b/examples/gaussian_process/plot_gpc_isoprobability.py @@ -75,7 +75,7 @@ def g(x): plt.ylabel('$x_2$') cax = plt.imshow(y_prob, cmap=cm.gray_r, alpha=0.8, - extent=(-lim, lim, -lim, lim)) + extent=(-lim, lim, -lim, lim)) norm = plt.matplotlib.colors.Normalize(vmin=0., vmax=0.9) cb = plt.colorbar(cax, ticks=[0., 0.2, 0.4, 0.6, 0.8, 1.], norm=norm) cb.set_label('${\\rm \mathbb{P}}\left[\widehat{G}(\mathbf{x}) \leq 0\\right]$') @@ -88,15 +88,15 @@ def g(x): cs = plt.contour(x1, x2, y_true, [0.], colors='k', linestyles='dashdot') cs = plt.contour(x1, x2, y_prob, [0.666], colors='b', - linestyles='solid') + linestyles='solid') plt.clabel(cs, fontsize=11) cs = plt.contour(x1, x2, y_prob, [0.5], colors='k', - linestyles='dashed') + linestyles='dashed') plt.clabel(cs, fontsize=11) cs = plt.contour(x1, x2, y_prob, [0.334], colors='r', - linestyles='solid') + linestyles='solid') plt.clabel(cs, fontsize=11) plt.show() diff --git a/examples/gaussian_process/plot_gpr_noisy_targets.py b/examples/gaussian_process/plot_gpr_noisy_targets.py index 01e3fcb826602..d1c313d714509 100644 --- a/examples/gaussian_process/plot_gpr_noisy_targets.py +++ b/examples/gaussian_process/plot_gpr_noisy_targets.py @@ -66,9 +66,9 @@ def f(x): plt.plot(X, y, 'r.', markersize=10, label=u'Observations') plt.plot(x, y_pred, 'b-', label=u'Prediction') plt.fill(np.concatenate([x, x[::-1]]), - np.concatenate([y_pred - 1.9600 * sigma, - (y_pred + 1.9600 * sigma)[::-1]]), - alpha=.5, fc='b', ec='None', label='95% confidence interval') + np.concatenate([y_pred - 1.9600 * sigma, + (y_pred + 1.9600 * sigma)[::-1]]), + alpha=.5, fc='b', ec='None', label='95% confidence interval') plt.xlabel('$x$') plt.ylabel('$f(x)$') plt.ylim(-10, 20) @@ -102,9 +102,9 @@ def f(x): plt.errorbar(X.ravel(), y, dy, fmt='r.', markersize=10, label=u'Observations') plt.plot(x, y_pred, 'b-', label=u'Prediction') plt.fill(np.concatenate([x, x[::-1]]), - np.concatenate([y_pred - 1.9600 * sigma, - (y_pred + 1.9600 * sigma)[::-1]]), - alpha=.5, fc='b', ec='None', label='95% confidence interval') + np.concatenate([y_pred - 1.9600 * sigma, + (y_pred + 1.9600 * sigma)[::-1]]), + alpha=.5, fc='b', ec='None', label='95% confidence interval') plt.xlabel('$x$') plt.ylabel('$f(x)$') plt.ylim(-10, 20)