Hi List,

I'm currently working on some performance documentation [1] and I wanted to
micro-benchmark the dense vs sparse coefficients case.

I created a self-contained script and wanted to bench it using
line_profiler, but it seems that after the call to `sparsify()` my
SGDRegressor can't predict anymore (crashes with a dimensions mismatch
error).

Here is a gist to reproduce that: [2].

The weird thing is that the coeffs_ attribute changes shape after the call
to sparsify:
(30,) -> (1, 30)
where 30 equals to n_features in my case.

Any idea or explanation welcome !

[1] https://github.com/scikit-learn/scikit-learn/pull/2488
[2] https://gist.github.com/oddskool/7300982

PS: The stack trace:
"""
Traceback (most recent call last):
  File "/usr/local/bin/kernprof.py", line 233, in <module>
    sys.exit(main(sys.argv))
  File "/usr/local/bin/kernprof.py", line 221, in main
    execfile(script_file, ns, ns)
  File "sparsity_benchmark.py", line 52, in <module>
    score(y_test, clf.predict(X_test), 'sparse model')
  File
"/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/stochastic_gradient.py",
line 903, in predict
    return self.decision_function(X)
  File
"/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/stochastic_gradient.py",
line 888, in decision_function
    scores = safe_sparse_dot(X, self.coef_) + self.intercept_
  File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/extmath.py",
line 190, in safe_sparse_dot
    ret = a * b
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/base.py", line 311,
in __rmul__
    return (self.transpose() * tr).transpose()
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/base.py", line 278,
in __mul__
    raise ValueError('dimension mismatch')
ValueError: dimension mismatch
"""
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to