Skip to content

Commit

Permalink
Remove the pygam dependency and allow latest versions of Cython, nump…
Browse files Browse the repository at this point in the history
…y, scipy, scikit-learn (#812)
  • Loading branch information
jeongyoonlee authored Feb 16, 2025
1 parent 22b13c2 commit 618367d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
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

0 comments on commit 618367d

Please sign in to comment.