Skip to content

Instantly share code, notes, and snippets.

View MechCoder's full-sized avatar
💭
away

manoj kumar MechCoder

💭
away
View GitHub Profile
@MechCoder
MechCoder / gsoc.diff
Created September 30, 2013 11:37
GSoC Patch
commit e5ca40b8972b0b7cd2210c1108ac696e94f675ce
Author: Manoj-Kumar-S <manojkumarsivaraj334@gmail.com>
Date: Sat Sep 7 23:53:55 2013 +0530
Changed n to int(n)
diff --git a/sympy/solvers/ode.py b/sympy/solvers/ode.py
index a464f8a..9620b04 100644
--- a/sympy/solvers/ode.py
+++ b/sympy/solvers/ode.py
from sklearn.datasets.samples_generator import make_regression
from scipy import sparse
X, y = make_regression(n_samples=500, n_features=20000, random_state=0)
X[X < 2.5] = 0
mat = sparse.coo_matrix(X)
clf = ElasticNetCV(max_iter=2000)
%timeit clf.fit(mat,y)
1 loops, best of 3: 376 s per loop
clf = ElasticNetCV(max_iter=2000)
%timeit clf.fit(X, y)
Dense data
0 alpha 0.0855941772461
1 alpha 0.0869829654694
2 alpha 0.0868599414825
3 alpha 0.0869789123535
4 alpha 0.0870821475983
5 alpha 0.0872299671173
6 alpha 0.0973160266876
7 alpha 0.0973291397095
# -*- coding: utf-8 -*-
"""
Strong rules for coordinate descent
Author: Fabian Pedregosa <fabian@fseoane.net>
"""
import numpy as np
from scipy import linalg
@MechCoder
MechCoder / sparse.py
Created March 21, 2014 05:32
Sparse matrix handling
# 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]
@MechCoder
MechCoder / setup.py
Last active August 29, 2015 14:00
Setup cblas
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
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
@MechCoder
MechCoder / benchmark.py
Created May 10, 2014 05:57
Benchmarking with gil and with nogil
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")
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)
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)