| |
- builtins.object
-
- RegressorTree
- RegressorTreeUtility
class RegressorTree(builtins.object) |
|
RegressorTree(max_depth=5, min_samples_split=2)
A class representing a decision tree for regression.
Args:
max_depth: (int) - The maximum depth of the decision tree.
min_samples_split: (int) - The minimum number of samples required to split a node.
n_features: (int) - The number of features in the dataset.
X: (array-like) - The input features.
y: (array-like) - The target labels.
Methods:
fit(X, y, verbose=False): Fits the decision tree to the training data.
predict(X): Predicts the target values for the input features.
_traverse_tree(x, node): Traverses the decision tree for a single sample x.
_leran_recursive(indices, depth): Recursive helper function for learning. |
|
Methods defined here:
- __init__(self, max_depth=5, min_samples_split=2)
- Initialize the decision tree.
Args:
max_depth (int): The maximum depth of the decision tree.
min_samples_split (int): The minimum number of samples required to split a node.
- fit(self, X, y, sample_weight=None, verbose=False)
- Fit the decision tree to the training data.
Args:
X: (array-like) - The input features.
y: (array-like) - The target labels.
sample_weight: (array-like) - The sample weights (default: None).
verbose: (bool) - If True, print detailed logs during fitting.
Returns:
dict: The learned decision tree.
- predict(self, X)
- Predict the target value for a record or batch of records using the decision tree.
Args:
X: (array-like) - The input features.
Returns:
np.ndarray: The predicted target values.
Data descriptors defined here:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
|
class RegressorTreeUtility(builtins.object) |
|
RegressorTreeUtility(X, y, min_samples_split, n_features)
Utility class containing helper functions for building the Regressor Tree.
Handles variance calculation, leaf value calculation, and finding the best split. |
|
Methods defined here:
- __init__(self, X, y, min_samples_split, n_features)
- Initialize the utility class with references to data and parameters.
Args:
X (np.ndarray): Reference to the feature data.
y (np.ndarray): Reference to the target data.
min_samples_split (int): Minimum number of samples required to split a node.
n_features (int): Total number of features in X.
- best_split(self, indices, sample_weight=None)
- Finds the best split for the data subset defined by indices.
- calculate_leaf_value(self, indices, sample_weight=None)
- Calculate the weighted mean value for a leaf node.
- calculate_variance(self, indices, sample_weight=None)
- Calculate weighted variance for the subset defined by indices.
Data descriptors defined here:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
| |