Created
May 10, 2014 05:57
-
-
Save MechCoder/b18c519ce018dc47b8b3 to your computer and use it in GitHub Desktop.
Benchmarking with gil and with nogil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pylab as pl | |
import numpy as np | |
from sklearn.linear_model import * | |
from sklearn.datasets import make_regression | |
import time | |
def plot(): | |
pl.figure("Benchmark with nogil") | |
n_alphas = [5, 10, 100, 500] | |
l1_ratios = [1, 2, 5, 10] | |
n_samples = [200, 500] | |
n_features = [200, 500] | |
temp = 221 | |
colors = ["b-", "g-", "r-", "c-"] | |
for i, sample in enumerate(n_samples): | |
for j, feature in enumerate(n_features): | |
X, y = make_regression(n_samples=sample, n_features=feature) | |
pl.subplot(temp) | |
temp += 1 | |
for alpha, color in zip(n_alphas, colors): | |
times1= [] | |
for l1_ratio in l1_ratios: | |
n_l1_ratios = np.linspace(0.1, 1, num=l1_ratio) | |
clf = ElasticNetCV() | |
t = time.time() | |
clf.fit(X, y) | |
times1.append(time.time() - t) | |
pl.plot(l1_ratios, times1, color, label=str(alpha)) | |
pl.legend(loc='upper right') | |
pl.title("n_samples=%d, n_features=%d" % (sample, feature)) | |
pl.xlabel('number of l1_ratios') | |
pl.ylabel('Time (s)') | |
pl.axis('tight') | |
#pl.show() | |
pl.savefig("withnogil.png") | |
if __name__ == '__main__': | |
plot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment