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
# -*- coding: utf-8 -*- | |
""" | |
Strong rules for coordinate descent | |
Author: Fabian Pedregosa <fabian@fseoane.net> | |
""" | |
import numpy as np | |
from scipy import linalg |
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
# Accessing rows and columns. | |
for ptr in xrange(len(csc.indptr) - 1): | |
strptr = csc.indptr[ptr] | |
endptr = csc.indptr[ptr + 1] | |
temp = xrange(strptr, endptr) | |
if temp: | |
for row in temp: | |
print ptr, csc.data[row], csc.indices[row] |
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 numpy.distutils.system_info import get_info | |
import os | |
from os.path import join | |
import numpy | |
def configuration(): | |
from numpy.distutils.misc_util import Configuration |
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 libc.math cimport fabs, sqrt | |
cimport cython | |
cdef extern from "cblas.h": | |
void daxpy "cblas_daxpy"(int N, double alpha, double *X, int incX, | |
double *Y, int incY) | |
def b(int x): | |
print x |
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") |
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 ElasticNetCV | |
from sklearn.datasets import make_regression | |
import numpy as np | |
from scipy.sparse import csr_matrix | |
X, y = make_regression(n_samples=2000, n_features=2000) | |
clf = ElasticNetCV(n_jobs=4, cv=3, n_alphas=100, fit_intercept=False, l1_ratio=np.linspace(0.1, 0.9, 5)) | |
clf.fit(X, y) |
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 LogisticRegressionCV | |
from sklearn.datasets import make_classification | |
from time import time | |
import numpy as np | |
rng = np.random.RandomState(0) | |
X, y = make_classification(n_samples=2000, n_features=2000, random_state=rng) | |
clf = LogisticRegressionCV(n_jobs=4, Cs=[1, 10, 100, 1000], cv=10) | |
t = time() | |
clf.fit(X, y) |
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.datasets import load_digits, fetch_20newsgroups_vectorized | |
from sklearn.linear_model import LogisticRegressionCV | |
from sklearn.cross_validation import cross_val_score | |
from scipy.sparse import csr_matrix | |
digits = load_digits(n_class=2) | |
X, y = digits.data, digits.target | |
clf = LogisticRegressionCV(solver='liblinear') | |
csr = csr_matrix(X) | |
print cross_val_score(clf, X, y) |
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 numpy as np | |
from scipy import signal | |
rng = np.random.RandomState(42) | |
n_samples, n_features, k = 500, 1000, 10 | |
h = signal.gaussian(50, 15) | |
X = signal.convolve2d(np.eye(n_features), h[:, np.newaxis], 'same') # convolutional design | |
X = X[::n_features // n_samples] |
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 * | |
from sklearn.datasets import * | |
X, y = load_svmlight_file("/home/manoj/Downloads/duke") | |
# Get the best alpha, l1_ratio combination first | |
clf = ElasticNetCV(max_iter=10000, n_jobs=-1) | |
clf.fit(X, y) | |
clf_random = ElasticNet(alpha=clf.alpha_, l1_ratio=clf.l1_ratio_, max_iter=50000, tol=0, random_state=42) | |
clf_random.fit(X.toarray(), y) |
OlderNewer