@@ -350,6 +350,12 @@ In addition, we add the following guidelines:
350
350
351
351
* Use relative imports for references inside scikit-learn.
352
352
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
+
353
359
* **Please don't use `import *` in any case **. It is considered harmful
354
360
by the `official Python recommendations
355
361
<http://docs.python.org/howto/doanddont.html#from-module-import> `_.
@@ -621,5 +627,31 @@ advised to maintain notes on the `GitHub wiki
621
627
Specific models
622
628
---------------
623
629
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
+
624
654
In linear models, coefficients are stored in an array called ``coef_ ``,
625
655
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