Created
July 3, 2014 13:11
-
-
Save MechCoder/a35f34cff26d965af401 to your computer and use it in GitHub Desktop.
Bench arcene, normal vs random.
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
from sklearn.linear_model import * | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# This can be got from, https://github.com/scikit-learn/ml-benchmarks/blob/master/benchmarks/data/arcene_train.labels | |
# and https://github.com/scikit-learn/ml-benchmarks/blob/master/benchmarks/data/arcene_train.data | |
f = open("../Downloads/arcene/arcene_train.data") | |
X = np.fromfile(f, dtype=np.float64, sep=' ') | |
X = X.reshape(-1, 10000) | |
f = open("../Downloads/arcene/arcene_train.labels") | |
y = np.fromfile(f, dtype=np.int32, sep=' ') | |
r_dual_gap = [] | |
n_dual_gap = [] | |
print "Here" | |
clf = ElasticNetCV(n_jobs=-1, max_iter=5000) | |
clf.fit(X, y) | |
n_iter = [500, 1000, 2000, 5000, 10000, 20000, 30000, 40000, 50000] | |
for max_iter in n_iter: | |
clf_random = ElasticNet(alpha=clf.alpha_, l1_ratio=0.5, | |
max_iter=max_iter, tol=0, random_state=42) | |
print "................." | |
print "%d number of iterations for random" % max_iter | |
clf_random.fit(X, y) | |
print clf_random.dual_gap_ | |
r_dual_gap.append(clf_random.dual_gap_.tolist()) | |
clf_normal = ElasticNet(alpha=clf.alpha_, l1_ratio=0.5, | |
max_iter=max_iter, tol=0) | |
print "................." | |
print "%d number of iterations for normal" % max_iter | |
clf_normal.fit(X, y) | |
print clf_normal.dual_gap_ | |
n_dual_gap.append(clf_normal.dual_gap_.tolist()) | |
plt.title("Bench arcene with %0.15f" % clf.alpha_) | |
plt.xlabel("No. of iterations ") | |
plt.ylabel("Log of dual gap ") | |
random_ = plt.plot(n_iter, np.log(r_dual_gap), "r-")[0] | |
normal = plt.plot(n_iter, np.log(n_dual_gap), "b-")[0] | |
plt.legend([random_, normal], ["Random descent", "Normal descent"]) | |
plt.savefig("best_alpha_arcene.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment