8000 DOC developer guidelines for unit tests and classes_ · scikit-learn/scikit-learn@68d378d · GitHub
[go: up one dir, main page]

Skip to content

Commit 68d378d

Browse files
committed
DOC developer guidelines for unit tests and classes_
1 parent 73d3d3f commit 68d378d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

doc/developers/index.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ In addition, we add the following guidelines:
350350

351351
* Use relative imports for references inside scikit-learn.
352352

353+
* Unit tests are an exception to the previous rule;
354+
they should use absolute imports, exactly as client code would.
355+
A corollary is that, if ``sklearn.foo`` exports a class or function
356+
that is implemented in ``sklearn.foo.bar.baz``,
357+
the test should import it from ``sklearn.foo``.
358+
353359
* **Please don't use `import *` in any case**. It is considered harmful
354360
by the `official Python recommendations
355361
<http://docs.python.org/howto/doanddont.html#from-module-import>`_.
@@ -621,5 +627,31 @@ advised to maintain notes on the `GitHub wiki
621627
Specific models
622628
---------------
623629

630+
Classifiers should accept ``y`` (target) arguments to ``fit``
631+
that are sequences (lists, arrays) of either strings or integers.
632+
They should not assume that the class labels
633+
are a contiguous range of integers;
634+
instead, they should store a list of classes
635+
in a ``classes_`` attribute or property.
636+
The order of class labels in this attribute
637+
should match the order in which ``predict_proba``, ``predict_log_proba``
638+
and ``decision_function`` return their values.
639+
The easiest way to achieve this is to put::
640+
641+
self.classes_ = np.unique(y)
642+
643+
in ``fit``.
644+
645+
A classifier's ``predict`` method should return
646+
arrays containing class labels from ``classes_``.
647+
In a classifier that implements ``decision_function``,
648+
this can be achieved with::
649+
650+
def predict(self, X):
651+
D = self.decision_function(X)
652+
return self.classes_[np.argmax(D, axis=1)]
653+
624654
In linear models, coefficients are stored in an array called ``coef_``,
625655
and the independent term is stored in ``intercept_``.
656+
``sklearn.linear_model.base`` contains a few base classes and mixins
657+
that implement common linear model patterns.

0 commit comments

Comments
 (0)
0