-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trees Module #351
Merged
Merged
Trees Module #351
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from dislib.classification.csvm.base import CascadeSVM | ||
from dislib.commons.rf.forest import RandomForestClassifier | ||
from dislib.trees.forest import RandomForestClassifier | ||
|
||
__all__ = ["CascadeSVM", "RandomForestClassifier"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from dislib.regression.linear.base import LinearRegression | ||
from dislib.regression.lasso.base import Lasso | ||
from dislib.commons.rf.forest import RandomForestRegressor | ||
from dislib.trees.forest import RandomForestRegressor | ||
|
||
__all__ = ["LinearRegression", "Lasso", "RandomForestRegressor"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from dislib.trees.forest import RandomForestClassifier, RandomForestRegressor | ||
from dislib.trees.decision_tree import ( | ||
DecisionTreeClassifier, | ||
DecisionTreeRegressor, | ||
) | ||
from dislib.trees.data import transform_to_rf_dataset | ||
|
||
__all__ = [ | ||
"RandomForestClassifier", | ||
"RandomForestRegressor", | ||
"DecisionTreeClassifier", | ||
"DecisionTreeRegressor", | ||
"transform_to_rf_dataset", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
from sklearn.tree import DecisionTreeClassifier as SklearnDTClassifier | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please consider exposing only objects that are necessary in dislib/regression/init.py |
||
from sklearn.tree import DecisionTreeRegressor as SklearnDTRegressor | ||
|
||
from dislib.commons.rf.test_split import test_split | ||
from dislib.trees.test_split import test_split | ||
from dislib.data.array import Array | ||
|
||
|
||
|
@@ -27,13 +27,17 @@ def __init__( | |
sklearn_max, | ||
bootstrap, | ||
random_state, | ||
base_node, | ||
base_tree, | ||
): | ||
self.try_features = try_features | ||
self.max_depth = max_depth | ||
self.distr_depth = distr_depth | ||
self.sklearn_max = sklearn_max | ||
self.bootstrap = bootstrap | ||
self.random_state = random_state | ||
self.base_node = base_node | ||
self.base_tree = base_tree | ||
|
||
self.n_features = None | ||
self.n_classes = None | ||
|
@@ -48,7 +52,6 @@ def fit(self, dataset): | |
Parameters | ||
---------- | ||
dataset : dislib.classification.rf._data.RfDataset | ||
|
||
""" | ||
|
||
self.n_features = dataset.get_n_features() | ||
|
@@ -63,9 +66,8 @@ def fit(self, dataset): | |
sample, y_s = _sample_selection( | ||
n_samples, y_targets, self.bootstrap, seed | ||
) | ||
Node = _ClassificationNode if self.n_classes else _RegressionNode | ||
|
||
self.tree = Node() | ||
self.tree = self.base_node() | ||
self.nodes_info = [] | ||
self.subtrees = [] | ||
tree_traversal = [(self.tree, sample, y_s, 0)] | ||
|
@@ -87,8 +89,8 @@ def fit(self, dataset): | |
compss_delete_object(y_s) | ||
node.content = len(self.nodes_info) | ||
self.nodes_info.append(node_info) | ||
node.left = Node() | ||
node.right = Node() | ||
node.left = self.base_node() | ||
node.right = self.base_node() | ||
depth = depth + 1 | ||
tree_traversal.append((node.right, right_group, y_r, depth)) | ||
tree_traversal.append((node.left, left_group, y_l, depth)) | ||
|
@@ -102,6 +104,8 @@ def fit(self, dataset): | |
self.try_features, | ||
self.sklearn_max, | ||
self.random_state, | ||
self.base_node, | ||
self.base_tree, | ||
samples_path, | ||
features_path, | ||
) | ||
|
@@ -216,6 +220,8 @@ def __init__( | |
sklearn_max, | ||
bootstrap, | ||
random_state, | ||
_ClassificationNode, | ||
SklearnDTClassifier, | ||
) | ||
|
||
def predict_proba(self, x_row): | ||
|
@@ -234,7 +240,6 @@ def predict_proba(self, x_row): | |
of the column being codes of the fitted | ||
dislib.classification.rf.data.RfDataset. The returned object can be | ||
a pycompss.runtime.Future object. | ||
|
||
""" | ||
|
||
assert self.tree is not None, "The decision tree is not fitted." | ||
|
@@ -319,6 +324,8 @@ def __init__( | |
sklearn_max, | ||
bootstrap, | ||
random_state, | ||
_RegressionNode, | ||
SklearnDTRegressor, | ||
) | ||
|
||
|
||
|
@@ -539,6 +546,8 @@ def _build_subtree_wrapper( | |
m_try, | ||
sklearn_max, | ||
random_state, | ||
base_node, | ||
base_tree, | ||
samples_file, | ||
features_file, | ||
): | ||
|
@@ -553,6 +562,8 @@ def _build_subtree_wrapper( | |
m_try, | ||
sklearn_max, | ||
seed, | ||
base_node, | ||
base_tree, | ||
samples_file, | ||
features_file, | ||
) | ||
|
@@ -566,6 +577,8 @@ def _build_subtree_wrapper( | |
m_try, | ||
sklearn_max, | ||
seed, | ||
base_node, | ||
base_tree, | ||
samples_file, | ||
) | ||
|
||
|
@@ -580,6 +593,8 @@ def _build_subtree_using_features( | |
m_try, | ||
sklearn_max, | ||
seed, | ||
base_node, | ||
base_tree, | ||
samples_file, | ||
features_file, | ||
): | ||
|
@@ -593,6 +608,8 @@ def _build_subtree_using_features( | |
m_try, | ||
sklearn_max, | ||
random_state, | ||
base_node, | ||
base_tree, | ||
samples_file, | ||
features_file=features_file, | ||
) | ||
|
@@ -608,6 +625,8 @@ def _build_subtree( | |
m_try, | ||
sklearn_max, | ||
seed, | ||
base_node, | ||
base_tree, | ||
samples_file, | ||
): | ||
random_state = RandomState(seed) | ||
|
@@ -620,6 +639,8 @@ def _build_subtree( | |
m_try, | ||
sklearn_max, | ||
random_state, | ||
base_node, | ||
base_tree, | ||
samples_file, | ||
) | ||
|
||
|
@@ -633,19 +654,19 @@ def _compute_build_subtree( | |
m_try, | ||
sklearn_max, | ||
random_state, | ||
base_node, | ||
base_tree, | ||
samples_file, | ||
features_file=None, | ||
use_sklearn=True, | ||
): | ||
Node = _ClassificationNode if n_classes else _RegressionNode | ||
SklearnDT = SklearnDTClassifier if n_classes else SklearnDTRegressor | ||
if not sample.size: | ||
return Node() | ||
return base_node() | ||
if features_file is not None: | ||
mmap = np.load(features_file, mmap_mode="r", allow_pickle=False) | ||
else: | ||
mmap = np.load(samples_file, mmap_mode="r", allow_pickle=False).T | ||
subtree = Node() | ||
subtree = base_node() | ||
tree_traversal = [(subtree, sample, y_s, 0)] | ||
while tree_traversal: | ||
node, sample, y_s, depth = tree_traversal.pop() | ||
|
@@ -655,7 +676,7 @@ def _compute_build_subtree( | |
sklearn_max_depth = None | ||
else: | ||
sklearn_max_depth = max_depth - depth | ||
dt = SklearnDT( | ||
dt = base_tree( | ||
max_features=m_try, | ||
max_depth=sklearn_max_depth, | ||
random_state=random_state, | ||
|
@@ -681,8 +702,8 @@ def _compute_build_subtree( | |
node_info, left_group, y_l, right_group, y_r = split | ||
node.content = node_info | ||
if isinstance(node_info, _InnerNodeInfo): | ||
node.left = Node() | ||
node.right = Node() | ||
node.left = base_node() | ||
node.right = base_node() | ||
tree_traversal.append( | ||
(node.right, right_group, y_r, depth + 1) | ||
) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please consider exposing only objects that are necessary in dislib/regression/init.py
(currently all of them are exposed)