Skip to content
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

Remove the pygam dependency and allow latest versions of Cython, numpy, scipy, scikit-learn #812

Merged
merged 3 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions causalml/inference/tree/causal/_criterion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ cdef class CausalRegressionCriterion(RegressionCriterion):

return 0

cdef void node_value(self, float64_t * dest) nogil:
cdef void node_value(self, float64_t * dest) noexcept nogil:
"""Compute the node values of sample_indices[start:end] into dest."""
dest[0] = self.state.node.ct_y_sum / self.state.node.ct_count
dest[1] = self.state.node.tr_y_sum / self.state.node.tr_count
Expand All @@ -228,7 +228,7 @@ cdef class StandardMSE(CausalRegressionCriterion):
Source: https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/tree/_criterion.pyx
"""

cdef float64_t node_impurity(self) nogil:
cdef float64_t node_impurity(self) noexcept nogil:
"""Evaluate the impurity of the current node.
Evaluate the MSE criterion as impurity of the current node,
i.e. the impurity of sample_indices[start:end]. The smaller the impurity the
Expand All @@ -246,7 +246,7 @@ cdef class StandardMSE(CausalRegressionCriterion):

return impurity / self.n_outputs

cdef float64_t proxy_impurity_improvement(self) nogil:
cdef float64_t proxy_impurity_improvement(self) noexcept nogil:
"""Compute a proxy of the impurity reduction.
This method is used to speed up the search for the best split.
It is a proxy quantity such that the split that maximizes this value
Expand Down Expand Up @@ -279,7 +279,7 @@ cdef class StandardMSE(CausalRegressionCriterion):
self,
float64_t * impurity_left,
float64_t * impurity_right
) nogil:
) noexcept nogil:
"""Evaluate the impurity in children nodes.
i.e. the impurity of the left child (sample_indices[start:pos]) and the
impurity the right child (sample_indices[pos:end]).
Expand Down Expand Up @@ -335,7 +335,7 @@ cdef class CausalMSE(CausalRegressionCriterion):
effect = alpha * tau^2 - (1 - alpha) * (1 + train_to_est_ratio) * (VAR_tr / p + VAR_cont / (1 - p))
"""

cdef float64_t node_impurity(self) nogil:
cdef float64_t node_impurity(self) noexcept nogil:
"""
Evaluate the impurity of the current node, i.e. the impurity of sample_indices[start:end].
"""
Expand Down Expand Up @@ -365,7 +365,7 @@ cdef class CausalMSE(CausalRegressionCriterion):
cdef float64_t get_variance(self, float64_t y_sum, float64_t y_sq_sum, float64_t count) nogil:
return y_sq_sum / count - (y_sum * y_sum) / (count * count)

cdef void children_impurity(self, float64_t * impurity_left, float64_t * impurity_right) nogil:
cdef void children_impurity(self, float64_t * impurity_left, float64_t * impurity_right) noexcept nogil:
"""
Evaluate the impurity in children nodes, i.e. the impurity of the
left child (sample_indices[start:pos]) and the impurity the right child
Expand Down Expand Up @@ -405,7 +405,7 @@ cdef class TTest(CausalRegressionCriterion):
"""
TTest impurity criterion for Causal Tree based on "Su, Xiaogang, et al. (2009). Subgroup analysis via recursive partitioning."
"""
cdef float64_t node_impurity(self) nogil:
cdef float64_t node_impurity(self) noexcept nogil:
cdef float64_t impurity
cdef float64_t node_tau
cdef float64_t tr_var
Expand All @@ -432,7 +432,7 @@ cdef class TTest(CausalRegressionCriterion):
cdef float64_t get_variance(self, float64_t y_sum, float64_t y_sq_sum, float64_t count) nogil:
return y_sq_sum / count - (y_sum * y_sum) / (count * count)

cdef void children_impurity(self, float64_t * impurity_left, float64_t * impurity_right) nogil:
cdef void children_impurity(self, float64_t * impurity_left, float64_t * impurity_right) noexcept nogil:
"""
Evaluate the impurity in children nodes, i.e. the impurity of the
left child (sample_indices[start:pos]) and the impurity the right child
Expand Down Expand Up @@ -496,10 +496,10 @@ cdef class TTest(CausalRegressionCriterion):

cdef float64_t impurity_improvement(self, float64_t impurity_parent,
float64_t impurity_left,
float64_t impurity_right) nogil:
float64_t impurity_right) noexcept nogil:
return self.state.left.split_metric

cdef float64_t proxy_impurity_improvement(self) nogil:
cdef float64_t proxy_impurity_improvement(self) noexcept nogil:
"""Compute a proxy of the impurity reduction. In case of t statistic - proxy_impurity_improvement
is the same as impurity_improvement.
"""
Expand Down
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,25 @@ classifiers = [
"Operating System :: OS Independent",
]

requires-python = ">=3.7"
requires-python = ">=3.9"
dependencies = [
"forestci==0.6",
"pathos==0.2.9",
"pip>=10.0",
"numpy>=1.18.5, <2",
"numpy>=1.18.5",
"scipy>=1.4.1",
"matplotlib",
"pandas>=0.24.1",
"scikit-learn>=1.5.2, <1.6",
"scikit-learn>=1.5.2",
"statsmodels>=0.9.0",
"Cython<=0.29.34",
"Cython",
"seaborn",
"xgboost",
"pydotplus",
"tqdm",
"shap",
"dill",
"lightgbm",
"pygam",
"packaging",
"graphviz",
]
Expand Down