Skip to content

Commit

Permalink
Update linting and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
reidjohnson committed Aug 17, 2024
1 parent ecceee5 commit 35bf344
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 8 additions & 0 deletions docs/getting_started/developers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ On macOS, run::
Test and Coverage
~~~~~~~~~~~~~~~~~

Ensure that `pytest` and `pytest-cov` are installed::

$ pip install pytest pytest-cov

To test the code::

$ python -m pytest quantile_forest -v

To test the code and produce a coverage report::

$ python -m pytest quantile_forest --cov-report html --cov=quantile_forest

To test the documentation::

$ python -m pytest docs/user_guide/*rst
Expand Down
16 changes: 8 additions & 8 deletions quantile_forest/_quantile_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def fit(self, X, y, sample_weight=None, sparse_pickle=False):
X, y_sorted, sorter=sorter, sample_weight=sample_weight
)

# Get map of tree leaf nodes to target value bounds.
# Get map of tree leaf nodes to target value bounds (for monotonicity constraints).
y_bound_leaves = self._get_y_bound_leaves(y_sorted, y_train_leaves)

# Create quantile forest object.
Expand Down Expand Up @@ -254,7 +254,7 @@ def _get_y_train_leaves(self, X, y, sorter=None, sample_weight=None):
outputs. Each node list is padded to equal length with 0s.
"""
n_samples = X.shape[0]
y_dim = y.shape[-1]
n_outputs = y.shape[-1]

if isinstance(self.max_samples_leaf, (Integral, np.integer)):
max_samples_leaf = self.max_samples_leaf
Expand Down Expand Up @@ -322,7 +322,7 @@ def _get_y_train_leaves(self, X, y, sorter=None, sample_weight=None):
max_samples_leaf = sample_count

# Initialize NumPy array (more efficient serialization than dict/list).
shape = (self.n_estimators, max_node_count, y_dim, max_samples_leaf)
shape = (self.n_estimators, max_node_count, n_outputs, max_samples_leaf)
y_train_leaves = np.zeros(shape, dtype=np.int64)

for i, estimator in enumerate(self.estimators_):
Expand All @@ -347,12 +347,12 @@ def _get_y_train_leaves(self, X, y, sorter=None, sample_weight=None):
y_indices = random.sample(y_indices, max_samples_leaf)

if sorter is not None:
y_indices = np.asarray(y_indices).reshape(-1, y_dim).swapaxes(0, 1)
y_indices = np.asarray(y_indices).reshape(-1, n_outputs).swapaxes(0, 1)

for j in range(y_dim):
for j in range(n_outputs):
y_train_leaves[i, leaf_idx, j, : len(y_indices[j])] = y_indices[j]
else:
for j in range(y_dim):
for j in range(n_outputs):
y_train_leaves[i, leaf_idx, j, : len(y_indices)] = y_indices

return y_train_leaves
Expand Down Expand Up @@ -1152,7 +1152,7 @@ class RandomForestQuantileRegressor(BaseForestQuantileRegressor):
Monotonicity constraints are not supported for:
- multioutput regressions (i.e. when `n_outputs_ > 1`),
- regressions trained on data with missing values,
- trees with large leaf samples (i.e. when `max_samples_leaf > 1`).
- trees with multi-sample leaves (i.e. when `max_samples_leaf > 1`).
.. sklearn-versionadded:: 1.4
Expand Down Expand Up @@ -1498,7 +1498,7 @@ class ExtraTreesQuantileRegressor(BaseForestQuantileRegressor):
Monotonicity constraints are not supported for:
- multioutput regressions (i.e. when `n_outputs_ > 1`),
- regressions trained on data with missing values,
- trees with large leaf samples (i.e. when `max_samples_leaf > 1`).
- trees with multi-sample leaves (i.e. when `max_samples_leaf > 1`).
.. sklearn-versionadded:: 1.4
Expand Down
3 changes: 3 additions & 0 deletions quantile_forest/_quantile_forest_fast.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ cpdef vector[double] calc_weighted_quantile(
sorted_quantile_indices = vector[double](n_quantiles)
for i in range(<intp_t>(sorted_quantile_indices.size())):
sorted_quantile_indices[i] = <double>i

# Sort the quantiles in ascending order to help reuse calculations for efficiency.
# The sorted quantile indices allow assigning output based on the original ordering.
parallel_qsort_asc(quantiles, sorted_quantile_indices, 0, n_quantiles - 1)

out = vector[double](n_quantiles)
Expand Down

0 comments on commit 35bf344

Please sign in to comment.