Benchmarks for linear_model¶
Ridge-arcene¶
Benchmark setup
from sklearn.linear_model import Ridge from deps import load_data kwargs = {'normalize': False, 'alpha': 0.1} X, y, X_t, y_t = load_data('arcene') obj = Ridge(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
72 function calls in 0.106 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.106 0.106 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.106 0.106 <f>:1(<module>)
1 0.000 0.000 0.106 0.106 /tmp/vb_sklearn/sklearn/linear_model/ridge.py:141(fit)
1 0.000 0.000 0.090 0.090 /tmp/vb_sklearn/sklearn/linear_model/ridge.py:55(ridge_regression)
3 0.089 0.030 0.089 0.030 {numpy.core._dotblas.dot}
1 0.003 0.003 0.012 0.012 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
1 0.000 0.000 0.005 0.005 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
1 0.005 0.005 0.005 0.005 {method 'copy' of 'numpy.ndarray' objects}
2 0.004 0.002 0.004 0.002 {method 'mean' of 'numpy.ndarray' objects}
1 0.000 0.000 0.003 0.003 /tmp/vb_sklearn/sklearn/utils/validation.py:23(safe_asarray)
1 0.000 0.000 0.003 0.003 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
1 0.003 0.003 0.003 0.003 {method 'sum' of 'numpy.ndarray' objects}
1 0.000 0.000 0.001 0.001 /tmp/vb_sklearn/sklearn/linear_model/ridge.py:23(_solve)
1 0.001 0.001 0.001 0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/basic.py:19(solve)
1 0.000 0.000 0.000 0.000 {map}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
4 0.000 0.000 0.000 0.000 {method 'any' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
4 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
3 0.000 0.000 0.000 0.000 {hasattr}
1 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
6 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
4 0.000 0.000 0.000 0.000 {isinstance}
4 0.000 0.000 0.000 0.000 {issubclass}
1 0.000 0.000 0.000 0.000 {getattr}
1 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
1 0.000 0.000 0.000 0.000 {range}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
3 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
2 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/ridge.py
Function: fit at line 141
Total time: 0.098984 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
141 def fit(self, X, y, sample_weight=1.0, solver='auto'):
142 """Fit Ridge regression model
143
144 Parameters
145 ----------
146 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
147 Training data
148
149 y : array-like, shape = [n_samples] or [n_samples, n_responses]
150 Target values
151
152 sample_weight : float or numpy array of shape [n_samples]
153 Individual weights for each sample
154
155 solver : {'auto', 'dense_cholesky', 'sparse_cg'}
156 Solver to use in the computational
157 routines. 'dense_cholesky' will use the standard
158 scipy.linalg.solve function, 'sparse_cg' will use the
159 conjugate gradient solver as found in
160 scipy.sparse.linalg.cg while 'auto' will chose the most
161 appropriate depending on the matrix X.
162
163 Returns
164 -------
165 self : returns an instance of self.
166 """
167 1 2826 2826.0 2.9 X = safe_asarray(X, dtype=np.float)
168 1 25 25.0 0.0 y = np.asarray(y, dtype=np.float)
169
170 X, y, X_mean, y_mean, X_std = \
171 1 4 4.0 0.0 self._center_data(X, y, self.fit_intercept,
172 1 9240 9240.0 9.3 self.normalize, self.copy_X)
173
174 1 4 4.0 0.0 self.coef_ = ridge_regression(X, y, self.alpha, sample_weight,
175 1 86742 86742.0 87.6 solver, self.tol)
176 1 141 141.0 0.1 self._set_intercept(X_mean, y_mean, X_std)
177 1 2 2.0 0.0 return self
Ridge-madelon¶
Benchmark setup
from sklearn.linear_model import Ridge from deps import load_data kwargs = {'normalize': False, 'alpha': 0.1} X, y, X_t, y_t = load_data('madelon') obj = Ridge(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
73 function calls in 0.475 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.475 0.475 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.475 0.475 <f>:1(<module>)
1 0.000 0.000 0.475 0.475 /tmp/vb_sklearn/sklearn/linear_model/ridge.py:141(fit)
1 0.000 0.000 0.432 0.432 /tmp/vb_sklearn/sklearn/linear_model/ridge.py:55(ridge_regression)
3 0.400 0.133 0.400 0.133 {numpy.core._dotblas.dot}
1 0.004 0.004 0.040 0.040 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
1 0.000 0.000 0.032 0.032 /tmp/vb_sklearn/sklearn/linear_model/ridge.py:23(_solve)
1 0.024 0.024 0.032 0.032 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/basic.py:19(solve)
2 0.030 0.015 0.030 0.015 {method 'mean' of 'numpy.ndarray' objects}
1 0.000 0.000 0.008 0.008 {map}
2 0.007 0.003 0.008 0.004 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
1 0.000 0.000 0.006 0.006 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
1 0.005 0.005 0.005 0.005 {method 'copy' of 'numpy.ndarray' objects}
1 0.000 0.000 0.003 0.003 /tmp/vb_sklearn/sklearn/utils/validation.py:23(safe_asarray)
1 0.000 0.000 0.003 0.003 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
1 0.003 0.003 0.003 0.003 {method 'sum' of 'numpy.ndarray' objects}
4 0.001 0.000 0.001 0.000 {method 'any' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
4 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
3 0.000 0.000 0.000 0.000 {hasattr}
6 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
5 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
4 0.000 0.000 0.000 0.000 {issubclass}
1 0.000 0.000 0.000 0.000 {getattr}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
1 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
1 0.000 0.000 0.000 0.000 {range}
3 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
2 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/ridge.py
Function: fit at line 141
Total time: 0.531613 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
141 def fit(self, X, y, sample_weight=1.0, solver='auto'):
142 """Fit Ridge regression model
143
144 Parameters
145 ----------
146 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
147 Training data
148
149 y : array-like, shape = [n_samples] or [n_samples, n_responses]
150 Target values
151
152 sample_weight : float or numpy array of shape [n_samples]
153 Individual weights for each sample
154
155 solver : {'auto', 'dense_cholesky', 'sparse_cg'}
156 Solver to use in the computational
157 routines. 'dense_cholesky' will use the standard
158 scipy.linalg.solve function, 'sparse_cg' will use the
159 conjugate gradient solver as found in
160 scipy.sparse.linalg.cg while 'auto' will chose the most
161 appropriate depending on the matrix X.
162
163 Returns
164 -------
165 self : returns an instance of self.
166 """
167 1 2807 2807.0 0.5 X = safe_asarray(X, dtype=np.float)
168 1 31 31.0 0.0 y = np.asarray(y, dtype=np.float)
169
170 X, y, X_mean, y_mean, X_std = \
171 1 4 4.0 0.0 self._center_data(X, y, self.fit_intercept,
172 1 47228 47228.0 8.9 self.normalize, self.copy_X)
173
174 1 4 4.0 0.0 self.coef_ = ridge_regression(X, y, self.alpha, sample_weight,
175 1 481479 481479.0 90.6 solver, self.tol)
176 1 57 57.0 0.0 self._set_intercept(X_mean, y_mean, X_std)
177 1 3 3.0 0.0 return self
Lars-minimadelon-oney¶
Benchmark setup
from sklearn.linear_model import Lars from deps import load_data kwargs = {'normalize': False} X, y, X_t, y_t = load_data('minimadelon-oney') obj = Lars(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
7127 function calls in 0.520 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.520 0.520 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.520 0.520 <f>:1(<module>)
1 0.000 0.000 0.520 0.520 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:420(fit)
1 0.428 0.428 0.519 0.519 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:26(lars_path)
1520 0.052 0.000 0.052 0.000 {numpy.core._dotblas.dot}
502 0.002 0.000 0.010 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
259 0.009 0.000 0.009 0.000 {sklearn.utils.arrayfuncs.solve_triangular}
1500 0.009 0.000 0.009 0.000 {sklearn.utils.arrayfuncs.min_pos}
502 0.006 0.000 0.006 0.000 {method 'sum' of 'numpy.ndarray' objects}
501 0.001 0.000 0.004 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:683(argmax)
501 0.003 0.000 0.003 0.000 {method 'argmax' of 'numpy.ndarray' objects}
501 0.003 0.000 0.003 0.000 {min}
507 0.002 0.000 0.002 0.000 {isinstance}
242 0.002 0.000 0.002 0.000 {numpy.core.multiarray.where}
2 0.001 0.001 0.001 0.001 {numpy.core.multiarray.zeros}
261 0.001 0.000 0.001 0.000 {max}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
2 0.000 0.000 0.000 0.000 {method 'mean' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
264 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
2 0.000 0.000 0.000 0.000 {method 'copy' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/blas.py:30(get_blas_funcs)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/getlimits.py:91(__new__)
3 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
6 0.000 0.000 0.000 0.000 {getattr}
6 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.arange}
5 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:408(_get_gram)
3 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
1 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
2 0.000 0.000 0.000 0.000 {hasattr}
2 0.000 0.000 0.000 0.000 {issubclass}
4 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 {range}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
1 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/least_angle.py
Function: fit at line 420
Total time: 0.710206 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
420 def fit(self, X, y):
421 """Fit the model using X, y as training data.
422
423 parameters
424 ----------
425 X : array-like, shape = [n_samples, n_features]
426 training data.
427
428 y : array-like, shape = [n_samples]
429 target values.
430
431 returns
432 -------
433 self : object
434 returns an instance of self.
435 """
436 1 86 86.0 0.0 X = array2d(X)
437 1 8 8.0 0.0 y = np.asarray(y)
438
439 1 3 3.0 0.0 X, y, X_mean, y_mean, X_std = self._center_data(X, y,
440 1 3 3.0 0.0 self.fit_intercept,
441 1 3 3.0 0.0 self.normalize,
442 1 370 370.0 0.1 self.copy_X)
443 1 11 11.0 0.0 alpha = getattr(self, 'alpha', 0.)
444 1 3 3.0 0.0 if hasattr(self, 'n_nonzero_coefs'):
445 1 3 3.0 0.0 alpha = 0. # n_nonzero_coefs parametrization takes priority
446 1 3 3.0 0.0 max_iter = self.n_nonzero_coefs
447 else:
448 max_iter = self.max_iter
449
450 1 12 12.0 0.0 Gram = self._get_gram()
451
452 1 3 3.0 0.0 self.alphas_, self.active_, self.coef_path_ = lars_path(X, y,
453 1 3 3.0 0.0 Gram=Gram, copy_X=self.copy_X,
454 1 3 3.0 0.0 copy_Gram=False, alpha_min=alpha,
455 1 6 6.0 0.0 method=self.method, verbose=max(0, self.verbose - 1),
456 1 709628 709628.0 99.9 max_iter=max_iter, eps=self.eps)
457
458 1 9 9.0 0.0 self.coef_ = self.coef_path_[:, -1]
459
460 1 46 46.0 0.0 self._set_intercept(X_mean, y_mean, X_std)
461
462 1 3 3.0 0.0 return self
Lars-madelon¶
Benchmark setup
from sklearn.linear_model import Lars from deps import load_data kwargs = {'normalize': False} X, y, X_t, y_t = load_data('madelon') obj = Lars(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
7021 function calls in 1.354 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 1.354 1.354 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 1.354 1.354 <f>:1(<module>)
1 0.000 0.000 1.354 1.354 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:420(fit)
1 0.742 0.742 1.331 1.331 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:26(lars_path)
982 0.515 0.001 0.515 0.001 {numpy.core._dotblas.dot}
479 0.041 0.000 0.041 0.000 {sklearn.utils.arrayfuncs.solve_triangular}
1 0.002 0.002 0.023 0.023 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
2 0.017 0.008 0.017 0.008 {method 'mean' of 'numpy.ndarray' objects}
501 0.001 0.000 0.016 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:683(argmax)
501 0.015 0.000 0.015 0.000 {method 'argmax' of 'numpy.ndarray' objects}
500 0.002 0.000 0.007 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
1500 0.005 0.000 0.005 0.000 {sklearn.utils.arrayfuncs.min_pos}
500 0.005 0.000 0.005 0.000 {method 'sum' of 'numpy.ndarray' objects}
1 0.000 0.000 0.004 0.004 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
1 0.004 0.004 0.004 0.004 {method 'copy' of 'numpy.ndarray' objects}
501 0.002 0.000 0.002 0.000 {min}
505 0.001 0.000 0.001 0.000 {isinstance}
481 0.001 0.000 0.001 0.000 {max}
2 0.001 0.000 0.001 0.000 {numpy.core.multiarray.zeros}
21 0.000 0.000 0.000 0.000 {numpy.core.multiarray.where}
484 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/blas.py:30(get_blas_funcs)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/getlimits.py:91(__new__)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
3 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
5 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects}
6 0.000 0.000 0.000 0.000 {getattr}
6 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.arange}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
3 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
1 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:408(_get_gram)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
2 0.000 0.000 0.000 0.000 {hasattr}
1 0.000 0.000 0.000 0.000 {range}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
1 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
2 0.000 0.000 0.000 0.000 {issubclass}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
4 0.000 0.000 0.000 0.000 {len}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/least_angle.py
Function: fit at line 420
Total time: 1.48593 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
420 def fit(self, X, y):
421 """Fit the model using X, y as training data.
422
423 parameters
424 ----------
425 X : array-like, shape = [n_samples, n_features]
426 training data.
427
428 y : array-like, shape = [n_samples]
429 target values.
430
431 returns
432 -------
433 self : object
434 returns an instance of self.
435 """
436 1 68 68.0 0.0 X = array2d(X)
437 1 8 8.0 0.0 y = np.asarray(y)
438
439 1 4 4.0 0.0 X, y, X_mean, y_mean, X_std = self._center_data(X, y,
440 1 3 3.0 0.0 self.fit_intercept,
441 1 3 3.0 0.0 self.normalize,
442 1 36327 36327.0 2.4 self.copy_X)
443 1 12 12.0 0.0 alpha = getattr(self, 'alpha', 0.)
444 1 5 5.0 0.0 if hasattr(self, 'n_nonzero_coefs'):
445 1 3 3.0 0.0 alpha = 0. # n_nonzero_coefs parametrization takes priority
446 1 3 3.0 0.0 max_iter = self.n_nonzero_coefs
447 else:
448 max_iter = self.max_iter
449
450 1 13 13.0 0.0 Gram = self._get_gram()
451
452 1 3 3.0 0.0 self.alphas_, self.active_, self.coef_path_ = lars_path(X, y,
453 1 3 3.0 0.0 Gram=Gram, copy_X=self.copy_X,
454 1 3 3.0 0.0 copy_Gram=False, alpha_min=alpha,
455 1 7 7.0 0.0 method=self.method, verbose=max(0, self.verbose - 1),
456 1 1449360 1449360.0 97.5 max_iter=max_iter, eps=self.eps)
457
458 1 10 10.0 0.0 self.coef_ = self.coef_path_[:, -1]
459
460 1 88 88.0 0.0 self._set_intercept(X_mean, y_mean, X_std)
461
462 1 3 3.0 0.0 return self
LassoLars-minimadelon-oney¶
Benchmark setup
from sklearn.linear_model import LassoLars from deps import load_data kwargs = {'normalize': False, 'alpha': 0.1} X, y, X_t, y_t = load_data('minimadelon-oney') obj = LassoLars(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
13352 function calls in 0.705 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.705 0.705 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.705 0.705 <f>:1(<module>)
1 0.000 0.000 0.705 0.705 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:420(fit)
1 0.554 0.554 0.704 0.704 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:26(lars_path)
2004 0.094 0.000 0.094 0.000 {numpy.core._dotblas.dot}
94 0.002 0.000 0.018 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:3267(delete)
94 0.002 0.000 0.015 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:376(setdiff1d)
407 0.014 0.000 0.014 0.000 {sklearn.utils.arrayfuncs.solve_triangular}
188 0.003 0.000 0.007 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:90(unique)
94 0.002 0.000 0.006 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:281(in1d)
500 0.001 0.000 0.006 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
1500 0.005 0.000 0.005 0.000 {sklearn.utils.arrayfuncs.min_pos}
564 0.005 0.000 0.005 0.000 {numpy.core.multiarray.concatenate}
94 0.002 0.000 0.004 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:237(__getitem__)
500 0.003 0.000 0.003 0.000 {method 'sum' of 'numpy.ndarray' objects}
501 0.001 0.000 0.002 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:683(argmax)
188 0.002 0.000 0.002 0.000 {method 'argsort' of 'numpy.ndarray' objects}
501 0.002 0.000 0.002 0.000 {min}
501 0.002 0.000 0.002 0.000 {method 'argmax' of 'numpy.ndarray' objects}
1069 0.002 0.000 0.002 0.000 {isinstance}
94 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:3525(append)
567 0.001 0.000 0.001 0.000 {numpy.core.multiarray.array}
94 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:961(find_common_type)
284 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
2 0.001 0.000 0.001 0.000 {numpy.core.multiarray.zeros}
188 0.001 0.000 0.001 0.000 {method 'sort' of 'numpy.ndarray' objects}
94 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1044(ravel)
409 0.001 0.000 0.001 0.000 {max}
95 0.001 0.000 0.001 0.000 {numpy.core.multiarray.arange}
188 0.000 0.000 0.000 0.000 {method 'flatten' of 'numpy.ndarray' objects}
94 0.000 0.000 0.000 0.000 {sklearn.utils.arrayfuncs.cholesky_delete}
94 0.000 0.000 0.000 0.000 {numpy.core.multiarray.where}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
95 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
882 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
188 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:946(_can_coerce_all)
94 0.000 0.000 0.000 0.000 {method 'astype' of 'numpy.ndarray' objects}
189 0.000 0.000 0.000 0.000 {range}
94 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:217(_retval)
94 0.000 0.000 0.000 0.000 {method 'pop' of 'list' objects}
188 0.000 0.000 0.000 0.000 {method 'index' of 'list' objects}
2 0.000 0.000 0.000 0.000 {method 'mean' of 'numpy.ndarray' objects}
94 0.000 0.000 0.000 0.000 {method 'ravel' of 'numpy.ndarray' objects}
380 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
1 0.000 0.000 0.000 0.000 {method 'copy' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/blas.py:30(get_blas_funcs)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/getlimits.py:91(__new__)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
3 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
5 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects}
6 0.000 0.000 0.000 0.000 {getattr}
6 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
2 0.000 0.000 0.000 0.000 {hasattr}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:408(_get_gram)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
2 0.000 0.000 0.000 0.000 {issubclass}
1 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/least_angle.py
Function: fit at line 420
Total time: 0.939889 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
420 def fit(self, X, y):
421 """Fit the model using X, y as training data.
422
423 parameters
424 ----------
425 X : array-like, shape = [n_samples, n_features]
426 training data.
427
428 y : array-like, shape = [n_samples]
429 target values.
430
431 returns
432 -------
433 self : object
434 returns an instance of self.
435 """
436 1 39 39.0 0.0 X = array2d(X)
437 1 5 5.0 0.0 y = np.asarray(y)
438
439 1 2 2.0 0.0 X, y, X_mean, y_mean, X_std = self._center_data(X, y,
440 1 1 1.0 0.0 self.fit_intercept,
441 1 2 2.0 0.0 self.normalize,
442 1 196 196.0 0.0 self.copy_X)
443 1 4 4.0 0.0 alpha = getattr(self, 'alpha', 0.)
444 1 4 4.0 0.0 if hasattr(self, 'n_nonzero_coefs'):
445 alpha = 0. # n_nonzero_coefs parametrization takes priority
446 max_iter = self.n_nonzero_coefs
447 else:
448 1 2 2.0 0.0 max_iter = self.max_iter
449
450 1 7 7.0 0.0 Gram = self._get_gram()
451
452 1 2 2.0 0.0 self.alphas_, self.active_, self.coef_path_ = lars_path(X, y,
453 1 1 1.0 0.0 Gram=Gram, copy_X=self.copy_X,
454 1 2 2.0 0.0 copy_Gram=False, alpha_min=alpha,
455 1 3 3.0 0.0 method=self.method, verbose=max(0, self.verbose - 1),
456 1 939568 939568.0 100.0 max_iter=max_iter, eps=self.eps)
457
458 1 10 10.0 0.0 self.coef_ = self.coef_path_[:, -1]
459
460 1 38 38.0 0.0 self._set_intercept(X_mean, y_mean, X_std)
461
462 1 3 3.0 0.0 return self
LassoLars-madelon¶
Benchmark setup
from sklearn.linear_model import LassoLars from deps import load_data kwargs = {'normalize': False, 'alpha': 0.1} X, y, X_t, y_t = load_data('madelon') obj = LassoLars(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
5367 function calls in 0.969 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.969 0.969 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.969 0.969 <f>:1(<module>)
1 0.000 0.000 0.969 0.969 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:420(fit)
1 0.396 0.396 0.928 0.928 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:26(lars_path)
722 0.467 0.001 0.467 0.001 {numpy.core._dotblas.dot}
352 0.042 0.000 0.042 0.000 {sklearn.utils.arrayfuncs.solve_triangular}
1 0.005 0.005 0.042 0.042 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
2 0.030 0.015 0.030 0.015 {method 'mean' of 'numpy.ndarray' objects}
357 0.001 0.000 0.006 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
1 0.000 0.000 0.006 0.006 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
1 0.005 0.005 0.005 0.005 {method 'copy' of 'numpy.ndarray' objects}
1071 0.005 0.000 0.005 0.000 {sklearn.utils.arrayfuncs.min_pos}
357 0.004 0.000 0.004 0.000 {method 'sum' of 'numpy.ndarray' objects}
358 0.001 0.000 0.003 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:683(argmax)
358 0.002 0.000 0.002 0.000 {method 'argmax' of 'numpy.ndarray' objects}
358 0.002 0.000 0.002 0.000 {min}
5 0.000 0.000 0.002 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:3267(delete)
5 0.000 0.000 0.002 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:376(setdiff1d)
392 0.001 0.000 0.001 0.000 {isinstance}
2 0.001 0.001 0.001 0.001 {numpy.core.multiarray.zeros}
10 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:90(unique)
5 0.001 0.000 0.001 0.000 {sklearn.utils.arrayfuncs.cholesky_delete}
354 0.001 0.000 0.001 0.000 {max}
5 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:237(__getitem__)
5 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:281(in1d)
30 0.001 0.000 0.001 0.000 {numpy.core.multiarray.concatenate}
10 0.000 0.000 0.000 0.000 {method 'argsort' of 'numpy.ndarray' objects}
382 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:3525(append)
33 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
6 0.000 0.000 0.000 0.000 {numpy.core.multiarray.arange}
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:961(find_common_type)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/blas.py:30(get_blas_funcs)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
17 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
10 0.000 0.000 0.000 0.000 {method 'sort' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
10 0.000 0.000 0.000 0.000 {method 'flatten' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1044(ravel)
11 0.000 0.000 0.000 0.000 {range}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
6 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/getlimits.py:91(__new__)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
3 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
5 0.000 0.000 0.000 0.000 {numpy.core.multiarray.where}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
5 0.000 0.000 0.000 0.000 {method 'astype' of 'numpy.ndarray' objects}
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/index_tricks.py:217(_retval)
10 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numerictypes.py:946(_can_coerce_all)
5 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects}
6 0.000 0.000 0.000 0.000 {getattr}
2 0.000 0.000 0.000 0.000 {hasattr}
5 0.000 0.000 0.000 0.000 {method 'pop' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
6 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/least_angle.py:408(_get_gram)
24 0.000 0.000 0.000 0.000 {len}
5 0.000 0.000 0.000 0.000 {method 'ravel' of 'numpy.ndarray' objects}
10 0.000 0.000 0.000 0.000 {method 'index' of 'list' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
1 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
2 0.000 0.000 0.000 0.000 {issubclass}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/least_angle.py
Function: fit at line 420
Total time: 1.16844 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
420 def fit(self, X, y):
421 """Fit the model using X, y as training data.
422
423 parameters
424 ----------
425 X : array-like, shape = [n_samples, n_features]
426 training data.
427
428 y : array-like, shape = [n_samples]
429 target values.
430
431 returns
432 -------
433 self : object
434 returns an instance of self.
435 """
436 1 60 60.0 0.0 X = array2d(X)
437 1 8 8.0 0.0 y = np.asarray(y)
438
439 1 3 3.0 0.0 X, y, X_mean, y_mean, X_std = self._center_data(X, y,
440 1 2 2.0 0.0 self.fit_intercept,
441 1 3 3.0 0.0 self.normalize,
442 1 46830 46830.0 4.0 self.copy_X)
443 1 7 7.0 0.0 alpha = getattr(self, 'alpha', 0.)
444 1 11 11.0 0.0 if hasattr(self, 'n_nonzero_coefs'):
445 alpha = 0. # n_nonzero_coefs parametrization takes priority
446 max_iter = self.n_nonzero_coefs
447 else:
448 1 3 3.0 0.0 max_iter = self.max_iter
449
450 1 13 13.0 0.0 Gram = self._get_gram()
451
452 1 3 3.0 0.0 self.alphas_, self.active_, self.coef_path_ = lars_path(X, y,
453 1 3 3.0 0.0 Gram=Gram, copy_X=self.copy_X,
454 1 3 3.0 0.0 copy_Gram=False, alpha_min=alpha,
455 1 7 7.0 0.0 method=self.method, verbose=max(0, self.verbose - 1),
456 1 1121433 1121433.0 96.0 max_iter=max_iter, eps=self.eps)
457
458 1 9 9.0 0.0 self.coef_ = self.coef_path_[:, -1]
459
460 1 43 43.0 0.0 self._set_intercept(X_mean, y_mean, X_std)
461
462 1 3 3.0 0.0 return self
Lasso-minimadelon-oney¶
Benchmark setup
from sklearn.linear_model import Lasso from deps import load_data kwargs = {'normalize': False, 'alpha': 0.1} X, y, X_t, y_t = load_data('minimadelon-oney') obj = Lasso(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
64 function calls in 0.004 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.004 0.004 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.004 0.004 <f>:1(<module>)
1 0.000 0.000 0.004 0.004 /tmp/vb_sklearn/sklearn/linear_model/coordinate_descent.py:131(fit)
1 0.000 0.000 0.004 0.004 /tmp/vb_sklearn/sklearn/linear_model/coordinate_descent.py:161(_dense_fit)
1 0.003 0.003 0.003 0.003 {sklearn.linear_model.cd_fast.enet_coordinate_descent}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/linalg/linalg.py:1840(norm)
2 0.000 0.000 0.000 0.000 {method 'mean' of 'numpy.ndarray' objects}
8 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:325(asfortranarray)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
1 0.000 0.000 0.000 0.000 {method 'copy' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
6 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
2 0.000 0.000 0.000 0.000 {abs}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
1 0.000 0.000 0.000 0.000 {method 'max' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 {method 'sum' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
2 0.000 0.000 0.000 0.000 {method 'reduce' of 'numpy.ufunc' objects}
2 0.000 0.000 0.000 0.000 {hasattr}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.zeros}
4 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
2 0.000 0.000 0.000 0.000 {method 'ravel' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {numpy.core._dotblas.dot}
4 0.000 0.000 0.000 0.000 {isinstance}
3 0.000 0.000 0.000 0.000 {method 'conj' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/coordinate_descent.py
Function: fit at line 131
Total time: 0.003799 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
131 def fit(self, X, y, Xy=None, coef_init=None):
132 """Fit Elastic Net model with coordinate descent
133
134 Parameters
135 -----------
136 X: ndarray or scipy.sparse matrix, (n_samples, n_features)
137 Data
138 y: ndarray, (n_samples)
139 Target
140 Xy : array-like, optional
141 Xy = np.dot(X.T, y) that can be precomputed. It is useful
142 only when the Gram matrix is precomputed.
143 coef_init: ndarray of shape n_features
144 The initial coeffients to warm-start the optimization
145
146 Notes
147 -----
148
149 Coordinate descent is an algorithm that considers each column of
150 data at a time hence it will automatically convert the X input
151 as a fortran contiguous numpy array if necessary.
152
153 To avoid memory re-allocation it is advised to allocate the
154 initial data in memory directly using that format.
155 """
156
157 1 27 27.0 0.7 fit = self._sparse_fit if sparse.isspmatrix(X) else self._dense_fit
158 1 3770 3770.0 99.2 fit(X, y, Xy, coef_init)
159 1 2 2.0 0.1 return self
Lasso-madelon¶
Benchmark setup
from sklearn.linear_model import Lasso from deps import load_data kwargs = {'normalize': False, 'alpha': 0.1} X, y, X_t, y_t = load_data('madelon') obj = Lasso(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
63 function calls in 0.878 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.878 0.878 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.878 0.878 <f>:1(<module>)
1 0.000 0.000 0.878 0.878 /tmp/vb_sklearn/sklearn/linear_model/coordinate_descent.py:131(fit)
1 0.000 0.000 0.878 0.878 /tmp/vb_sklearn/sklearn/linear_model/coordinate_descent.py:161(_dense_fit)
1 0.478 0.478 0.478 0.478 {sklearn.linear_model.cd_fast.enet_coordinate_descent_gram}
3 0.345 0.115 0.345 0.115 {numpy.core._dotblas.dot}
1 0.004 0.004 0.040 0.040 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
2 0.030 0.015 0.030 0.015 {method 'mean' of 'numpy.ndarray' objects}
7 0.014 0.002 0.014 0.002 {numpy.core.multiarray.array}
1 0.000 0.000 0.014 0.014 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:325(asfortranarray)
1 0.000 0.000 0.005 0.005 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
1 0.005 0.005 0.005 0.005 {method 'copy' of 'numpy.ndarray' objects}
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/linalg/linalg.py:1840(norm)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
2 0.000 0.000 0.000 0.000 {abs}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
3 0.000 0.000 0.000 0.000 {method 'sum' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {method 'max' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 {hasattr}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
1 0.000 0.000 0.000 0.000 {method 'reduce' of 'numpy.ufunc' objects}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
5 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.zeros}
4 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {method 'ravel' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 {method 'conj' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/coordinate_descent.py
Function: fit at line 131
Total time: 0.978558 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
131 def fit(self, X, y, Xy=None, coef_init=None):
132 """Fit Elastic Net model with coordinate descent
133
134 Parameters
135 -----------
136 X: ndarray or scipy.sparse matrix, (n_samples, n_features)
137 Data
138 y: ndarray, (n_samples)
139 Target
140 Xy : array-like, optional
141 Xy = np.dot(X.T, y) that can be precomputed. It is useful
142 only when the Gram matrix is precomputed.
143 coef_init: ndarray of shape n_features
144 The initial coeffients to warm-start the optimization
145
146 Notes
147 -----
148
149 Coordinate descent is an algorithm that considers each column of
150 data at a time hence it will automatically convert the X input
151 as a fortran contiguous numpy array if necessary.
152
153 To avoid memory re-allocation it is advised to allocate the
154 initial data in memory directly using that format.
155 """
156
157 1 30 30.0 0.0 fit = self._sparse_fit if sparse.isspmatrix(X) else self._dense_fit
158 1 978525 978525.0 100.0 fit(X, y, Xy, coef_init)
159 1 3 3.0 0.0 return self
ElasticNet-minimadelon-oney¶
Benchmark setup
from sklearn.linear_model import ElasticNet from deps import load_data kwargs = {'alpha': 0.5, 'rho': 0.5} X, y, X_t, y_t = load_data('minimadelon-oney') obj = ElasticNet(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
64 function calls in 0.025 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.025 0.025 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.025 0.025 <f>:1(<module>)
1 0.000 0.000 0.025 0.025 /tmp/vb_sklearn/sklearn/linear_model/coordinate_descent.py:131(fit)
1 0.000 0.000 0.025 0.025 /tmp/vb_sklearn/sklearn/linear_model/coordinate_descent.py:161(_dense_fit)
1 0.024 0.024 0.024 0.024 {sklearn.linear_model.cd_fast.enet_coordinate_descent}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/linalg/linalg.py:1840(norm)
2 0.000 0.000 0.000 0.000 {method 'mean' of 'numpy.ndarray' objects}
8 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:325(asfortranarray)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
1 0.000 0.000 0.000 0.000 {method 'copy' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
6 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
2 0.000 0.000 0.000 0.000 {abs}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
1 0.000 0.000 0.000 0.000 {method 'max' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 {method 'sum' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 {method 'reduce' of 'numpy.ufunc' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.zeros}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
2 0.000 0.000 0.000 0.000 {hasattr}
4 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
4 0.000 0.000 0.000 0.000 {isinstance}
2 0.000 0.000 0.000 0.000 {method 'ravel' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {numpy.core._dotblas.dot}
3 0.000 0.000 0.000 0.000 {method 'conj' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/base.py
Function: predict at line 122
Total time: 0 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
122 def predict(self, X):
123 """Predict using the linear model
124
125 Parameters
126 ----------
127 X : numpy array of shape [n_samples, n_features]
128
129 Returns
130 -------
131 C : array, shape = [n_samples]
132 Returns predicted values.
133 """
134 return self.decision_function(X)
File: /tmp/vb_sklearn/sklearn/linear_model/coordinate_descent.py
Function: fit at line 131
Total time: 0.024867 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
131 def fit(self, X, y, Xy=None, coef_init=None):
132 """Fit Elastic Net model with coordinate descent
133
134 Parameters
135 -----------
136 X: ndarray or scipy.sparse matrix, (n_samples, n_features)
137 Data
138 y: ndarray, (n_samples)
139 Target
140 Xy : array-like, optional
141 Xy = np.dot(X.T, y) that can be precomputed. It is useful
142 only when the Gram matrix is precomputed.
143 coef_init: ndarray of shape n_features
144 The initial coeffients to warm-start the optimization
145
146 Notes
147 -----
148
149 Coordinate descent is an algorithm that considers each column of
150 data at a time hence it will automatically convert the X input
151 as a fortran contiguous numpy array if necessary.
152
153 To avoid memory re-allocation it is advised to allocate the
154 initial data in memory directly using that format.
155 """
156
157 1 26 26.0 0.1 fit = self._sparse_fit if sparse.isspmatrix(X) else self._dense_fit
158 1 24839 24839.0 99.9 fit(X, y, Xy, coef_init)
159 1 2 2.0 0.0 return self
Benchmark statement
obj.predict(X_t)
Execution time
Memory usage
Additional output
cProfile
33 function calls in 0.000 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.000 0.000 <f>:1(<module>)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:122(predict)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/coordinate_descent.py:275(decision_function)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:107(decision_function)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:23(safe_asarray)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 {method 'sum' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {numpy.core._dotblas.dot}
8 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
4 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/base.py
Function: predict at line 122
Total time: 0.000221 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
122 def predict(self, X):
123 """Predict using the linear model
124
125 Parameters
126 ----------
127 X : numpy array of shape [n_samples, n_features]
128
129 Returns
130 -------
131 C : array, shape = [n_samples]
132 Returns predicted values.
133 """
134 1 221 221.0 100.0 return self.decision_function(X)
File: /tmp/vb_sklearn/sklearn/linear_model/coordinate_descent.py
Function: fit at line 131
Total time: 0.024867 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
131 def fit(self, X, y, Xy=None, coef_init=None):
132 """Fit Elastic Net model with coordinate descent
133
134 Parameters
135 -----------
136 X: ndarray or scipy.sparse matrix, (n_samples, n_features)
137 Data
138 y: ndarray, (n_samples)
139 Target
140 Xy : array-like, optional
141 Xy = np.dot(X.T, y) that can be precomputed. It is useful
142 only when the Gram matrix is precomputed.
143 coef_init: ndarray of shape n_features
144 The initial coeffients to warm-start the optimization
145
146 Notes
147 -----
148
149 Coordinate descent is an algorithm that considers each column of
150 data at a time hence it will automatically convert the X input
151 as a fortran contiguous numpy array if necessary.
152
153 To avoid memory re-allocation it is advised to allocate the
154 initial data in memory directly using that format.
155 """
156
157 1 26 26.0 0.1 fit = self._sparse_fit if sparse.isspmatrix(X) else self._dense_fit
158 1 24839 24839.0 99.9 fit(X, y, Xy, coef_init)
159 1 2 2.0 0.0 return self
OrthogonalMatchingPursuit-minimadelon¶
Benchmark setup
from sklearn.linear_model import OrthogonalMatchingPursuit from deps import load_data kwargs = {'n_nonzero_coefs': 10} X, y, X_t, y_t = load_data('minimadelon') obj = OrthogonalMatchingPursuit(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
947 function calls in 0.023 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.023 0.023 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.023 0.023 <f>:1(<module>)
1 0.000 0.000 0.023 0.023 /tmp/vb_sklearn/sklearn/linear_model/omp.py:484(fit)
1 0.001 0.001 0.022 0.022 /tmp/vb_sklearn/sklearn/linear_model/omp.py:206(orthogonal_mp)
10 0.014 0.001 0.021 0.002 /tmp/vb_sklearn/sklearn/linear_model/omp.py:24(_cholesky_omp)
301 0.004 0.000 0.004 0.000 {numpy.core._dotblas.dot}
1 0.001 0.001 0.001 0.001 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
100 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:683(argmax)
100 0.001 0.000 0.001 0.000 {method 'argmax' of 'numpy.ndarray' objects}
12 0.001 0.000 0.001 0.000 {method 'copy' of 'numpy.ndarray' objects}
10 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
10 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/blas.py:30(get_blas_funcs)
90 0.000 0.000 0.000 0.000 {sklearn.utils.arrayfuncs.solve_triangular}
10 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
2 0.000 0.000 0.000 0.000 {method 'mean' of 'numpy.ndarray' objects}
20 0.000 0.000 0.000 0.000 {range}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
10 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/getlimits.py:91(__new__)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
20 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
1 0.000 0.000 0.000 0.000 {method 'sum' of 'numpy.ndarray' objects}
40 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
10 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
30 0.000 0.000 0.000 0.000 {getattr}
24 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
15 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.zeros}
41 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
20 0.000 0.000 0.000 0.000 {issubclass}
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
10 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
5 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
10 0.000 0.000 0.000 0.000 {max}
10 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:871(squeeze)
13 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 {method 'squeeze' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/omp.py
Function: fit at line 484
Total time: 0.027398 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
484 def fit(self, X, y, Gram=None, Xy=None):
485 """Fit the model using X, y as training data.
486
487 Parameters
488 ----------
489 X: array-like, shape = (n_samples, n_features)
490 Training data.
491
492 y: array-like, shape = (n_samples,) or (n_samples, n_targets)
493 Target values.
494
495 Gram: array-like, shape = (n_features, n_features) (optional)
496 Gram matrix of the input data: X.T * X
497
498 Xy: array-like, shape = (n_features,) or (n_features, n_targets)
499 (optional)
500 Input targets multiplied by X: X.T * y
501
502
503 Returns
504 -------
505 self: object
506 returns an instance of self.
507 """
508 1 62 62.0 0.2 X = array2d(X)
509 1 9 9.0 0.0 y = np.asarray(y)
510 1 5 5.0 0.0 n_features = X.shape[1]
511
512 1 3 3.0 0.0 X, y, X_mean, y_mean, X_std = self._center_data(X, y,
513 1 3 3.0 0.0 self.fit_intercept,
514 1 3 3.0 0.0 self.normalize,
515 1 796 796.0 2.9 self.copy_X)
516
517 1 5 5.0 0.0 if y.ndim == 1:
518 y = y[:, np.newaxis]
519
520 1 5 5.0 0.0 if self.n_nonzero_coefs == None and self.tol is None:
521 self.n_nonzero_coefs = int(0.1 * n_features)
522 1 3 3.0 0.0 if (Gram is not None or Xy is not None) and (self.fit_intercept is True
523 or self.normalize is True):
524 warnings.warn('Mean subtraction (fit_intercept) and '
525 'normalization cannot be applied on precomputed Gram '
526 'and Xy matrices. Your precomputed values are ignored '
527 'and recomputed. To avoid this, do the scaling yourself '
528 'and call with fit_intercept and normalize set to False.',
529 RuntimeWarning, stacklevel=2)
530 Gram, Xy = None, None
531
532 1 3 3.0 0.0 if Gram is not None:
533 Gram = array2d(Gram)
534
535 if self.copy_Gram:
536 copy_Gram = False
537 Gram = Gram.copy('F')
538 else:
539 Gram = np.asfortranarray(Gram)
540
541 copy_Gram = self.copy_Gram
542
543 if y.shape[1] > 1: # subsequent targets will be affected
544 copy_Gram = True
545
546 if Xy is None:
547 Xy = np.dot(X.T, y)
548 else:
549 if self.copy_Xy:
550 Xy = Xy.copy()
551 if self.normalize:
552 if len(Xy.shape) == 1:
553 Xy /= X_std
554 else:
555 Xy /= X_std[:, np.newaxis]
556
557 if self.normalize:
558 Gram /= X_std
559 Gram /= X_std[:, np.newaxis]
560
561 norms_sq = np.sum(y ** 2, axis=0) if self.tol is not None else None
562 self.coef_ = orthogonal_mp_gram(Gram, Xy, self.n_nonzero_coefs,
563 self.tol, norms_sq,
564 copy_Gram, True).T
565 else:
566 1 3 3.0 0.0 precompute_gram = self.precompute_gram
567 1 5 5.0 0.0 if precompute_gram == 'auto':
568 precompute_gram = X.shape[0] > X.shape[1]
569 1 4 4.0 0.0 self.coef_ = orthogonal_mp(X, y, self.n_nonzero_coefs, self.tol,
570 1 3 3.0 0.0 precompute_gram=self.precompute_gram,
571 1 26365 26365.0 96.2 copy_X=self.copy_X).T
572
573 1 117 117.0 0.4 self._set_intercept(X_mean, y_mean, X_std)
574 1 4 4.0 0.0 return self
OrthogonalMatchingPursuit-madelon¶
Benchmark setup
from sklearn.linear_model import OrthogonalMatchingPursuit from deps import load_data kwargs = {'n_nonzero_coefs': 10} X, y, X_t, y_t = load_data('madelon') obj = OrthogonalMatchingPursuit(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
138 function calls in 0.130 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.130 0.130 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.130 0.130 <f>:1(<module>)
1 0.000 0.000 0.130 0.130 /tmp/vb_sklearn/sklearn/linear_model/omp.py:484(fit)
1 0.030 0.030 0.096 0.096 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
1 0.000 0.000 0.034 0.034 /tmp/vb_sklearn/sklearn/linear_model/omp.py:206(orthogonal_mp)
2 0.030 0.015 0.030 0.015 {method 'mean' of 'numpy.ndarray' objects}
1 0.000 0.000 0.030 0.030 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
1 0.030 0.030 0.030 0.030 {method 'sum' of 'numpy.ndarray' objects}
1 0.002 0.002 0.023 0.023 /tmp/vb_sklearn/sklearn/linear_model/omp.py:24(_cholesky_omp)
31 0.020 0.001 0.020 0.001 {numpy.core._dotblas.dot}
2 0.016 0.008 0.016 0.008 {method 'copy' of 'numpy.ndarray' objects}
1 0.000 0.000 0.005 0.005 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
10 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:683(argmax)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
10 0.000 0.000 0.000 0.000 {method 'argmax' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/blas.py:30(get_blas_funcs)
9 0.000 0.000 0.000 0.000 {sklearn.utils.arrayfuncs.solve_triangular}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
2 0.000 0.000 0.000 0.000 {range}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/getlimits.py:91(__new__)
6 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
6 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
6 0.000 0.000 0.000 0.000 {isinstance}
2 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
4 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:325(asfortranarray)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.zeros}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
3 0.000 0.000 0.000 0.000 {getattr}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:871(squeeze)
5 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
2 0.000 0.000 0.000 0.000 {issubclass}
4 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
1 0.000 0.000 0.000 0.000 {max}
1 0.000 0.000 0.000 0.000 {method 'squeeze' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/omp.py
Function: fit at line 484
Total time: 0.124885 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
484 def fit(self, X, y, Gram=None, Xy=None):
485 """Fit the model using X, y as training data.
486
487 Parameters
488 ----------
489 X: array-like, shape = (n_samples, n_features)
490 Training data.
491
492 y: array-like, shape = (n_samples,) or (n_samples, n_targets)
493 Target values.
494
495 Gram: array-like, shape = (n_features, n_features) (optional)
496 Gram matrix of the input data: X.T * X
497
498 Xy: array-like, shape = (n_features,) or (n_features, n_targets)
499 (optional)
500 Input targets multiplied by X: X.T * y
501
502
503 Returns
504 -------
505 self: object
506 returns an instance of self.
507 """
508 1 68 68.0 0.1 X = array2d(X)
509 1 9 9.0 0.0 y = np.asarray(y)
510 1 4 4.0 0.0 n_features = X.shape[1]
511
512 1 3 3.0 0.0 X, y, X_mean, y_mean, X_std = self._center_data(X, y,
513 1 3 3.0 0.0 self.fit_intercept,
514 1 3 3.0 0.0 self.normalize,
515 1 89442 89442.0 71.6 self.copy_X)
516
517 1 6 6.0 0.0 if y.ndim == 1:
518 1 14 14.0 0.0 y = y[:, np.newaxis]
519
520 1 6 6.0 0.0 if self.n_nonzero_coefs == None and self.tol is None:
521 self.n_nonzero_coefs = int(0.1 * n_features)
522 1 4 4.0 0.0 if (Gram is not None or Xy is not None) and (self.fit_intercept is True
523 or self.normalize is True):
524 warnings.warn('Mean subtraction (fit_intercept) and '
525 'normalization cannot be applied on precomputed Gram '
526 'and Xy matrices. Your precomputed values are ignored '
527 'and recomputed. To avoid this, do the scaling yourself '
528 'and call with fit_intercept and normalize set to False.',
529 RuntimeWarning, stacklevel=2)
530 Gram, Xy = None, None
531
532 1 3 3.0 0.0 if Gram is not None:
533 Gram = array2d(Gram)
534
535 if self.copy_Gram:
536 copy_Gram = False
537 Gram = Gram.copy('F')
538 else:
539 Gram = np.asfortranarray(Gram)
540
541 copy_Gram = self.copy_Gram
542
543 if y.shape[1] > 1: # subsequent targets will be affected
544 copy_Gram = True
545
546 if Xy is None:
547 Xy = np.dot(X.T, y)
548 else:
549 if self.copy_Xy:
550 Xy = Xy.copy()
551 if self.normalize:
552 if len(Xy.shape) == 1:
553 Xy /= X_std
554 else:
555 Xy /= X_std[:, np.newaxis]
556
557 if self.normalize:
558 Gram /= X_std
559 Gram /= X_std[:, np.newaxis]
560
561 norms_sq = np.sum(y ** 2, axis=0) if self.tol is not None else None
562 self.coef_ = orthogonal_mp_gram(Gram, Xy, self.n_nonzero_coefs,
563 self.tol, norms_sq,
564 copy_Gram, True).T
565 else:
566 1 3 3.0 0.0 precompute_gram = self.precompute_gram
567 1 5 5.0 0.0 if precompute_gram == 'auto':
568 precompute_gram = X.shape[0] > X.shape[1]
569 1 4 4.0 0.0 self.coef_ = orthogonal_mp(X, y, self.n_nonzero_coefs, self.tol,
570 1 3 3.0 0.0 precompute_gram=self.precompute_gram,
571 1 35261 35261.0 28.2 copy_X=self.copy_X).T
572
573 1 41 41.0 0.0 self._set_intercept(X_mean, y_mean, X_std)
574 1 3 3.0 0.0 return self
SGDClassifier-madelon¶
Benchmark setup
from sklearn.linear_model import SGDClassifier from deps import load_data kwargs = {} X, y, X_t, y_t = load_data('madelon') obj = SGDClassifier(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
115 function calls in 0.042 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.042 0.042 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.041 0.041 <f>:1(<module>)
1 0.000 0.000 0.041 0.041 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:460(fit)
1 0.000 0.000 0.038 0.038 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:383(_partial_fit)
1 0.000 0.000 0.035 0.035 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:597(_fit_binary)
1 0.000 0.000 0.035 0.035 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:650(fit_binary)
1 0.035 0.035 0.035 0.035 {sklearn.linear_model.sgd_fast.plain_sgd}
2 0.000 0.000 0.006 0.003 /tmp/vb_sklearn/sklearn/utils/validation.py:23(safe_asarray)
2 0.000 0.000 0.006 0.003 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
2 0.005 0.003 0.005 0.003 {method 'sum' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:90(unique)
10 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1508(any)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:632(_prepare_fit_binary)
10 0.000 0.000 0.000 0.000 {method 'any' of 'numpy.ndarray' objects}
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:119(_set_coef)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:182(_make_dataset)
1 0.000 0.000 0.000 0.000 {method 'sort' of 'numpy.ndarray' objects}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:82(_init_t)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
8 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:6(atleast_1d)
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.concatenate}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:358(_set_class_weight)
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
3 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:106(_validate_sample_weight)
2 0.000 0.000 0.000 0.000 {method 'reshape' of 'numpy.ndarray' objects}
3 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
10 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:128(_allocate_parameter_mem)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:325(asfortranarray)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
5 0.000 0.000 0.000 0.000 {isinstance}
2 0.000 0.000 0.000 0.000 {numpy.core.multiarray.zeros}
1 0.000 0.000 0.000 0.000 {method 'flatten' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {method 'ravel' of 'numpy.ndarray' objects}
2 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:176(_check_fit_data)
6 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 {max}
1 0.000 0.000 0.000 0.000 {method 'dloss' of 'sklearn.linear_model.sgd_fast.Hinge' objects}
2 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py
Function: fit at line 460
Total time: 0.041555 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
460 def fit(self, X, y, coef_init=None, intercept_init=None,
461 class_weight=None, sample_weight=None):
462 """Fit linear model with Stochastic Gradient Descent.
463
464 Parameters
465 ----------
466 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
467 Training data
468
469 y : numpy array of shape [n_samples]
470 Target values
471
472 coef_init : array, shape = [n_classes,n_features]
473 The initial coeffients to warm-start the optimization.
474
475 intercept_init : array, shape = [n_classes]
476 The initial intercept to warm-start the optimization.
477
478 sample_weight : array-like, shape = [n_samples], optional
479 Weights applied to individual samples.
480 If not provided, uniform weights are assumed.
481
482 Returns
483 -------
484 self : returns an instance of self.
485 """
486 1 5 5.0 0.0 if class_weight != None:
487 warnings.warn("Using 'class_weight' as a parameter to the 'fit'"
488 "method is deprecated. Set it on initialization instead.",
489 DeprecationWarning)
490 self.class_weight = class_weight
491
492 1 2901 2901.0 7.0 X = safe_asarray(X, dtype=np.float64, order="C")
493 # labels can be encoded as float, int, or string literals
494 1 15 15.0 0.0 y = np.asarray(y)
495
496 1 4 4.0 0.0 n_samples, n_features = X.shape
497 1 8 8.0 0.0 _check_fit_data(X, y)
498
499 # np.unique sorts in asc order; largest class id is positive class
500 1 193 193.0 0.5 classes = np.unique(y)
501
502 1 3 3.0 0.0 if self.warm_start and self.coef_ is not None:
503 if coef_init is None:
504 coef_init = self.coef_
505 if intercept_init is None:
506 intercept_init = self.intercept_
507 else:
508 1 3 3.0 0.0 self.coef_ = None
509 1 2 2.0 0.0 self.intercept_ = None
510
511 # Need to re-initialize in case of multiple call to fit.
512 1 53 53.0 0.1 self._init_t()
513
514 1 3 3.0 0.0 self._partial_fit(X, y, self.n_iter, classes,
515 1 38273 38273.0 92.1 sample_weight, coef_init, intercept_init)
516
517 # fitting is over, we can now transform coef_ to fortran order
518 # for faster predictions
519 1 89 89.0 0.2 self._set_coef(self.coef_)
520
521 1 3 3.0 0.0 return self
File: /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py
Function: predict at line 542
Total time: 0 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
542 def predict(self, X):
543 """Predict using the linear model
544
545 Parameters
546 ----------
547 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
548
549 Returns
550 -------
551 array, shape = [n_samples]
552 Array containing the predicted class labels.
553 """
554 scores = self.decision_function(X)
555 if self.classes_.shape[0] == 2:
556 indices = np.array(scores > 0, dtype=np.int)
557 else:
558 indices = scores.argmax(axis=1)
559 return self.classes_[np.ravel(indices)]
Benchmark statement
obj.predict(X_t)
Execution time
Memory usage
Additional output
cProfile
49 function calls in 0.002 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.002 0.002 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.002 0.002 <f>:1(<module>)
1 0.000 0.000 0.002 0.002 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:542(predict)
1 0.000 0.000 0.002 0.002 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:523(decision_function)
1 0.000 0.000 0.001 0.001 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
1 0.000 0.000 0.001 0.001 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
1 0.001 0.001 0.001 0.001 {method 'sum' of 'numpy.ndarray' objects}
1 0.000 0.000 0.001 0.001 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
1 0.001 0.001 0.001 0.001 {numpy.core._dotblas.dot}
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1044(ravel)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
5 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
8 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
2 0.000 0.000 0.000 0.000 {method 'ravel' of 'numpy.ndarray' objects}
4 0.000 0.000 0.000 0.000 {isinstance}
3 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py
Function: fit at line 460
Total time: 0.041555 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
460 def fit(self, X, y, coef_init=None, intercept_init=None,
461 class_weight=None, sample_weight=None):
462 """Fit linear model with Stochastic Gradient Descent.
463
464 Parameters
465 ----------
466 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
467 Training data
468
469 y : numpy array of shape [n_samples]
470 Target values
471
472 coef_init : array, shape = [n_classes,n_features]
473 The initial coeffients to warm-start the optimization.
474
475 intercept_init : array, shape = [n_classes]
476 The initial intercept to warm-start the optimization.
477
478 sample_weight : array-like, shape = [n_samples], optional
479 Weights applied to individual samples.
480 If not provided, uniform weights are assumed.
481
482 Returns
483 -------
484 self : returns an instance of self.
485 """
486 1 5 5.0 0.0 if class_weight != None:
487 warnings.warn("Using 'class_weight' as a parameter to the 'fit'"
488 "method is deprecated. Set it on initialization instead.",
489 DeprecationWarning)
490 self.class_weight = class_weight
491
492 1 2901 2901.0 7.0 X = safe_asarray(X, dtype=np.float64, order="C")
493 # labels can be encoded as float, int, or string literals
494 1 15 15.0 0.0 y = np.asarray(y)
495
496 1 4 4.0 0.0 n_samples, n_features = X.shape
497 1 8 8.0 0.0 _check_fit_data(X, y)
498
499 # np.unique sorts in asc order; largest class id is positive class
500 1 193 193.0 0.5 classes = np.unique(y)
501
502 1 3 3.0 0.0 if self.warm_start and self.coef_ is not None:
503 if coef_init is None:
504 coef_init = self.coef_
505 if intercept_init is None:
506 intercept_init = self.intercept_
507 else:
508 1 3 3.0 0.0 self.coef_ = None
509 1 2 2.0 0.0 self.intercept_ = None
510
511 # Need to re-initialize in case of multiple call to fit.
512 1 53 53.0 0.1 self._init_t()
513
514 1 3 3.0 0.0 self._partial_fit(X, y, self.n_iter, classes,
515 1 38273 38273.0 92.1 sample_weight, coef_init, intercept_init)
516
517 # fitting is over, we can now transform coef_ to fortran order
518 # for faster predictions
519 1 89 89.0 0.2 self._set_coef(self.coef_)
520
521 1 3 3.0 0.0 return self
File: /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py
Function: predict at line 542
Total time: 0.001652 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
542 def predict(self, X):
543 """Predict using the linear model
544
545 Parameters
546 ----------
547 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
548
549 Returns
550 -------
551 array, shape = [n_samples]
552 Array containing the predicted class labels.
553 """
554 1 1583 1583.0 95.8 scores = self.decision_function(X)
555 1 4 4.0 0.2 if self.classes_.shape[0] == 2:
556 1 34 34.0 2.1 indices = np.array(scores > 0, dtype=np.int)
557 else:
558 indices = scores.argmax(axis=1)
559 1 31 31.0 1.9 return self.classes_[np.ravel(indices)]
SGDClassifier-newsgroups¶
Benchmark setup
from sklearn.linear_model import SGDClassifier from deps import load_data kwargs = {} X, y, X_t, y_t = load_data('newsgroups') obj = SGDClassifier(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
1585 function calls (1578 primitive calls) in 1.970 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 1.970 1.970 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 1.970 1.970 <f>:1(<module>)
1 0.000 0.000 1.970 1.970 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:460(fit)
1 0.000 0.000 1.883 1.883 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:383(_partial_fit)
1 0.000 0.000 1.852 1.852 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:611(_fit_multiclass)
1 0.000 0.000 1.788 1.788 /tmp/vb_sklearn/sklearn/externals/joblib/parallel.py:430(__call__)
20 0.000 0.000 1.786 0.089 /tmp/vb_sklearn/sklearn/externals/joblib/parallel.py:292(dispatch)
20 0.000 0.000 1.786 0.089 /tmp/vb_sklearn/sklearn/externals/joblib/parallel.py:121(__init__)
20 0.000 0.000 1.786 0.089 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:650(fit_binary)
20 1.620 0.081 1.776 0.089 {sklearn.linear_model.sgd_fast.plain_sgd}
200 0.059 0.000 0.156 0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1508(any)
200 0.097 0.000 0.097 0.000 {method 'any' of 'numpy.ndarray' objects}
23 0.066 0.003 0.066 0.003 {numpy.core.multiarray.array}
1 0.000 0.000 0.066 0.066 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:119(_set_coef)
1 0.000 0.000 0.066 0.066 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:325(asfortranarray)
1 0.000 0.000 0.064 0.064 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:193(_tocsr)
2/1 0.000 0.000 0.064 0.064 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:20(__init__)
1 0.000 0.000 0.054 0.054 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:178(asformat)
1 0.000 0.000 0.054 0.054 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/coo.py:281(tocsr)
1 0.000 0.000 0.039 0.039 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sparsetools/coo.py:75(coo_tocsr)
1 0.039 0.039 0.039 0.039 {_coo.coo_tocsr}
2 0.000 0.000 0.039 0.019 /tmp/vb_sklearn/sklearn/utils/validation.py:23(safe_asarray)
2 0.000 0.000 0.039 0.019 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
2 0.000 0.000 0.039 0.019 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:486(sum)
2 0.000 0.000 0.037 0.019 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:229(__mul__)
2 0.000 0.000 0.037 0.018 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/coo.py:370(_mul_vector)
2 0.000 0.000 0.036 0.018 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sparsetools/coo.py:174(coo_matvec)
2 0.036 0.018 0.036 0.018 {_coo.coo_matvec}
1 0.000 0.000 0.014 0.014 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:567(sum_duplicates)
4 0.012 0.003 0.012 0.003 {numpy.core.multiarray.zeros}
1 0.000 0.000 0.012 0.012 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:128(_allocate_parameter_mem)
1 0.000 0.000 0.009 0.009 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sparsetools/csr.py:567(csr_sum_duplicates)
1 0.009 0.009 0.009 0.009 {_csr.csr_sum_duplicates}
1 0.009 0.009 0.009 0.009 {method 'astype' of 'numpy.ndarray' objects}
20 0.007 0.000 0.007 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:632(_prepare_fit_binary)
1 0.000 0.000 0.005 0.005 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:613(sort_indices)
1 0.000 0.000 0.005 0.005 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:581(__get_sorted)
1 0.000 0.000 0.005 0.005 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sparsetools/csr.py:85(csr_has_sorted_indices)
1 0.005 0.005 0.005 0.005 {_csr.csr_has_sorted_indices}
20 0.001 0.000 0.002 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:182(_make_dataset)
21 0.000 0.000 0.002 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:622(<genexpr>)
20 0.000 0.000 0.001 0.000 /tmp/vb_sklearn/sklearn/externals/joblib/parallel.py:101(delayed)
24 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
24 0.001 0.000 0.001 0.000 {method 'fill' of 'numpy.ndarray' objects}
1 0.000 0.000 0.001 0.001 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/arraysetops.py:90(unique)
1 0.001 0.001 0.001 0.001 {method 'sort' of 'numpy.ndarray' objects}
28 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
20 0.001 0.000 0.001 0.000 {cPickle.dumps}
31 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:101(check_format)
20 0.000 0.000 0.000 0.000 /sp/lib/python/cpython-2.7.2/lib/python2.7/functools.py:17(update_wrapper)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/matrixlib/defmatrix.py:403(sum)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:18(upcast)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:622(prune)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/externals/joblib/parallel.py:390(retrieve)
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/matrixlib/defmatrix.py:55(asmatrix)
27 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/matrixlib/defmatrix.py:233(__new__)
62 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
62 0.000 0.000 0.000 0.000 {isinstance}
20 0.000 0.000 0.000 0.000 /sp/lib/python/cpython-2.7.2/lib/python2.7/functools.py:39(wraps)
16/10 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/matrixlib/defmatrix.py:279(__array_finalize__)
4 0.000 0.000 0.000 0.000 {method 'view' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:77(isscalarlike)
41 0.000 0.000 0.000 0.000 {hasattr}
6 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/coo.py:194(getnnz)
101 0.000 0.000 0.000 0.000 {getattr}
11 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:82(_init_t)
60 0.000 0.000 0.000 0.000 {setattr}
86 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.concatenate}
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/matrixlib/defmatrix.py:365(_align)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:124(isdense)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1574(isscalar)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/matrixlib/defmatrix.py:301(__getitem__)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1044(ravel)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/externals/joblib/logger.py:39(short_format_time)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:358(_set_class_weight)
20 0.000 0.000 0.000 0.000 {method 'update' of 'dict' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:106(_validate_sample_weight)
30 0.000 0.000 0.000 0.000 {numpy.core.multiarray.can_cast}
20 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/externals/joblib/parallel.py:49(_verbosity_filter)
1 0.000 0.000 0.000 0.000 {method 'flatten' of 'numpy.ndarray' objects}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:50(to_native)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:59(set_shape)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/data.py:17(__init__)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:96(isshape)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:90(_set_self)
20 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:81(get_shape)
24 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2116(rank)
20 0.000 0.000 0.000 0.000 {method 'pop' of 'list' objects}
41 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
2 0.000 0.000 0.000 0.000 {method 'reshape' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/externals/joblib/logger.py:23(_squeeze_time)
12 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:85(getnnz)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:51(__init__)
8 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/csr.py:180(_swap)
7 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/data.py:20(_get_dtype)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/csr.py:395(isspmatrix_csr)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/externals/joblib/parallel.py:282(__init__)
20 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/externals/joblib/parallel.py:108(delayed_function)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:370(__getattr__)
20 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/externals/joblib/parallel.py:126(get)
2 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:176(_check_fit_data)
2 0.000 0.000 0.000 0.000 {method 'newbyteorder' of 'numpy.dtype' objects}
2 0.000 0.000 0.000 0.000 {method 'ravel' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:54(getdtype)
1 0.000 0.000 0.000 0.000 {max}
1 0.000 0.000 0.000 0.000 {method 'dloss' of 'sklearn.linear_model.sgd_fast.Hinge' objects}
1 0.000 0.000 0.000 0.000 {method 'startswith' of 'str' objects}
2 0.000 0.000 0.000 0.000 {time.time}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/externals/joblib/parallel.py:337(_print)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py
Function: fit at line 460
Total time: 2.10021 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
460 def fit(self, X, y, coef_init=None, intercept_init=None,
461 class_weight=None, sample_weight=None):
462 """Fit linear model with Stochastic Gradient Descent.
463
464 Parameters
465 ----------
466 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
467 Training data
468
469 y : numpy array of shape [n_samples]
470 Target values
471
472 coef_init : array, shape = [n_classes,n_features]
473 The initial coeffients to warm-start the optimization.
474
475 intercept_init : array, shape = [n_classes]
476 The initial intercept to warm-start the optimization.
477
478 sample_weight : array-like, shape = [n_samples], optional
479 Weights applied to individual samples.
480 If not provided, uniform weights are assumed.
481
482 Returns
483 -------
484 self : returns an instance of self.
485 """
486 1 4 4.0 0.0 if class_weight != None:
487 warnings.warn("Using 'class_weight' as a parameter to the 'fit'"
488 "method is deprecated. Set it on initialization instead.",
489 DeprecationWarning)
490 self.class_weight = class_weight
491
492 1 22587 22587.0 1.1 X = safe_asarray(X, dtype=np.float64, order="C")
493 # labels can be encoded as float, int, or string literals
494 1 14 14.0 0.0 y = np.asarray(y)
495
496 1 9 9.0 0.0 n_samples, n_features = X.shape
497 1 9 9.0 0.0 _check_fit_data(X, y)
498
499 # np.unique sorts in asc order; largest class id is positive class
500 1 1101 1101.0 0.1 classes = np.unique(y)
501
502 1 3 3.0 0.0 if self.warm_start and self.coef_ is not None:
503 if coef_init is None:
504 coef_init = self.coef_
505 if intercept_init is None:
506 intercept_init = self.intercept_
507 else:
508 1 3 3.0 0.0 self.coef_ = None
509 1 5 5.0 0.0 self.intercept_ = None
510
511 # Need to re-initialize in case of multiple call to fit.
512 1 59 59.0 0.0 self._init_t()
513
514 1 3 3.0 0.0 self._partial_fit(X, y, self.n_iter, classes,
515 1 2036138 2036138.0 96.9 sample_weight, coef_init, intercept_init)
516
517 # fitting is over, we can now transform coef_ to fortran order
518 # for faster predictions
519 1 40277 40277.0 1.9 self._set_coef(self.coef_)
520
521 1 3 3.0 0.0 return self
File: /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py
Function: predict at line 542
Total time: 0 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
542 def predict(self, X):
543 """Predict using the linear model
544
545 Parameters
546 ----------
547 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
548
549 Returns
550 -------
551 array, shape = [n_samples]
552 Array containing the predicted class labels.
553 """
554 scores = self.decision_function(X)
555 if self.classes_.shape[0] == 2:
556 indices = np.array(scores > 0, dtype=np.int)
557 else:
558 indices = scores.argmax(axis=1)
559 return self.classes_[np.ravel(indices)]
Benchmark statement
obj.predict(X_t)
Execution time
Memory usage
Additional output
cProfile
187 function calls in 0.146 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.146 0.146 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.145 0.145 <f>:1(<module>)
1 0.000 0.000 0.145 0.145 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:542(predict)
1 0.001 0.001 0.144 0.144 /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py:523(decision_function)
1 0.000 0.000 0.111 0.111 /tmp/vb_sklearn/sklearn/utils/extmath.py:70(safe_sparse_dot)
1 0.000 0.000 0.111 0.111 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:229(__mul__)
1 0.000 0.000 0.111 0.111 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:263(_mul_multivector)
1 0.000 0.000 0.111 0.111 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sparsetools/csr.py:320(csr_matvecs)
1 0.111 0.111 0.111 0.111 {_csr.csr_matvecs}
1 0.000 0.000 0.031 0.031 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
1 0.000 0.000 0.028 0.028 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/coo.py:281(tocsr)
1 0.000 0.000 0.019 0.019 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sparsetools/coo.py:75(coo_tocsr)
1 0.019 0.019 0.019 0.019 {_coo.coo_tocsr}
1 0.000 0.000 0.009 0.009 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:567(sum_duplicates)
1 0.000 0.000 0.006 0.006 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sparsetools/csr.py:567(csr_sum_duplicates)
1 0.006 0.006 0.006 0.006 {_csr.csr_sum_duplicates}
1 0.000 0.000 0.003 0.003 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
1 0.000 0.000 0.003 0.003 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:613(sort_indices)
1 0.000 0.000 0.003 0.003 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:581(__get_sorted)
1 0.000 0.000 0.003 0.003 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:310(sum)
1 0.003 0.003 0.003 0.003 {method 'sum' of 'numpy.ndarray' objects}
1 0.000 0.000 0.003 0.003 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sparsetools/csr.py:85(csr_has_sorted_indices)
1 0.003 0.003 0.003 0.003 {_csr.csr_has_sorted_indices}
1 0.002 0.002 0.002 0.002 {method 'argmax' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:20(__init__)
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.zeros}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:101(check_format)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:622(prune)
2 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:18(upcast)
12 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/coo.py:194(getnnz)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:77(isscalarlike)
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:96(isshape)
3 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
20 0.000 0.000 0.000 0.000 {numpy.core.multiarray.can_cast}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1044(ravel)
10 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
8 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 {hasattr}
9 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:81(get_shape)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:50(to_native)
8 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/compressed.py:85(getnnz)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/data.py:17(__init__)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:124(isdense)
26 0.000 0.000 0.000 0.000 {len}
15 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2116(rank)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:59(set_shape)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:51(__init__)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1574(isscalar)
3 0.000 0.000 0.000 0.000 {method 'ravel' of 'numpy.ndarray' objects}
5 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/csr.py:180(_swap)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:370(__getattr__)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:54(getdtype)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/data.py:20(_get_dtype)
1 0.000 0.000 0.000 0.000 {method 'newbyteorder' of 'numpy.dtype' objects}
1 0.000 0.000 0.000 0.000 {getattr}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py
Function: fit at line 460
Total time: 2.10021 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
460 def fit(self, X, y, coef_init=None, intercept_init=None,
461 class_weight=None, sample_weight=None):
462 """Fit linear model with Stochastic Gradient Descent.
463
464 Parameters
465 ----------
466 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
467 Training data
468
469 y : numpy array of shape [n_samples]
470 Target values
471
472 coef_init : array, shape = [n_classes,n_features]
473 The initial coeffients to warm-start the optimization.
474
475 intercept_init : array, shape = [n_classes]
476 The initial intercept to warm-start the optimization.
477
478 sample_weight : array-like, shape = [n_samples], optional
479 Weights applied to individual samples.
480 If not provided, uniform weights are assumed.
481
482 Returns
483 -------
484 self : returns an instance of self.
485 """
486 1 4 4.0 0.0 if class_weight != None:
487 warnings.warn("Using 'class_weight' as a parameter to the 'fit'"
488 "method is deprecated. Set it on initialization instead.",
489 DeprecationWarning)
490 self.class_weight = class_weight
491
492 1 22587 22587.0 1.1 X = safe_asarray(X, dtype=np.float64, order="C")
493 # labels can be encoded as float, int, or string literals
494 1 14 14.0 0.0 y = np.asarray(y)
495
496 1 9 9.0 0.0 n_samples, n_features = X.shape
497 1 9 9.0 0.0 _check_fit_data(X, y)
498
499 # np.unique sorts in asc order; largest class id is positive class
500 1 1101 1101.0 0.1 classes = np.unique(y)
501
502 1 3 3.0 0.0 if self.warm_start and self.coef_ is not None:
503 if coef_init is None:
504 coef_init = self.coef_
505 if intercept_init is None:
506 intercept_init = self.intercept_
507 else:
508 1 3 3.0 0.0 self.coef_ = None
509 1 5 5.0 0.0 self.intercept_ = None
510
511 # Need to re-initialize in case of multiple call to fit.
512 1 59 59.0 0.0 self._init_t()
513
514 1 3 3.0 0.0 self._partial_fit(X, y, self.n_iter, classes,
515 1 2036138 2036138.0 96.9 sample_weight, coef_init, intercept_init)
516
517 # fitting is over, we can now transform coef_ to fortran order
518 # for faster predictions
519 1 40277 40277.0 1.9 self._set_coef(self.coef_)
520
521 1 3 3.0 0.0 return self
File: /tmp/vb_sklearn/sklearn/linear_model/stochastic_gradient.py
Function: predict at line 542
Total time: 0.170825 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
542 def predict(self, X):
543 """Predict using the linear model
544
545 Parameters
546 ----------
547 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
548
549 Returns
550 -------
551 array, shape = [n_samples]
552 Array containing the predicted class labels.
553 """
554 1 169070 169070.0 99.0 scores = self.decision_function(X)
555 1 4 4.0 0.0 if self.classes_.shape[0] == 2:
556 indices = np.array(scores > 0, dtype=np.int)
557 else:
558 1 1589 1589.0 0.9 indices = scores.argmax(axis=1)
559 1 162 162.0 0.1 return self.classes_[np.ravel(indices)]
LogisticRegression-arcene¶
Benchmark setup
from sklearn.linear_model import LogisticRegression from deps import load_data kwargs = {'C': 100000.0} X, y, X_t, y_t = load_data('arcene') obj = LogisticRegression(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
46 function calls in 0.386 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.386 0.386 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.386 0.386 <f>:1(<module>)
1 0.000 0.000 0.386 0.386 /tmp/vb_sklearn/sklearn/svm/base.py:596(fit)
1 0.384 0.384 0.384 0.384 {sklearn.svm.liblinear.train_wrap}
1 0.000 0.000 0.002 0.002 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
1 0.000 0.000 0.002 0.002 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
1 0.002 0.002 0.002 0.002 {method 'sum' of 'numpy.ndarray' objects}
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
5 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:16(_get_class_weight)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:563(_get_solver_type)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
6 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
3 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 {sklearn.svm.liblinear.set_verbosity_wrap}
1 0.000 0.000 0.000 0.000 {method 'ravel' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:766(_get_bias)
2 0.000 0.000 0.000 0.000 {method 'upper' of 'str' objects}
3 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/svm/base.py
Function: fit at line 596
Total time: 0.659028 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
596 def fit(self, X, y, class_weight=None):
597 """Fit the model according to the given training data.
598
599 Parameters
600 ----------
601 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
602 Training vector, where n_samples in the number of samples and
603 n_features is the number of features.
604
605 y : array-like, shape = [n_samples]
606 Target vector relative to X
607
608 class_weight : {dict, 'auto'}, optional
609 Weights associated with classes. If not given, all classes
610 are supposed to have weight one.
611
612 Returns
613 -------
614 self : object
615 Returns self.
616 """
617
618 1 4 4.0 0.0 if class_weight != None:
619 warnings.warn("'class_weight' is now an initialization parameter."
620 "Using it in the 'fit' method is deprecated.",
621 DeprecationWarning)
622 self.class_weight = class_weight
623
624 1 1667 1667.0 0.3 X = atleast2d_or_csr(X, dtype=np.float64, order="C")
625 1 22 22.0 0.0 y = np.asarray(y, dtype=np.float64).ravel()
626 1 24 24.0 0.0 self._sparse = sp.isspmatrix(X)
627
628 self.class_weight_, self.class_weight_label_ = \
629 1 44 44.0 0.0 _get_class_weight(self.class_weight, y)
630
631 1 3 3.0 0.0 if X.shape[0] != y.shape[0]:
632 raise ValueError("X and y have incompatible shapes.\n" +
633 "X has %s samples, but y has %s." % \
634 (X.shape[0], y.shape[0]))
635
636 1 4 4.0 0.0 liblinear.set_verbosity_wrap(self.verbose)
637
638 1 1 1.0 0.0 if self._sparse:
639 train = liblinear.csr_train_wrap
640 else:
641 1 2 2.0 0.0 train = liblinear.train_wrap
642
643 1 1 1.0 0.0 if self.verbose:
644 print '[LibLinear]',
645 1 20 20.0 0.0 self.raw_coef_, self.label_ = train(X, y, self._get_solver_type(),
646 1 5 5.0 0.0 self.tol, self._get_bias(), self.C,
647 1 1 1.0 0.0 self.class_weight_label_,
648 1 657225 657225.0 99.7 self.class_weight_)
649
650 1 5 5.0 0.0 return self
File: /tmp/vb_sklearn/sklearn/svm/base.py
Function: predict at line 652
Total time: 0 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
652 def predict(self, X):
653 """Predict target values of X according to the fitted model.
654
655 Parameters
656 ----------
657 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
658
659 Returns
660 -------
661 C : array, shape = [n_samples]
662 """
663 X = self._validate_for_predict(X)
664
665 C = 0.0 # C is not useful here
666
667 predict = liblinear.csr_predict_wrap if self._sparse \
668 else liblinear.predict_wrap
669 return predict(X, self.raw_coef_, self._get_solver_type(), self.tol,
670 C, self.class_weight_label_, self.class_weight_,
671 self.label_, self._get_bias())
Benchmark statement
obj.predict(X_t)
Execution time
Memory usage
Additional output
cProfile
39 function calls in 0.014 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.014 0.014 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.014 0.014 <f>:1(<module>)
1 0.000 0.000 0.014 0.014 /tmp/vb_sklearn/sklearn/svm/base.py:652(predict)
1 0.012 0.012 0.012 0.012 {sklearn.svm.liblinear.predict_wrap}
1 0.000 0.000 0.002 0.002 /tmp/vb_sklearn/sklearn/svm/base.py:708(_validate_for_predict)
1 0.000 0.000 0.002 0.002 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
1 0.000 0.000 0.002 0.002 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
1 0.002 0.002 0.002 0.002 {method 'sum' of 'numpy.ndarray' objects}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:563(_get_solver_type)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
6 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
3 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
2 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:700(_check_n_features)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
2 0.000 0.000 0.000 0.000 {method 'upper' of 'str' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:766(_get_bias)
3 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/svm/base.py
Function: fit at line 596
Total time: 0.659028 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
596 def fit(self, X, y, class_weight=None):
597 """Fit the model according to the given training data.
598
599 Parameters
600 ----------
601 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
602 Training vector, where n_samples in the number of samples and
603 n_features is the number of features.
604
605 y : array-like, shape = [n_samples]
606 Target vector relative to X
607
608 class_weight : {dict, 'auto'}, optional
609 Weights associated with classes. If not given, all classes
610 are supposed to have weight one.
611
612 Returns
613 -------
614 self : object
615 Returns self.
616 """
617
618 1 4 4.0 0.0 if class_weight != None:
619 warnings.warn("'class_weight' is now an initialization parameter."
620 "Using it in the 'fit' method is deprecated.",
621 DeprecationWarning)
622 self.class_weight = class_weight
623
624 1 1667 1667.0 0.3 X = atleast2d_or_csr(X, dtype=np.float64, order="C")
625 1 22 22.0 0.0 y = np.asarray(y, dtype=np.float64).ravel()
626 1 24 24.0 0.0 self._sparse = sp.isspmatrix(X)
627
628 self.class_weight_, self.class_weight_label_ = \
629 1 44 44.0 0.0 _get_class_weight(self.class_weight, y)
630
631 1 3 3.0 0.0 if X.shape[0] != y.shape[0]:
632 raise ValueError("X and y have incompatible shapes.\n" +
633 "X has %s samples, but y has %s." % \
634 (X.shape[0], y.shape[0]))
635
636 1 4 4.0 0.0 liblinear.set_verbosity_wrap(self.verbose)
637
638 1 1 1.0 0.0 if self._sparse:
639 train = liblinear.csr_train_wrap
640 else:
641 1 2 2.0 0.0 train = liblinear.train_wrap
642
643 1 1 1.0 0.0 if self.verbose:
644 print '[LibLinear]',
645 1 20 20.0 0.0 self.raw_coef_, self.label_ = train(X, y, self._get_solver_type(),
646 1 5 5.0 0.0 self.tol, self._get_bias(), self.C,
647 1 1 1.0 0.0 self.class_weight_label_,
648 1 657225 657225.0 99.7 self.class_weight_)
649
650 1 5 5.0 0.0 return self
File: /tmp/vb_sklearn/sklearn/svm/base.py
Function: predict at line 652
Total time: 0.02336 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
652 def predict(self, X):
653 """Predict target values of X according to the fitted model.
654
655 Parameters
656 ----------
657 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
658
659 Returns
660 -------
661 C : array, shape = [n_samples]
662 """
663 1 2894 2894.0 12.4 X = self._validate_for_predict(X)
664
665 1 3 3.0 0.0 C = 0.0 # C is not useful here
666
667 1 2 2.0 0.0 predict = liblinear.csr_predict_wrap if self._sparse \
668 1 3 3.0 0.0 else liblinear.predict_wrap
669 1 30 30.0 0.1 return predict(X, self.raw_coef_, self._get_solver_type(), self.tol,
670 1 5 5.0 0.0 C, self.class_weight_label_, self.class_weight_,
671 1 20423 20423.0 87.4 self.label_, self._get_bias())
LogisticRegression-madelon¶
Benchmark setup
from sklearn.linear_model import LogisticRegression from deps import load_data kwargs = {'C': 100000.0} X, y, X_t, y_t = load_data('madelon') obj = LogisticRegression(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
46 function calls in 10.078 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 10.078 10.078 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 10.078 10.078 <f>:1(<module>)
1 0.000 0.000 10.078 10.078 /tmp/vb_sklearn/sklearn/svm/base.py:596(fit)
1 10.074 10.074 10.074 10.074 {sklearn.svm.liblinear.train_wrap}
1 0.000 0.000 0.003 0.003 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
1 0.000 0.000 0.003 0.003 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
1 0.003 0.003 0.003 0.003 {method 'sum' of 'numpy.ndarray' objects}
4 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
5 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:16(_get_class_weight)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:563(_get_solver_type)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
6 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
3 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 {sklearn.svm.liblinear.set_verbosity_wrap}
1 0.000 0.000 0.000 0.000 {method 'ravel' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:766(_get_bias)
3 0.000 0.000 0.000 0.000 {len}
2 0.000 0.000 0.000 0.000 {method 'upper' of 'str' objects}
1 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/svm/base.py
Function: fit at line 596
Total time: 10.2476 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
596 def fit(self, X, y, class_weight=None):
597 """Fit the model according to the given training data.
598
599 Parameters
600 ----------
601 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
602 Training vector, where n_samples in the number of samples and
603 n_features is the number of features.
604
605 y : array-like, shape = [n_samples]
606 Target vector relative to X
607
608 class_weight : {dict, 'auto'}, optional
609 Weights associated with classes. If not given, all classes
610 are supposed to have weight one.
611
612 Returns
613 -------
614 self : object
615 Returns self.
616 """
617
618 1 4 4.0 0.0 if class_weight != None:
619 warnings.warn("'class_weight' is now an initialization parameter."
620 "Using it in the 'fit' method is deprecated.",
621 DeprecationWarning)
622 self.class_weight = class_weight
623
624 1 2573 2573.0 0.0 X = atleast2d_or_csr(X, dtype=np.float64, order="C")
625 1 32 32.0 0.0 y = np.asarray(y, dtype=np.float64).ravel()
626 1 32 32.0 0.0 self._sparse = sp.isspmatrix(X)
627
628 self.class_weight_, self.class_weight_label_ = \
629 1 66 66.0 0.0 _get_class_weight(self.class_weight, y)
630
631 1 5 5.0 0.0 if X.shape[0] != y.shape[0]:
632 raise ValueError("X and y have incompatible shapes.\n" +
633 "X has %s samples, but y has %s." % \
634 (X.shape[0], y.shape[0]))
635
636 1 5 5.0 0.0 liblinear.set_verbosity_wrap(self.verbose)
637
638 1 2 2.0 0.0 if self._sparse:
639 train = liblinear.csr_train_wrap
640 else:
641 1 3 3.0 0.0 train = liblinear.train_wrap
642
643 1 3 3.0 0.0 if self.verbose:
644 print '[LibLinear]',
645 1 31 31.0 0.0 self.raw_coef_, self.label_ = train(X, y, self._get_solver_type(),
646 1 7 7.0 0.0 self.tol, self._get_bias(), self.C,
647 1 2 2.0 0.0 self.class_weight_label_,
648 1 10244878 10244878.0 100.0 self.class_weight_)
649
650 1 4 4.0 0.0 return self
File: /tmp/vb_sklearn/sklearn/svm/base.py
Function: predict at line 652
Total time: 0 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
652 def predict(self, X):
653 """Predict target values of X according to the fitted model.
654
655 Parameters
656 ----------
657 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
658
659 Returns
660 -------
661 C : array, shape = [n_samples]
662 """
663 X = self._validate_for_predict(X)
664
665 C = 0.0 # C is not useful here
666
667 predict = liblinear.csr_predict_wrap if self._sparse \
668 else liblinear.predict_wrap
669 return predict(X, self.raw_coef_, self._get_solver_type(), self.tol,
670 C, self.class_weight_label_, self.class_weight_,
671 self.label_, self._get_bias())
Benchmark statement
obj.predict(X_t)
Execution time
Memory usage
Additional output
cProfile
39 function calls in 0.005 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.005 0.005 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.005 0.005 <f>:1(<module>)
1 0.000 0.000 0.005 0.005 /tmp/vb_sklearn/sklearn/svm/base.py:652(predict)
1 0.004 0.004 0.004 0.004 {sklearn.svm.liblinear.predict_wrap}
1 0.000 0.000 0.001 0.001 /tmp/vb_sklearn/sklearn/svm/base.py:708(_validate_for_predict)
1 0.000 0.000 0.001 0.001 /tmp/vb_sklearn/sklearn/utils/validation.py:70(atleast2d_or_csr)
1 0.000 0.000 0.001 0.001 /tmp/vb_sklearn/sklearn/utils/validation.py:10(assert_all_finite)
1 0.001 0.001 0.001 0.001 {method 'sum' of 'numpy.ndarray' objects}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:62(array2d)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/shape_base.py:58(atleast_2d)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:563(_get_solver_type)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:237(asanyarray)
6 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
2 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
3 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:700(_check_n_features)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/svm/base.py:766(_get_bias)
3 0.000 0.000 0.000 0.000 {len}
2 0.000 0.000 0.000 0.000 {method 'upper' of 'str' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/svm/base.py
Function: fit at line 596
Total time: 10.2476 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
596 def fit(self, X, y, class_weight=None):
597 """Fit the model according to the given training data.
598
599 Parameters
600 ----------
601 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
602 Training vector, where n_samples in the number of samples and
603 n_features is the number of features.
604
605 y : array-like, shape = [n_samples]
606 Target vector relative to X
607
608 class_weight : {dict, 'auto'}, optional
609 Weights associated with classes. If not given, all classes
610 are supposed to have weight one.
611
612 Returns
613 -------
614 self : object
615 Returns self.
616 """
617
618 1 4 4.0 0.0 if class_weight != None:
619 warnings.warn("'class_weight' is now an initialization parameter."
620 "Using it in the 'fit' method is deprecated.",
621 DeprecationWarning)
622 self.class_weight = class_weight
623
624 1 2573 2573.0 0.0 X = atleast2d_or_csr(X, dtype=np.float64, order="C")
625 1 32 32.0 0.0 y = np.asarray(y, dtype=np.float64).ravel()
626 1 32 32.0 0.0 self._sparse = sp.isspmatrix(X)
627
628 self.class_weight_, self.class_weight_label_ = \
629 1 66 66.0 0.0 _get_class_weight(self.class_weight, y)
630
631 1 5 5.0 0.0 if X.shape[0] != y.shape[0]:
632 raise ValueError("X and y have incompatible shapes.\n" +
633 "X has %s samples, but y has %s." % \
634 (X.shape[0], y.shape[0]))
635
636 1 5 5.0 0.0 liblinear.set_verbosity_wrap(self.verbose)
637
638 1 2 2.0 0.0 if self._sparse:
639 train = liblinear.csr_train_wrap
640 else:
641 1 3 3.0 0.0 train = liblinear.train_wrap
642
643 1 3 3.0 0.0 if self.verbose:
644 print '[LibLinear]',
645 1 31 31.0 0.0 self.raw_coef_, self.label_ = train(X, y, self._get_solver_type(),
646 1 7 7.0 0.0 self.tol, self._get_bias(), self.C,
647 1 2 2.0 0.0 self.class_weight_label_,
648 1 10244878 10244878.0 100.0 self.class_weight_)
649
650 1 4 4.0 0.0 return self
File: /tmp/vb_sklearn/sklearn/svm/base.py
Function: predict at line 652
Total time: 0.00556 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
652 def predict(self, X):
653 """Predict target values of X according to the fitted model.
654
655 Parameters
656 ----------
657 X : {array-like, sparse matrix}, shape = [n_samples, n_features]
658
659 Returns
660 -------
661 C : array, shape = [n_samples]
662 """
663 1 972 972.0 17.5 X = self._validate_for_predict(X)
664
665 1 3 3.0 0.1 C = 0.0 # C is not useful here
666
667 1 2 2.0 0.0 predict = liblinear.csr_predict_wrap if self._sparse \
668 1 2 2.0 0.0 else liblinear.predict_wrap
669 1 26 26.0 0.5 return predict(X, self.raw_coef_, self._get_solver_type(), self.tol,
670 1 4 4.0 0.1 C, self.class_weight_label_, self.class_weight_,
671 1 4551 4551.0 81.9 self.label_, self._get_bias())
ARDRegression-minimadelon-oney¶
Benchmark setup
from sklearn.linear_model import ARDRegression from deps import load_data kwargs = {} X, y, X_t, y_t = load_data('minimadelon-oney') obj = ARDRegression(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
1093 function calls in 0.080 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.080 0.080 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 0.080 0.080 <f>:1(<module>)
1 0.028 0.028 0.080 0.080 /tmp/vb_sklearn/sklearn/linear_model/bayes.py:339(fit)
14 0.000 0.000 0.028 0.002 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/basic.py:457(pinv)
14 0.024 0.002 0.027 0.002 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/basic.py:365(lstsq)
85 0.021 0.000 0.021 0.000 {numpy.core._dotblas.dot}
42 0.002 0.000 0.003 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
14 0.000 0.000 0.002 0.000 {map}
14 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
84 0.001 0.000 0.001 0.000 {method 'any' of 'numpy.ndarray' objects}
72 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
85 0.001 0.000 0.001 0.000 {numpy.core.multiarray.array}
27 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
14 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
42 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:107(reshape)
41 0.000 0.000 0.000 0.000 {method 'sum' of 'numpy.ndarray' objects}
14 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/twodim_base.py:220(diag)
14 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/twodim_base.py:169(eye)
42 0.000 0.000 0.000 0.000 {method 'reshape' of 'numpy.ndarray' objects}
14 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1830(identity)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:94(check_arrays)
2 0.000 0.000 0.000 0.000 {method 'mean' of 'numpy.ndarray' objects}
29 0.000 0.000 0.000 0.000 {numpy.core.multiarray.zeros}
28 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
28 0.000 0.000 0.000 0.000 {getattr}
14 0.000 0.000 0.000 0.000 {method 'astype' of 'numpy.generic' objects}
13 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:781(copy)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
32 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 {method 'copy' of 'numpy.ndarray' objects}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2470(var)
1 0.000 0.000 0.000 0.000 {method 'var' of 'numpy.ndarray' objects}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
34 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
56 0.000 0.000 0.000 0.000 {issubclass}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
15 0.000 0.000 0.000 0.000 {range}
14 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
14 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
44 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
3 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:87(_num_samples)
71 0.000 0.000 0.000 0.000 {len}
28 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
3 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
3 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
6 0.000 0.000 0.000 0.000 {hasattr}
4 0.000 0.000 0.000 0.000 {method 'pop' of 'dict' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/bayes.py
Function: fit at line 339
Total time: 0.080527 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
339 def fit(self, X, y):
340 """Fit the ARDRegression model according to the given training data
341 and parameters.
342
343 Iterative procedure to maximize the evidence
344
345 Parameters
346 ----------
347 X : array-like, shape = [n_samples, n_features]
348 Training vector, where n_samples in the number of samples and
349 n_features is the number of features.
350 y : array, shape = [n_samples]
351 Target values (integers)
352
353 Returns
354 -------
355 self : returns an instance of self.
356 """
357 1 5 5.0 0.0 X, y = check_arrays(X, y, sparse_format='dense',
358 1 130 130.0 0.2 dtype=np.float)
359
360 1 5 5.0 0.0 n_samples, n_features = X.shape
361 1 13 13.0 0.0 coef_ = np.zeros(n_features)
362
363 1 5 5.0 0.0 X, y, X_mean, y_mean, X_std = self._center_data(X, y,
364 1 335 335.0 0.4 self.fit_intercept, self.normalize, self.copy_X)
365
366 ### Launch the convergence loop
367 1 20 20.0 0.0 keep_lambda = np.ones(n_features, dtype=bool)
368
369 1 5 5.0 0.0 lambda_1 = self.lambda_1
370 1 4 4.0 0.0 lambda_2 = self.lambda_2
371 1 4 4.0 0.0 alpha_1 = self.alpha_1
372 1 4 4.0 0.0 alpha_2 = self.alpha_2
373 1 4 4.0 0.0 verbose = self.verbose
374
375 ### Initialization of the values of the parameters
376 1 87 87.0 0.1 alpha_ = 1. / np.var(y)
377 1 19 19.0 0.0 lambda_ = np.ones(n_features)
378
379 1 6 6.0 0.0 self.scores_ = list()
380 1 4 4.0 0.0 coef_old_ = None
381
382 ### Iterative procedure of ARDRegression
383 14 75 5.4 0.1 for iter_ in range(self.n_iter):
384 ### Compute mu and sigma (using Woodbury matrix identity)
385 14 701 50.1 0.9 sigma_ = linalg.pinv(np.eye(n_samples) / alpha_ +
386 14 3622 258.7 4.5 np.dot(X[:, keep_lambda] *
387 14 1214 86.7 1.5 np.reshape(1. / lambda_[keep_lambda], [1, -1]),
388 14 35472 2533.7 44.0 X[:, keep_lambda].T))
389 14 3597 256.9 4.5 sigma_ = np.dot(sigma_, X[:, keep_lambda]
390 14 4221 301.5 5.2 * np.reshape(1. / lambda_[keep_lambda], [1, -1]))
391 14 699 49.9 0.9 sigma_ = - np.dot(np.reshape(1. / lambda_[keep_lambda], [-1, 1])
392 14 18849 1346.4 23.4 * X[:, keep_lambda].T, sigma_)
393 14 214 15.3 0.3 sigma_.flat[::(sigma_.shape[1] + 1)] += \
394 14 718 51.3 0.9 1. / lambda_[keep_lambda]
395 14 71 5.1 0.1 coef_[keep_lambda] = alpha_ * np.dot(
396 14 5091 363.6 6.3 sigma_, np.dot(X[:, keep_lambda].T, y))
397
398 ### Update alpha and lambda
399 14 1141 81.5 1.4 rmse_ = np.sum((y - np.dot(X, coef_)) ** 2)
400 14 1037 74.1 1.3 gamma_ = 1. - lambda_[keep_lambda] * np.diag(sigma_)
401 14 198 14.1 0.2 lambda_[keep_lambda] = (gamma_ + 2. * lambda_1) \
402 14 756 54.0 0.9 / ((coef_[keep_lambda]) ** 2 + 2. * lambda_2)
403 14 352 25.1 0.4 alpha_ = (n_samples - gamma_.sum() + 2. * alpha_1) \
404 14 117 8.4 0.1 / (rmse_ + 2. * alpha_2)
405
406 ### Prune the weights with a precision over a threshold
407 14 239 17.1 0.3 keep_lambda = lambda_ < self.threshold_lambda
408 14 515 36.8 0.6 coef_[keep_lambda == False] = 0
409
410 ### Compute the objective function
411 14 64 4.6 0.1 if self.compute_score:
412 s = (lambda_1 * np.log(lambda_) - lambda_2 * lambda_).sum()
413 s += alpha_1 * log(alpha_) - alpha_2 * alpha_
414 s += 0.5 * (fast_logdet(sigma_) + n_samples * log(alpha_)
415 + np.sum(np.log(lambda_)))
416 s -= 0.5 * (alpha_ * rmse_ + (lambda_ * coef_ ** 2).sum())
417 self.scores_.append(s)
418
419 ### Check for convergence
420 14 631 45.1 0.8 if iter_ > 0 and np.sum(np.abs(coef_old_ - coef_)) < self.tol:
421 1 4 4.0 0.0 if verbose:
422 print "Converged after %s iterations" % iter_
423 1 9 9.0 0.0 break
424 13 214 16.5 0.3 coef_old_ = np.copy(coef_)
425
426 1 7 7.0 0.0 self.coef_ = coef_
427 1 4 4.0 0.0 self.alpha_ = alpha_
428 1 4 4.0 0.0 self.sigma_ = sigma_
429
430 1 37 37.0 0.0 self._set_intercept(X_mean, y_mean, X_std)
431 1 4 4.0 0.0 return self
ARDRegression-blobs¶
Benchmark setup
from sklearn.linear_model import ARDRegression from deps import load_data kwargs = {} X, y, X_t, y_t = load_data('blobs') obj = ARDRegression(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
945 function calls in 3.359 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 3.359 3.359 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 3.359 3.359 <f>:1(<module>)
1 0.068 0.068 3.359 3.359 /tmp/vb_sklearn/sklearn/linear_model/bayes.py:339(fit)
12 0.000 0.000 3.208 0.267 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/basic.py:457(pinv)
12 3.081 0.257 3.161 0.263 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/basic.py:365(lstsq)
36 0.112 0.003 0.124 0.003 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
73 0.079 0.001 0.079 0.001 {numpy.core._dotblas.dot}
12 0.000 0.000 0.079 0.007 {map}
72 0.012 0.000 0.012 0.000 {method 'any' of 'numpy.ndarray' objects}
25 0.002 0.000 0.002 0.000 {numpy.core.multiarray.zeros}
12 0.000 0.000 0.002 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/twodim_base.py:169(eye)
12 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1830(identity)
62 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
12 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
73 0.001 0.000 0.001 0.000 {numpy.core.multiarray.array}
12 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
23 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
36 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:107(reshape)
35 0.000 0.000 0.000 0.000 {method 'sum' of 'numpy.ndarray' objects}
12 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/twodim_base.py:220(diag)
36 0.000 0.000 0.000 0.000 {method 'reshape' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:94(check_arrays)
12 0.000 0.000 0.000 0.000 {method 'astype' of 'numpy.generic' objects}
2 0.000 0.000 0.000 0.000 {method 'mean' of 'numpy.ndarray' objects}
24 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
28 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 {method 'copy' of 'numpy.ndarray' objects}
11 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:781(copy)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
24 0.000 0.000 0.000 0.000 {getattr}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2470(var)
1 0.000 0.000 0.000 0.000 {method 'var' of 'numpy.ndarray' objects}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
30 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
13 0.000 0.000 0.000 0.000 {range}
48 0.000 0.000 0.000 0.000 {issubclass}
12 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
12 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
38 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
3 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:87(_num_samples)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
61 0.000 0.000 0.000 0.000 {len}
3 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
24 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
3 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
6 0.000 0.000 0.000 0.000 {hasattr}
4 0.000 0.000 0.000 0.000 {method 'pop' of 'dict' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/bayes.py
Function: fit at line 339
Total time: 3.45568 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
339 def fit(self, X, y):
340 """Fit the ARDRegression model according to the given training data
341 and parameters.
342
343 Iterative procedure to maximize the evidence
344
345 Parameters
346 ----------
347 X : array-like, shape = [n_samples, n_features]
348 Training vector, where n_samples in the number of samples and
349 n_features is the number of features.
350 y : array, shape = [n_samples]
351 Target values (integers)
352
353 Returns
354 -------
355 self : returns an instance of self.
356 """
357 1 6 6.0 0.0 X, y = check_arrays(X, y, sparse_format='dense',
358 1 171 171.0 0.0 dtype=np.float)
359
360 1 5 5.0 0.0 n_samples, n_features = X.shape
361 1 11 11.0 0.0 coef_ = np.zeros(n_features)
362
363 1 5 5.0 0.0 X, y, X_mean, y_mean, X_std = self._center_data(X, y,
364 1 317 317.0 0.0 self.fit_intercept, self.normalize, self.copy_X)
365
366 ### Launch the convergence loop
367 1 19 19.0 0.0 keep_lambda = np.ones(n_features, dtype=bool)
368
369 1 5 5.0 0.0 lambda_1 = self.lambda_1
370 1 4 4.0 0.0 lambda_2 = self.lambda_2
371 1 4 4.0 0.0 alpha_1 = self.alpha_1
372 1 4 4.0 0.0 alpha_2 = self.alpha_2
373 1 4 4.0 0.0 verbose = self.verbose
374
375 ### Initialization of the values of the parameters
376 1 71 71.0 0.0 alpha_ = 1. / np.var(y)
377 1 18 18.0 0.0 lambda_ = np.ones(n_features)
378
379 1 27 27.0 0.0 self.scores_ = list()
380 1 4 4.0 0.0 coef_old_ = None
381
382 ### Iterative procedure of ARDRegression
383 12 70 5.8 0.0 for iter_ in range(self.n_iter):
384 ### Compute mu and sigma (using Woodbury matrix identity)
385 12 8226 685.5 0.2 sigma_ = linalg.pinv(np.eye(n_samples) / alpha_ +
386 12 9357 779.8 0.3 np.dot(X[:, keep_lambda] *
387 12 1517 126.4 0.0 np.reshape(1. / lambda_[keep_lambda], [1, -1]),
388 12 3339843 278320.2 96.6 X[:, keep_lambda].T))
389 12 9598 799.8 0.3 sigma_ = np.dot(sigma_, X[:, keep_lambda]
390 12 54851 4570.9 1.6 * np.reshape(1. / lambda_[keep_lambda], [1, -1]))
391 12 666 55.5 0.0 sigma_ = - np.dot(np.reshape(1. / lambda_[keep_lambda], [-1, 1])
392 12 15587 1298.9 0.5 * X[:, keep_lambda].T, sigma_)
393 12 166 13.8 0.0 sigma_.flat[::(sigma_.shape[1] + 1)] += \
394 12 444 37.0 0.0 1. / lambda_[keep_lambda]
395 12 59 4.9 0.0 coef_[keep_lambda] = alpha_ * np.dot(
396 12 10369 864.1 0.3 sigma_, np.dot(X[:, keep_lambda].T, y))
397
398 ### Update alpha and lambda
399 12 1105 92.1 0.0 rmse_ = np.sum((y - np.dot(X, coef_)) ** 2)
400 12 823 68.6 0.0 gamma_ = 1. - lambda_[keep_lambda] * np.diag(sigma_)
401 12 173 14.4 0.0 lambda_[keep_lambda] = (gamma_ + 2. * lambda_1) \
402 12 496 41.3 0.0 / ((coef_[keep_lambda]) ** 2 + 2. * lambda_2)
403 12 315 26.2 0.0 alpha_ = (n_samples - gamma_.sum() + 2. * alpha_1) \
404 12 101 8.4 0.0 / (rmse_ + 2. * alpha_2)
405
406 ### Prune the weights with a precision over a threshold
407 12 210 17.5 0.0 keep_lambda = lambda_ < self.threshold_lambda
408 12 241 20.1 0.0 coef_[keep_lambda == False] = 0
409
410 ### Compute the objective function
411 12 57 4.8 0.0 if self.compute_score:
412 s = (lambda_1 * np.log(lambda_) - lambda_2 * lambda_).sum()
413 s += alpha_1 * log(alpha_) - alpha_2 * alpha_
414 s += 0.5 * (fast_logdet(sigma_) + n_samples * log(alpha_)
415 + np.sum(np.log(lambda_)))
416 s -= 0.5 * (alpha_ * rmse_ + (lambda_ * coef_ ** 2).sum())
417 self.scores_.append(s)
418
419 ### Check for convergence
420 12 485 40.4 0.0 if iter_ > 0 and np.sum(np.abs(coef_old_ - coef_)) < self.tol:
421 1 4 4.0 0.0 if verbose:
422 print "Converged after %s iterations" % iter_
423 1 9 9.0 0.0 break
424 11 179 16.3 0.0 coef_old_ = np.copy(coef_)
425
426 1 7 7.0 0.0 self.coef_ = coef_
427 1 5 5.0 0.0 self.alpha_ = alpha_
428 1 4 4.0 0.0 self.sigma_ = sigma_
429
430 1 35 35.0 0.0 self._set_intercept(X_mean, y_mean, X_std)
431 1 4 4.0 0.0 return self
BayesianRidge-arcene¶
Benchmark setup
from sklearn.linear_model import BayesianRidge from deps import load_data kwargs = {} X, y, X_t, y_t = load_data('arcene') obj = BayesianRidge(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
110 function calls in 1.089 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 1.089 1.089 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 1.089 1.089 <f>:1(<module>)
1 0.001 0.001 1.089 1.089 /tmp/vb_sklearn/sklearn/linear_model/bayes.py:126(fit)
1 0.849 0.849 0.881 0.881 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
10 0.193 0.019 0.193 0.019 {numpy.core._dotblas.dot}
1 0.028 0.028 0.032 0.032 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
1 0.003 0.003 0.013 0.013 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
1 0.000 0.000 0.006 0.006 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
1 0.006 0.006 0.006 0.006 {method 'copy' of 'numpy.ndarray' objects}
2 0.004 0.002 0.004 0.002 {method 'mean' of 'numpy.ndarray' objects}
2 0.004 0.002 0.004 0.002 {method 'any' of 'numpy.ndarray' objects}
7 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:94(check_arrays)
7 0.000 0.000 0.000 0.000 {method 'sum' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2470(var)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
1 0.000 0.000 0.000 0.000 {method 'var' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
4 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
2 0.000 0.000 0.000 0.000 {range}
12 0.000 0.000 0.000 0.000 {isinstance}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:781(copy)
8 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
3 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:87(_num_samples)
1 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
6 0.000 0.000 0.000 0.000 {hasattr}
2 0.000 0.000 0.000 0.000 {getattr}
2 0.000 0.000 0.000 0.000 {issubclass}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
4 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
3 0.000 0.000 0.000 0.000 {len}
4 0.000 0.000 0.000 0.000 {method 'pop' of 'dict' objects}
1 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/bayes.py
Function: fit at line 126
Total time: 1.19802 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
126 def fit(self, X, y):
127 """Fit the model
128
129 Parameters
130 ----------
131 X : numpy array of shape [n_samples,n_features]
132 Training data
133 y : numpy array of shape [n_samples]
134 Target values
135
136 Returns
137 -------
138 self : returns an instance of self.
139 """
140 1 5 5.0 0.0 X, y = check_arrays(X, y, sparse_format='dense',
141 1 129 129.0 0.0 dtype=np.float)
142 1 4 4.0 0.0 X, y, X_mean, y_mean, X_std = self._center_data(X, y,
143 1 63361 63361.0 5.3 self.fit_intercept, self.normalize, self.copy_X)
144 1 6 6.0 0.0 n_samples, n_features = X.shape
145
146 ### Initialization of the values of the parameters
147 1 69 69.0 0.0 alpha_ = 1. / np.var(y)
148 1 4 4.0 0.0 lambda_ = 1.
149
150 1 4 4.0 0.0 verbose = self.verbose
151 1 5 5.0 0.0 lambda_1 = self.lambda_1
152 1 4 4.0 0.0 lambda_2 = self.lambda_2
153 1 4 4.0 0.0 alpha_1 = self.alpha_1
154 1 4 4.0 0.0 alpha_2 = self.alpha_2
155
156 1 6 6.0 0.0 self.scores_ = list()
157 1 3 3.0 0.0 coef_old_ = None
158
159 1 2745 2745.0 0.2 XT_y = np.dot(X.T, y)
160 1 952267 952267.0 79.5 U, S, Vh = linalg.svd(X, full_matrices=False)
161 1 40 40.0 0.0 eigen_vals_ = S ** 2
162
163 ### Convergence loop of the bayesian ridge regression
164 2 28 14.0 0.0 for iter_ in range(self.n_iter):
165
166 ### Compute mu and sigma
167 # sigma_ = lambda_ / alpha_ * np.eye(n_features) + np.dot(X.T, X)
168 # coef_ = sigma_^-1 * XT * y
169 2 8 4.0 0.0 if n_samples > n_features:
170 coef_ = np.dot(Vh.T,
171 Vh / (eigen_vals_ + lambda_ / alpha_)[:, None])
172 coef_ = np.dot(coef_, XT_y)
173 if self.compute_score:
174 logdet_sigma_ = - np.sum(
175 np.log(lambda_ + alpha_ * eigen_vals_))
176 else:
177 2 16 8.0 0.0 coef_ = np.dot(X.T, np.dot(
178 2 169758 84879.0 14.2 U / (eigen_vals_ + lambda_ / alpha_)[None, :], U.T))
179 2 4011 2005.5 0.3 coef_ = np.dot(coef_, y)
180 2 16 8.0 0.0 if self.compute_score:
181 logdet_sigma_ = lambda_ * np.ones(n_features)
182 logdet_sigma_[:n_samples] += alpha_ * eigen_vals_
183 logdet_sigma_ = - np.sum(np.log(logdet_sigma_))
184
185 ### Update alpha and lambda
186 2 3985 1992.5 0.3 rmse_ = np.sum((y - np.dot(X, coef_)) ** 2)
187 2 52 26.0 0.0 gamma_ = (np.sum((alpha_ * eigen_vals_)
188 2 100 50.0 0.0 / (lambda_ + alpha_ * eigen_vals_)))
189 2 28 14.0 0.0 lambda_ = ((gamma_ + 2 * lambda_1)
190 2 191 95.5 0.0 / (np.sum(coef_ ** 2) + 2 * lambda_2))
191 2 26 13.0 0.0 alpha_ = ((n_samples - gamma_ + 2 * alpha_1)
192 2 15 7.5 0.0 / (rmse_ + 2 * alpha_2))
193
194 ### Compute the objective function
195 2 9 4.5 0.0 if self.compute_score:
196 s = lambda_1 * log(lambda_) - lambda_2 * lambda_
197 s += alpha_1 * log(alpha_) - alpha_2 * alpha_
198 s += 0.5 * (n_features * log(lambda_)
199 + n_samples * log(alpha_)
200 - alpha_ * rmse_
201 - (lambda_ * np.sum(coef_ ** 2))
202 - logdet_sigma_
203 - n_samples * log(2 * np.pi))
204 self.scores_.append(s)
205
206 ### Check for convergence
207 2 345 172.5 0.0 if iter_ != 0 and np.sum(np.abs(coef_old_ - coef_)) < self.tol:
208 1 5 5.0 0.0 if verbose:
209 print "Convergence after ", str(iter_), " iterations"
210 1 10 10.0 0.0 break
211 1 34 34.0 0.0 coef_old_ = np.copy(coef_)
212
213 1 5 5.0 0.0 self.alpha_ = alpha_
214 1 4 4.0 0.0 self.lambda_ = lambda_
215 1 3 3.0 0.0 self.coef_ = coef_
216
217 1 712 712.0 0.1 self._set_intercept(X_mean, y_mean, X_std)
218 1 4 4.0 0.0 return self
BayesianRidge-madelon¶
Benchmark setup
from sklearn.linear_model import BayesianRidge from deps import load_data kwargs = {} X, y, X_t, y_t = load_data('madelon') obj = BayesianRidge(**kwargs)
Benchmark statement
obj.fit(X, y)
Execution time
Memory usage
Additional output
cProfile
244 function calls in 3.317 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 3.317 3.317 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/vbench/benchmark.py:286(f)
1 0.000 0.000 3.317 3.317 <f>:1(<module>)
1 0.064 0.064 3.317 3.317 /tmp/vb_sklearn/sklearn/linear_model/bayes.py:126(fit)
1 2.131 2.131 2.163 2.163 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py:14(svd)
32 1.049 0.033 1.049 0.033 {numpy.core._dotblas.dot}
1 0.004 0.004 0.040 0.040 /tmp/vb_sklearn/sklearn/linear_model/base.py:70(center_data)
1 0.028 0.028 0.032 0.032 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:526(asarray_chkfinite)
2 0.030 0.015 0.030 0.015 {method 'mean' of 'numpy.ndarray' objects}
1 0.000 0.000 0.006 0.006 /tmp/vb_sklearn/sklearn/utils/validation.py:33(as_float_array)
1 0.005 0.005 0.005 0.005 {method 'copy' of 'numpy.ndarray' objects}
2 0.004 0.002 0.004 0.002 {method 'any' of 'numpy.ndarray' objects}
39 0.000 0.000 0.001 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:1379(sum)
39 0.000 0.000 0.000 0.000 {method 'sum' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:94(check_arrays)
44 0.000 0.000 0.000 0.000 {isinstance}
9 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/lib/function_base.py:781(copy)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:60(get_lapack_funcs)
12 0.000 0.000 0.000 0.000 {numpy.core.multiarray.array}
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/base.py:553(isspmatrix)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.py:2470(var)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/sparse/sputils.py:116(_isinstance)
1 0.000 0.000 0.000 0.000 {method 'var' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:45(find_best_lapack_type)
3 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:167(asarray)
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:1791(ones)
2 0.000 0.000 0.000 0.000 {range}
1 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/linear_model/base.py:138(_set_intercept)
8 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects}
3 0.000 0.000 0.000 0.000 /tmp/vb_sklearn/sklearn/utils/validation.py:87(_num_samples)
1 0.000 0.000 0.000 0.000 {numpy.core.multiarray.empty}
1 0.000 0.000 0.000 0.000 {method 'fill' of 'numpy.ndarray' objects}
6 0.000 0.000 0.000 0.000 {hasattr}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/lapack.py:23(cast_to_lapack_prefix)
2 0.000 0.000 0.000 0.000 {getattr}
2 0.000 0.000 0.000 0.000 {issubclass}
3 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/numpy/core/numeric.py:449(isfortran)
4 0.000 0.000 0.000 0.000 {method 'pop' of 'dict' objects}
4 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 /home/slave/virtualenvs/cpython-2.7.2/lib/python2.7/site-packages/scipy/linalg/misc.py:22(_datacopied)
1 0.000 0.000 0.000 0.000 {method 'sort' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
LineProfiler
Timer unit: 1e-06 s
File: /tmp/vb_sklearn/sklearn/linear_model/bayes.py
Function: fit at line 126
Total time: 3.45243 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
126 def fit(self, X, y):
127 """Fit the model
128
129 Parameters
130 ----------
131 X : numpy array of shape [n_samples,n_features]
132 Training data
133 y : numpy array of shape [n_samples]
134 Target values
135
136 Returns
137 -------
138 self : returns an instance of self.
139 """
140 1 5 5.0 0.0 X, y = check_arrays(X, y, sparse_format='dense',
141 1 152 152.0 0.0 dtype=np.float)
142 1 4 4.0 0.0 X, y, X_mean, y_mean, X_std = self._center_data(X, y,
143 1 36274 36274.0 1.1 self.fit_intercept, self.normalize, self.copy_X)
144 1 5 5.0 0.0 n_samples, n_features = X.shape
145
146 ### Initialization of the values of the parameters
147 1 97 97.0 0.0 alpha_ = 1. / np.var(y)
148 1 4 4.0 0.0 lambda_ = 1.
149
150 1 5 5.0 0.0 verbose = self.verbose
151 1 6 6.0 0.0 lambda_1 = self.lambda_1
152 1 5 5.0 0.0 lambda_2 = self.lambda_2
153 1 5 5.0 0.0 alpha_1 = self.alpha_1
154 1 4 4.0 0.0 alpha_2 = self.alpha_2
155
156 1 7 7.0 0.0 self.scores_ = list()
157 1 4 4.0 0.0 coef_old_ = None
158
159 1 2422 2422.0 0.1 XT_y = np.dot(X.T, y)
160 1 2260268 2260268.0 65.5 U, S, Vh = linalg.svd(X, full_matrices=False)
161 1 30 30.0 0.0 eigen_vals_ = S ** 2
162
163 ### Convergence loop of the bayesian ridge regression
164 10 53 5.3 0.0 for iter_ in range(self.n_iter):
165
166 ### Compute mu and sigma
167 # sigma_ = lambda_ / alpha_ * np.eye(n_features) + np.dot(X.T, X)
168 # coef_ = sigma_^-1 * XT * y
169 10 34 3.4 0.0 if n_samples > n_features:
170 10 53 5.3 0.0 coef_ = np.dot(Vh.T,
171 10 1127775 112777.5 32.7 Vh / (eigen_vals_ + lambda_ / alpha_)[:, None])
172 10 4303 430.3 0.1 coef_ = np.dot(coef_, XT_y)
173 10 53 5.3 0.0 if self.compute_score:
174 logdet_sigma_ = - np.sum(
175 np.log(lambda_ + alpha_ * eigen_vals_))
176 else:
177 coef_ = np.dot(X.T, np.dot(
178 U / (eigen_vals_ + lambda_ / alpha_)[None, :], U.T))
179 coef_ = np.dot(coef_, y)
180 if self.compute_score:
181 logdet_sigma_ = lambda_ * np.ones(n_features)
182 logdet_sigma_[:n_samples] += alpha_ * eigen_vals_
183 logdet_sigma_ = - np.sum(np.log(logdet_sigma_))
184
185 ### Update alpha and lambda
186 10 18707 1870.7 0.5 rmse_ = np.sum((y - np.dot(X, coef_)) ** 2)
187 10 255 25.5 0.0 gamma_ = (np.sum((alpha_ * eigen_vals_)
188 10 546 54.6 0.0 / (lambda_ + alpha_ * eigen_vals_)))
189 10 123 12.3 0.0 lambda_ = ((gamma_ + 2 * lambda_1)
190 10 328 32.8 0.0 / (np.sum(coef_ ** 2) + 2 * lambda_2))
191 10 115 11.5 0.0 alpha_ = ((n_samples - gamma_ + 2 * alpha_1)
192 10 73 7.3 0.0 / (rmse_ + 2 * alpha_2))
193
194 ### Compute the objective function
195 10 44 4.4 0.0 if self.compute_score:
196 s = lambda_1 * log(lambda_) - lambda_2 * lambda_
197 s += alpha_1 * log(alpha_) - alpha_2 * alpha_
198 s += 0.5 * (n_features * log(lambda_)
199 + n_samples * log(alpha_)
200 - alpha_ * rmse_
201 - (lambda_ * np.sum(coef_ ** 2))
202 - logdet_sigma_
203 - n_samples * log(2 * np.pi))
204 self.scores_.append(s)
205
206 ### Check for convergence
207 10 436 43.6 0.0 if iter_ != 0 and np.sum(np.abs(coef_old_ - coef_)) < self.tol:
208 1 4 4.0 0.0 if verbose:
209 print "Convergence after ", str(iter_), " iterations"
210 1 9 9.0 0.0 break
211 9 168 18.7 0.0 coef_old_ = np.copy(coef_)
212
213 1 5 5.0 0.0 self.alpha_ = alpha_
214 1 3 3.0 0.0 self.lambda_ = lambda_
215 1 4 4.0 0.0 self.coef_ = coef_
216
217 1 40 40.0 0.0 self._set_intercept(X_mean, y_mean, X_std)
218 1 3 3.0 0.0 return self