8000 MRG: Explicitly mark the array returned by the linear svm readonly property coef_ as immutable by ogrisel · Pull Request #541 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Conversation

ogrisel
Copy link
Member
@ogrisel ogrisel commented Jan 7, 2012

This pull-request #539 should be taken into account to understand the context about the debate of readonly properties in the scikit-learn API.

This pull request is also related to issue #470 LogisticRegression and LinearSVC should have read-write coef_ and intercept_ attributes (it does not fix it but makes it a less dangerous behavior).

The following is an example session were the unsuspecting user might overlook a bug:

>>> from sklearn.svm import SVC
>>> from sklearn.datasets import load_iris
>>> iris = load_iris()
>>> clf = SVC(kernel='linear').fit(iris.data, iris.target)
>>> clf.coef_

array([[-1.0443518 ,  0.01195155, -1.91966087, -0.81040704],
       [ 1.5863679 ,  1.66207276, -1.65274791, -1.95241805]])
>>> clf.coef_[0, 3] = 0
>>> clf.coef_

array([[-1.0443518 ,  0.01195155, -1.91966087, -0.81040704],
       [ 1.5863679 ,  1.66207276, -1.65274791, -1.95241805]])

@pprett
Copy link
Member
pprett commented Jan 7, 2012

looks good to me - this will spare us some effort on the mailing list :-) - I'm +1 for merge

@amueller
Copy link
Member
amueller commented Jan 7, 2012

Didn't test but looks good. +1 for merge

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ret *= -1 avoid a copy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@GaelVaroquaux
Copy link
Member

Appart from the inline comment, I am +1 for a merge

ogrisel added a commit that referenced this pull request Jan 7, 2012
MRG: Explicitly mark the array returned by the linear svm readonly property coef_ as immutable
@ogrisel ogrisel merged commit 26632b6 into scikit-learn:master Jan 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0