2012/5/11 Mathieu Blondel <[email protected]>:
>
>
> On Fri, May 11, 2012 at 10:52 PM, Olivier Grisel <[email protected]>
> wrote:
>>
>> Unfortunately I don't think you can assign coef_ on liblinear wrapper
>> models due to internal memory layout constraints.
>>
>
> Sure you can :)
>
> https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/svm/base.py#L805

Indeed but no, actually not with the += operator that is overriden by
the numpy array that is just a readonly view:

In [2]: from sklearn.svm import LinearSVC

In [3]: LinearSVC().fit([[0, 0], [1, 1]], [1, 0])
Out[3]:
LinearSVC(C=1.0, class_weight=None, dual=True, fit_intercept=True,
     intercept_scaling=1, loss='l2', multi_class='ovr', penalty='l2',
     tol=0.0001, verbose=0)

In [4]: clf = LinearSVC().fit([[0, 0], [1, 1]], [1, 0])

In [5]: clf2 = LinearSVC().fit([[0, 1], [1, 2]], [1, 0])

In [6]: clf.coef_
Out[6]: array([[-0.58822085, -0.58822085]])

In [7]: clf.coef_ += clf2.coef_
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/home/ogrisel/coding/nuxeo/nuxeo-core/<ipython-input-7-7cc27f84b0a5>
in <module>()
----> 1 clf.coef_ += clf2.coef_

ValueError: return array is not writeable

In [8]: clf.coef_ = clf.coef_ + clf2.coef_

In [9]: clf.coef_
Out[9]: array([[-1.3468086 , -0.79509105]])


-- 
Olivier
http://twitter.com/ogrisel - http://github.com/ogrisel

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to