Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scikit-learn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ian Johnson
scikit-learn
Commits
fa76ac38
Commit
fa76ac38
authored
11 years ago
by
Joel Nothman
Browse files
Options
Downloads
Patches
Plain Diff
FIX OvR with constant label for non-predict methods
parent
aaefdbd3
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
sklearn/multiclass.py
+3
-0
3 additions, 0 deletions
sklearn/multiclass.py
sklearn/tests/test_multiclass.py
+6
-2
6 additions, 2 deletions
sklearn/tests/test_multiclass.py
with
9 additions
and
2 deletions
sklearn/multiclass.py
+
3
−
0
View file @
fa76ac38
...
...
@@ -128,6 +128,9 @@ class _ConstantPredictor(BaseEstimator):
def
decision_function
(
self
,
X
):
return
np
.
repeat
(
self
.
y_
,
X
.
shape
[
0
])
def
predict_proba
(
self
,
X
):
return
np
.
repeat
([[
0
,
1
]],
X
.
shape
[
0
],
axis
=
0
)
class
OneVsRestClassifier
(
BaseEstimator
,
ClassifierMixin
,
MetaEstimatorMixin
):
"""
One-vs-the-rest (OvR) multiclass/multilabel strategy
...
...
This diff is collapsed.
Click to expand it.
sklearn/tests/test_multiclass.py
+
6
−
2
View file @
fa76ac38
...
...
@@ -20,7 +20,7 @@ from sklearn.metrics import recall_score
from
sklearn.svm
import
LinearSVC
from
sklearn.naive_bayes
import
MultinomialNB
from
sklearn.linear_model
import
(
LinearRegression
,
Lasso
,
ElasticNet
,
Ridge
,
Perceptron
)
Perceptron
,
LogisticRegression
)
from
sklearn.tree
import
DecisionTreeClassifier
from
sklearn.grid_search
import
GridSearchCV
from
sklearn.pipeline
import
Pipeline
...
...
@@ -63,10 +63,14 @@ def test_ovr_always_present():
X
[:
5
,
:]
=
0
y
=
[[
int
(
i
>=
5
),
2
,
3
]
for
i
in
range
(
10
)]
with
warnings
.
catch_warnings
(
record
=
True
):
ovr
=
OneVsRestClassifier
(
DecisionTreeClassifier
())
ovr
=
OneVsRestClassifier
(
LogisticRegression
())
ovr
.
fit
(
X
,
y
)
y_pred
=
ovr
.
predict
(
X
)
assert_array_equal
(
np
.
array
(
y_pred
),
np
.
array
(
y
))
y_pred
=
ovr
.
decision_function
(
X
)
assert_equal
(
np
.
unique
(
y_pred
[:,
-
2
:]),
1
)
y_pred
=
ovr
.
predict_proba
(
X
)
assert_array_equal
(
y_pred
[:,
-
2
:],
np
.
ones
((
X
.
shape
[
0
],
2
)))
def
test_ovr_multilabel
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment