Fix random forest API for scikit-learn 0.21
@@ -21,7 +21,7 @@ import warnings
import daal4py
from .._utils import (getFPType, get_patch_message)
-from daal4py.sklearn._utils import daal_check_version
+from daal4py.sklearn._utils import daal_check_version, sklearn_check_version
import logging
from sklearn.tree import (DecisionTreeClassifier, DecisionTreeRegressor)
@@ -503,6 +503,29 @@ class RandomForestClassifier(RandomForestClassifier_original):
max_samples=None,
maxBins=256,
minBinSize=1):
+ if sklearn_check_version('0.21'):
+ super(RandomForestClassifier, self).__init__(
+ n_estimators=n_estimators,
+ criterion=criterion,
+ max_depth=max_depth,
+ min_samples_split=min_samples_split,
+ min_samples_leaf=min_samples_leaf,
+ min_weight_fraction_leaf=min_weight_fraction_leaf,
+ max_features=max_features,
+ max_leaf_nodes=max_leaf_nodes,
+ min_impurity_decrease=min_impurity_decrease,
+ min_impurity_split=min_impurity_split,
+ bootstrap=bootstrap,
+ oob_score=oob_score,
+ n_jobs=n_jobs,
+ random_state=random_state,
+ verbose=verbose,
+ warm_start=warm_start,
+ class_weight=class_weight
+ )
+ self.ccp_alpha = ccp_alpha
+ self.max_samples = max_samples
+ else:
super(RandomForestClassifier, self).__init__(
n_estimators=n_estimators,
criterion=criterion,
@@ -524,6 +547,7 @@ class RandomForestClassifier(RandomForestClassifier_original):
ccp_alpha=ccp_alpha,
max_samples=max_samples
)
+
self.maxBins = maxBins
self.minBinSize = minBinSize
@@ -726,6 +750,28 @@ class RandomForestRegressor(RandomForestRegressor_original):
max_samples=None,
maxBins=256,
minBinSize=1):
+ if sklearn_check_version('0.21'):
+ super(RandomForestRegressor, self).__init__(
+ n_estimators=n_estimators,
+ criterion=criterion,
+ max_depth=max_depth,
+ min_samples_split=min_samples_split,
+ min_samples_leaf=min_samples_leaf,
+ min_weight_fraction_leaf=min_weight_fraction_leaf,
+ max_features=max_features,
+ max_leaf_nodes=max_leaf_nodes,
+ min_impurity_decrease=min_impurity_decrease,
+ min_impurity_split=min_impurity_split,
+ bootstrap=bootstrap,
+ oob_score=oob_score,
+ n_jobs=n_jobs,
+ random_state=random_state,
+ verbose=verbose,
+ warm_start=warm_start
+ )
+ self.ccp_alpha = ccp_alpha
+ self.max_samples = max_samples
+ else:
super(RandomForestRegressor, self).__init__(
n_estimators=n_estimators,
criterion=criterion,
