8000 ENH make base classes abstract meta classes · pfdevilliers/scikit-learn@26c31bf · GitHub
[go: up one dir, main page]

Skip to content

Commit 26c31bf

Browse files
committed
ENH make base classes abstract meta classes
1 parent 1e9c337 commit 26c31bf

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

sklearn/ensemble/forest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class calls the ``fit`` method of each sub-estimator on random samples
3535

3636
import itertools
3737
import numpy as np
38+
from abc import ABCMeta, abstractmethod
3839

3940
from ..base import ClassifierMixin, RegressorMixin
4041
from ..externals.joblib import Parallel, delayed, cpu_count
@@ -164,6 +165,9 @@ class BaseForest(BaseEnsemble, SelectorMixin):
164165
Warning: This class should not be used directly. Use derived classes
165166
instead.
166167
"""
168+
__metaclass__ = ABCMeta
169+
170+
@abstractmethod
167171
def __init__(self, base_estimator,
168172
n_estimators=10,
169173
estimator_params=[],
@@ -294,6 +298,9 @@ class ForestClassifier(BaseForest, ClassifierMixin):
294298
Warning: This class should not be used directly. Use derived classes
295299
instead.
296300
"""
301+
__metaclass__ = ABCMeta
302+
303+
@abstractmethod
297304
def __init__(self, base_estimator,
298305
n_estimators=10,
299306
estimator_params=[],
@@ -394,6 +401,9 @@ class ForestRegressor(BaseForest, RegressorMixin):
394401
Warning: This class should not be used directly. Use derived classes
395402
instead.
396403
"""
404+
__metaclass__ = ABCMeta
405+
406+
@abstractmethod
397407
def __init__(self, base_estimator,
398408
n_estimators=10,
399409
estimator_params=[],

sklearn/ensemble/gradient_boosting.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ def _update_terminal_region(self, tree, terminal_regions, leaf, X, y,
326326

327327
class BaseGradientBoosting(BaseEnsemble):
328328
"""Abstract base class for Gradient Boosting. """
329+
__metaclass__ = ABCMeta
330+
331+
@abstractmethod
329332
def __init__(self, loss, learn_rate, n_estimators, min_samples_split,
330333
min_samples_leaf, max_depth, init, subsample, random_state):
331334
if n_estimators <= 0:

sklearn/svm/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import scipy.sparse as sp
33
import warnings
4+
from abc import ABCMeta, abstractmethod
45

56
from . import libsvm, liblinear
67
from . import libsvm_sparse
@@ -71,8 +72,10 @@ class BaseLibSVM(BaseEstimator):
7172
This implements support vector machine classification and regression.
7273
"""
7374

75+
__metaclass__ = ABCMeta
7476
_sparse_kernels = ["linear", "poly", "rbf", "sigmoid", "precomputed"]
7577

78+
@abstractmethod
7679
def __init__(self, impl, kernel, degree, gamma, coef0,
7780
tol, C, nu, epsilon, shrinking, probability, cache_size,
7881
sparse, class_weight, verbose):

sklearn/tree/tree.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from __future__ import division
1414
import numpy as np
15+
from abc import ABCMeta, abstractmethod
1516

1617
from ..base import BaseEstimator, ClassifierMixin, RegressorMixin
1718
from ..feature_selection.selector_mixin import SelectorMixin
@@ -408,6 +409,9 @@ class BaseDecisionTree(BaseEstimator, SelectorMixin):
408409
Warning: This class should not be used directly.
409410
Use derived classes instead.
410411
"""
412+
__metaclass__ = ABCMeta
413+
414+
@abstractmethod
411415
def __init__(self, criterion,
412416
max_depth,
413417
min_samples_split,

0 commit comments

Comments
 (0)
0