diff --git a/causalml/inference/tree/causaltree.html b/causalml/inference/tree/causaltree.html deleted file mode 100644 index a07ba4e7..00000000 --- a/causalml/inference/tree/causaltree.html +++ /dev/null @@ -1,3588 +0,0 @@ - - - -
- -Generated by Cython 0.29.24
-
- Yellow lines hint at Python interaction.
- Click on a line that starts with a "+
" to see the C code that Cython generated for it.
-
Raw output: causaltree.c
-+001: # cython: cdivision=True-
__pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
002: # cython: boundscheck=False-
003: # cython: wraparound=False-
004:
- 005:
-+006: import logging-
__pyx_t_1 = __Pyx_Import(__pyx_n_s_logging, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+007: import numbers-
__pyx_t_1 = __Pyx_Import(__pyx_n_s_numbers, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_numbers, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+008: import numpy as np-
__pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+009: import pandas as pd-
__pyx_t_1 = __Pyx_Import(__pyx_n_s_pandas, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pd, __pyx_t_1) < 0) __PYX_ERR(0, 9, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
010:
-+011: from math import ceil-
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_ceil); - __Pyx_GIVEREF(__pyx_n_s_ceil); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_ceil); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_math, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_ceil); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_ceil, __pyx_t_1) < 0) __PYX_ERR(0, 11, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+012: from scipy.sparse import issparse-
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_issparse); - __Pyx_GIVEREF(__pyx_n_s_issparse); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_issparse); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_scipy_sparse, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_issparse); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_issparse, __pyx_t_2) < 0) __PYX_ERR(0, 12, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+013: from scipy.stats import norm-
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_norm); - __Pyx_GIVEREF(__pyx_n_s_norm); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_norm); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_scipy_stats, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_norm); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_norm, __pyx_t_1) < 0) __PYX_ERR(0, 13, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
014: from sklearn.tree._criterion cimport RegressionCriterion-
015: from sklearn.tree._criterion cimport SIZE_t, DOUBLE_t-
+016: from sklearn.tree._splitter import BestSplitter-
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 16, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_BestSplitter); - __Pyx_GIVEREF(__pyx_n_s_BestSplitter); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_BestSplitter); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_sklearn_tree__splitter, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_BestSplitter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 16, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_BestSplitter, __pyx_t_2) < 0) __PYX_ERR(0, 16, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+017: from sklearn.tree._tree import DepthFirstTreeBuilder, DOUBLE, DTYPE, Tree-
__pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_DepthFirstTreeBuilder); - __Pyx_GIVEREF(__pyx_n_s_DepthFirstTreeBuilder); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_DepthFirstTreeBuilder); - __Pyx_INCREF(__pyx_n_s_DOUBLE); - __Pyx_GIVEREF(__pyx_n_s_DOUBLE); - PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_DOUBLE); - __Pyx_INCREF(__pyx_n_s_DTYPE); - __Pyx_GIVEREF(__pyx_n_s_DTYPE); - PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_DTYPE); - __Pyx_INCREF(__pyx_n_s_Tree); - __Pyx_GIVEREF(__pyx_n_s_Tree); - PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_Tree); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_sklearn_tree__tree, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_DepthFirstTreeBuilder); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_DepthFirstTreeBuilder, __pyx_t_1) < 0) __PYX_ERR(0, 17, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_DOUBLE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_DOUBLE, __pyx_t_1) < 0) __PYX_ERR(0, 17, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_DTYPE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_DTYPE, __pyx_t_1) < 0) __PYX_ERR(0, 17, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_Tree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_Tree, __pyx_t_1) < 0) __PYX_ERR(0, 17, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+018: from sklearn.utils import check_array, check_random_state-
__pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 18, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_check_array); - __Pyx_GIVEREF(__pyx_n_s_check_array); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_check_array); - __Pyx_INCREF(__pyx_n_s_check_random_state); - __Pyx_GIVEREF(__pyx_n_s_check_random_state); - PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_check_random_state); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_sklearn_utils, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 18, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_check_array); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 18, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_check_array, __pyx_t_2) < 0) __PYX_ERR(0, 18, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_check_random_state); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 18, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_check_random_state, __pyx_t_2) < 0) __PYX_ERR(0, 18, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
019:
-+020: from causalml.inference.meta.utils import check_treatment_vector-
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_check_treatment_vector); - __Pyx_GIVEREF(__pyx_n_s_check_treatment_vector); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_check_treatment_vector); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_causalml_inference_meta_utils, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_check_treatment_vector); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_check_treatment_vector, __pyx_t_1) < 0) __PYX_ERR(0, 20, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
021:
-+022: logger = logging.getLogger('causalml')-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_logging); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_getLogger); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_logger, __pyx_t_2) < 0) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -/* … */ - __pyx_tuple__25 = PyTuple_Pack(1, __pyx_n_s_causalml); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__25); - __Pyx_GIVEREF(__pyx_tuple__25); -
023:
- 024:
-+025: cdef class CausalMSE(RegressionCriterion):-
struct __pyx_obj_8causalml_9inference_4tree_10causaltree_CausalMSE { - struct __pyx_obj_7sklearn_4tree_10_criterion_RegressionCriterion __pyx_base; -}; -/* … */ -struct __pyx_vtabstruct_8causalml_9inference_4tree_10causaltree_CausalMSE { - struct __pyx_vtabstruct_7sklearn_4tree_10_criterion_RegressionCriterion __pyx_base; -}; -static struct __pyx_vtabstruct_8causalml_9inference_4tree_10causaltree_CausalMSE *__pyx_vtabptr_8causalml_9inference_4tree_10causaltree_CausalMSE; - -
026: """Causal Tree mean squared error impurity criterion.-
027:
-028: CausalTreeMSE = right_effect + left_effect-
029:
-030: where,-
031:
-032: effect = alpha * tau^2 - (1 - alpha) * (1 + train_to_est_ratio) * (VAR_tr / p + VAR_cont / (1 - p))-
033: """-
034:
-+035: cdef void node_value(self, double* dest) nogil:-
static void __pyx_f_8causalml_9inference_4tree_10causaltree_9CausalMSE_node_value(struct __pyx_obj_8causalml_9inference_4tree_10causaltree_CausalMSE *__pyx_v_self, double *__pyx_v_dest) {
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_start;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_end;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_i;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_p;
- __pyx_t_7sklearn_4tree_5_tree_DOUBLE_t __pyx_v_is_treated;
- __pyx_t_7sklearn_4tree_5_tree_DOUBLE_t __pyx_v_y_ik;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t *__pyx_v_samples;
- __pyx_t_7sklearn_4tree_5_tree_DOUBLE_t *__pyx_v_sample_weight;
- double __pyx_v_node_ct;
- double __pyx_v_node_tr;
- double __pyx_v_node_ct_sum;
- double __pyx_v_node_tr_sum;
- double __pyx_v_one_over_eps;
-/* … */
- /* function exit code */
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_WriteUnraisable("causalml.inference.tree.causaltree.CausalMSE.node_value", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
- __pyx_L0:;
-}
-
036: """Compute the node value of samples[start:end] into dest."""-
037:
-+038: cdef SIZE_t start = self.start-
__pyx_t_1 = __pyx_v_self->__pyx_base.__pyx_base.start; - __pyx_v_start = __pyx_t_1; -
+039: cdef SIZE_t end = self.end-
__pyx_t_1 = __pyx_v_self->__pyx_base.__pyx_base.end; - __pyx_v_end = __pyx_t_1; -
040:
-041: cdef SIZE_t i-
042: cdef SIZE_t p-
043: cdef DOUBLE_t is_treated-
044: cdef DOUBLE_t y_ik-
045:
-+046: cdef SIZE_t* samples = self.samples-
__pyx_t_2 = __pyx_v_self->__pyx_base.__pyx_base.samples; - __pyx_v_samples = __pyx_t_2; -
+047: cdef DOUBLE_t* sample_weight = self.sample_weight-
__pyx_t_3 = __pyx_v_self->__pyx_base.__pyx_base.sample_weight; - __pyx_v_sample_weight = __pyx_t_3; -
048:
-+049: cdef double node_ct = 0.0-
__pyx_v_node_ct = 0.0; -
+050: cdef double node_tr = 0.0-
__pyx_v_node_tr = 0.0; -
+051: cdef double node_ct_sum = 0.0-
__pyx_v_node_ct_sum = 0.0; -
+052: cdef double node_tr_sum = 0.0-
__pyx_v_node_tr_sum = 0.0; -
+053: cdef double one_over_eps = 1e5-
__pyx_v_one_over_eps = 1e5; -
054:
-+055: for p in range(start, end):-
__pyx_t_1 = __pyx_v_end; - __pyx_t_4 = __pyx_t_1; - for (__pyx_t_5 = __pyx_v_start; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_p = __pyx_t_5; -
+056: i = samples[p]-
__pyx_v_i = (__pyx_v_samples[__pyx_v_p]); -
057:
-+058: if sample_weight != NULL:-
__pyx_t_6 = ((__pyx_v_sample_weight != NULL) != 0); - if (__pyx_t_6) { -/* … */ - } -
059: # the weights of 1 and 1 + eps are used for treatment and control respectively-
+060: is_treated = (sample_weight[i] - 1.0) * one_over_eps-
__pyx_v_is_treated = (((__pyx_v_sample_weight[__pyx_v_i]) - 1.0) * __pyx_v_one_over_eps); -
061:
-062: # assume that there is only one output (k = 0)-
+063: y_ik = self.y[i, 0]-
if (unlikely(!__pyx_v_self->__pyx_base.__pyx_base.y.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 63, __pyx_L1_error)} - __pyx_t_7 = __pyx_v_i; - __pyx_t_8 = 0; - __pyx_v_y_ik = (*((__pyx_t_7sklearn_4tree_5_tree_DOUBLE_t const *) ( /* dim=1 */ ((char *) (((__pyx_t_7sklearn_4tree_5_tree_DOUBLE_t const *) ( /* dim=0 */ (__pyx_v_self->__pyx_base.__pyx_base.y.data + __pyx_t_7 * __pyx_v_self->__pyx_base.__pyx_base.y.strides[0]) )) + __pyx_t_8)) ))); -
064:
-+065: node_tr += is_treated-
__pyx_v_node_tr = (__pyx_v_node_tr + __pyx_v_is_treated); -
+066: node_ct += 1. - is_treated-
__pyx_v_node_ct = (__pyx_v_node_ct + (1. - __pyx_v_is_treated)); -
+067: node_tr_sum += y_ik * is_treated-
__pyx_v_node_tr_sum = (__pyx_v_node_tr_sum + (__pyx_v_y_ik * __pyx_v_is_treated)); -
+068: node_ct_sum += y_ik * (1. - is_treated)-
__pyx_v_node_ct_sum = (__pyx_v_node_ct_sum + (__pyx_v_y_ik * (1. - __pyx_v_is_treated))); - } -
069:
-070: # save the average of treatment effects within a node as a value for the node-
+071: dest[0] = node_tr_sum / node_tr - node_ct_sum / node_ct-
(__pyx_v_dest[0]) = ((__pyx_v_node_tr_sum / __pyx_v_node_tr) - (__pyx_v_node_ct_sum / __pyx_v_node_ct)); -
072:
-+073: cdef double node_impurity(self) nogil:-
static double __pyx_f_8causalml_9inference_4tree_10causaltree_9CausalMSE_node_impurity(struct __pyx_obj_8causalml_9inference_4tree_10causaltree_CausalMSE *__pyx_v_self) {
- CYTHON_UNUSED double *__pyx_v_sum_total;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_start;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_end;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_i;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_p;
- __pyx_t_7sklearn_4tree_5_tree_DOUBLE_t __pyx_v_is_treated;
- __pyx_t_7sklearn_4tree_5_tree_DOUBLE_t __pyx_v_y_ik;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t *__pyx_v_samples;
- __pyx_t_7sklearn_4tree_5_tree_DOUBLE_t *__pyx_v_sample_weight;
- double __pyx_v_node_tr;
- double __pyx_v_node_ct;
- double __pyx_v_node_sum;
- double __pyx_v_node_tr_sum;
- double __pyx_v_node_sq_sum;
- double __pyx_v_node_tr_sq_sum;
- double __pyx_v_tr_var;
- double __pyx_v_ct_var;
- double __pyx_v_one_over_eps;
- double __pyx_v_node_tau;
- double __pyx_r;
-/* … */
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_WriteUnraisable("causalml.inference.tree.causaltree.CausalMSE.node_impurity", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
- __pyx_r = 0;
- __pyx_L0:;
- return __pyx_r;
-}
-
074: """Evaluate the impurity of the current node, i.e. the impurity of-
075: samples[start:end]."""-
076:
-+077: cdef double* sum_total = self.sum_total-
__pyx_t_1 = __pyx_v_self->__pyx_base.__pyx_base.sum_total; - __pyx_v_sum_total = __pyx_t_1; -
078: cdef double impurity-
+079: cdef SIZE_t start = self.start-
__pyx_t_2 = __pyx_v_self->__pyx_base.__pyx_base.start; - __pyx_v_start = __pyx_t_2; -
+080: cdef SIZE_t end = self.end-
__pyx_t_2 = __pyx_v_self->__pyx_base.__pyx_base.end; - __pyx_v_end = __pyx_t_2; -
081:
-082: cdef SIZE_t i-
083: cdef SIZE_t p-
084: cdef DOUBLE_t is_treated-
085: cdef DOUBLE_t y_ik-
086:
-+087: cdef SIZE_t* samples = self.samples-
__pyx_t_3 = __pyx_v_self->__pyx_base.__pyx_base.samples; - __pyx_v_samples = __pyx_t_3; -
+088: cdef DOUBLE_t* sample_weight = self.sample_weight-
__pyx_t_4 = __pyx_v_self->__pyx_base.__pyx_base.sample_weight; - __pyx_v_sample_weight = __pyx_t_4; -
089:
-+090: cdef double node_tr = 0.0-
__pyx_v_node_tr = 0.0; -
+091: cdef double node_ct = 0.0-
__pyx_v_node_ct = 0.0; -
+092: cdef double node_sum = self.sum_total[0]-
__pyx_v_node_sum = (__pyx_v_self->__pyx_base.__pyx_base.sum_total[0]); -
+093: cdef double node_tr_sum = 0.0-
__pyx_v_node_tr_sum = 0.0; -
+094: cdef double node_sq_sum = 0.0-
__pyx_v_node_sq_sum = 0.0; -
+095: cdef double node_tr_sq_sum = 0.0-
__pyx_v_node_tr_sq_sum = 0.0; -
096: cdef double tr_var-
097: cdef double ct_var-
+098: cdef double one_over_eps = 1e5-
__pyx_v_one_over_eps = 1e5; -
099:
-+100: for p in range(start, end):-
__pyx_t_2 = __pyx_v_end; - __pyx_t_5 = __pyx_t_2; - for (__pyx_t_6 = __pyx_v_start; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_p = __pyx_t_6; -
+101: i = samples[p]-
__pyx_v_i = (__pyx_v_samples[__pyx_v_p]); -
102:
-+103: if sample_weight != NULL:-
__pyx_t_7 = ((__pyx_v_sample_weight != NULL) != 0); - if (__pyx_t_7) { -/* … */ - } -
104: # the weights of 1 and 1 + eps are used for treatment and control respectively-
+105: is_treated = (sample_weight[i] - 1.0) * one_over_eps-
__pyx_v_is_treated = (((__pyx_v_sample_weight[__pyx_v_i]) - 1.0) * __pyx_v_one_over_eps); -
106:
-107: # assume that there is only one output (k = 0)-
+108: y_ik = self.y[i, 0]-
if (unlikely(!__pyx_v_self->__pyx_base.__pyx_base.y.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 108, __pyx_L1_error)} - __pyx_t_8 = __pyx_v_i; - __pyx_t_9 = 0; - __pyx_v_y_ik = (*((__pyx_t_7sklearn_4tree_5_tree_DOUBLE_t const *) ( /* dim=1 */ ((char *) (((__pyx_t_7sklearn_4tree_5_tree_DOUBLE_t const *) ( /* dim=0 */ (__pyx_v_self->__pyx_base.__pyx_base.y.data + __pyx_t_8 * __pyx_v_self->__pyx_base.__pyx_base.y.strides[0]) )) + __pyx_t_9)) ))); -
109:
-+110: node_tr += is_treated-
__pyx_v_node_tr = (__pyx_v_node_tr + __pyx_v_is_treated); -
+111: node_ct += (1. - is_treated)-
__pyx_v_node_ct = (__pyx_v_node_ct + (1. - __pyx_v_is_treated)); -
+112: node_tr_sum += y_ik * is_treated-
__pyx_v_node_tr_sum = (__pyx_v_node_tr_sum + (__pyx_v_y_ik * __pyx_v_is_treated)); -
+113: node_sq_sum += y_ik * y_ik-
__pyx_v_node_sq_sum = (__pyx_v_node_sq_sum + (__pyx_v_y_ik * __pyx_v_y_ik)); -
+114: node_tr_sq_sum += y_ik * y_ik * is_treated-
__pyx_v_node_tr_sq_sum = (__pyx_v_node_tr_sq_sum + ((__pyx_v_y_ik * __pyx_v_y_ik) * __pyx_v_is_treated)); - } -
115:
-+116: node_tau = node_tr_sum / node_tr - (node_sum - node_tr_sum) / node_ct-
__pyx_v_node_tau = ((__pyx_v_node_tr_sum / __pyx_v_node_tr) - ((__pyx_v_node_sum - __pyx_v_node_tr_sum) / __pyx_v_node_ct)); -
+117: tr_var = node_tr_sq_sum / node_tr - node_tr_sum * node_tr_sum / (node_tr * node_tr)-
__pyx_v_tr_var = ((__pyx_v_node_tr_sq_sum / __pyx_v_node_tr) - ((__pyx_v_node_tr_sum * __pyx_v_node_tr_sum) / (__pyx_v_node_tr * __pyx_v_node_tr))); -
+118: ct_var = ((node_sq_sum - node_tr_sq_sum) / node_ct --
__pyx_v_ct_var = (((__pyx_v_node_sq_sum - __pyx_v_node_tr_sq_sum) / __pyx_v_node_ct) - (((__pyx_v_node_sum - __pyx_v_node_tr_sum) * (__pyx_v_node_sum - __pyx_v_node_tr_sum)) / (__pyx_v_node_ct * __pyx_v_node_ct))); -
119: (node_sum - node_tr_sum) * (node_sum - node_tr_sum) / (node_ct * node_ct))-
120:
-+121: return (tr_var / node_tr + ct_var / node_ct) - node_tau * node_tau-
__pyx_r = (((__pyx_v_tr_var / __pyx_v_node_tr) + (__pyx_v_ct_var / __pyx_v_node_ct)) - (__pyx_v_node_tau * __pyx_v_node_tau)); - goto __pyx_L0; -
122:
- 123:
-+124: cdef void children_impurity(self, double* impurity_left, double* impurity_right) nogil:-
static void __pyx_f_8causalml_9inference_4tree_10causaltree_9CausalMSE_children_impurity(struct __pyx_obj_8causalml_9inference_4tree_10causaltree_CausalMSE *__pyx_v_self, double *__pyx_v_impurity_left, double *__pyx_v_impurity_right) {
- __pyx_t_7sklearn_4tree_5_tree_DOUBLE_t *__pyx_v_sample_weight;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t *__pyx_v_samples;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_start;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_pos;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_end;
- double *__pyx_v_sum_left;
- double *__pyx_v_sum_right;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_i;
- __pyx_t_7sklearn_4tree_5_tree_SIZE_t __pyx_v_p;
- __pyx_t_7sklearn_4tree_5_tree_DOUBLE_t __pyx_v_is_treated;
- __pyx_t_7sklearn_4tree_5_tree_DOUBLE_t __pyx_v_y_ik;
- double __pyx_v_right_tr;
- double __pyx_v_right_ct;
- double __pyx_v_right_sum;
- double __pyx_v_right_tr_sum;
- double __pyx_v_right_sq_sum;
- double __pyx_v_right_tr_sq_sum;
- double __pyx_v_right_tr_var;
- double __pyx_v_right_ct_var;
- double __pyx_v_left_tr;
- double __pyx_v_left_ct;
- double __pyx_v_left_sum;
- double __pyx_v_left_tr_sum;
- double __pyx_v_left_sq_sum;
- double __pyx_v_left_tr_sq_sum;
- double __pyx_v_left_tr_var;
- double __pyx_v_left_ct_var;
- double __pyx_v_one_over_eps;
- double __pyx_v_right_tau;
- double __pyx_v_left_tau;
-/* … */
- /* function exit code */
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_WriteUnraisable("causalml.inference.tree.causaltree.CausalMSE.children_impurity", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
- __pyx_L0:;
-}
-
125: """Evaluate the impurity in children nodes, i.e. the impurity of the-
126: left child (samples[start:pos]) and the impurity the right child-
127: (samples[pos:end])."""-
128:
-+129: cdef DOUBLE_t* sample_weight = self.sample_weight-
__pyx_t_1 = __pyx_v_self->__pyx_base.__pyx_base.sample_weight; - __pyx_v_sample_weight = __pyx_t_1; -
+130: cdef SIZE_t* samples = self.samples-
__pyx_t_2 = __pyx_v_self->__pyx_base.__pyx_base.samples; - __pyx_v_samples = __pyx_t_2; -
+131: cdef SIZE_t start = self.start-
__pyx_t_3 = __pyx_v_self->__pyx_base.__pyx_base.start; - __pyx_v_start = __pyx_t_3; -
+132: cdef SIZE_t pos = self.pos-
__pyx_t_3 = __pyx_v_self->__pyx_base.__pyx_base.pos; - __pyx_v_pos = __pyx_t_3; -
+133: cdef SIZE_t end = self.end-
__pyx_t_3 = __pyx_v_self->__pyx_base.__pyx_base.end; - __pyx_v_end = __pyx_t_3; -
134:
-+135: cdef double* sum_left = self.sum_left-
__pyx_t_4 = __pyx_v_self->__pyx_base.__pyx_base.sum_left; - __pyx_v_sum_left = __pyx_t_4; -
+136: cdef double* sum_right = self.sum_right-
__pyx_t_4 = __pyx_v_self->__pyx_base.__pyx_base.sum_right; - __pyx_v_sum_right = __pyx_t_4; -
137:
-138: cdef SIZE_t i-
139: cdef SIZE_t p-
140: cdef DOUBLE_t is_treated-
141: cdef DOUBLE_t y_ik-
142:
-+143: cdef double right_tr = 0.0-
__pyx_v_right_tr = 0.0; -
+144: cdef double right_ct = 0.0-
__pyx_v_right_ct = 0.0; -
+145: cdef double right_sum = 0.0-
__pyx_v_right_sum = 0.0; -
+146: cdef double right_tr_sum = 0.0-
__pyx_v_right_tr_sum = 0.0; -
+147: cdef double right_sq_sum = 0.0-
__pyx_v_right_sq_sum = 0.0; -
+148: cdef double right_tr_sq_sum = 0.0-
__pyx_v_right_tr_sq_sum = 0.0; -
149: cdef double right_tr_var-
150: cdef double right_ct_var-
151:
-+152: cdef double left_tr = 0.0-
__pyx_v_left_tr = 0.0; -
+153: cdef double left_ct = 0.0-
__pyx_v_left_ct = 0.0; -
+154: cdef double left_sum = 0.0-
__pyx_v_left_sum = 0.0; -
+155: cdef double left_tr_sum = 0.0-
__pyx_v_left_tr_sum = 0.0; -
+156: cdef double left_sq_sum = 0.0-
__pyx_v_left_sq_sum = 0.0; -
+157: cdef double left_tr_sq_sum = 0.0-
__pyx_v_left_tr_sq_sum = 0.0; -
158: cdef double left_tr_var-
159: cdef double left_ct_var-
160:
-+161: cdef double one_over_eps = 1e5-
__pyx_v_one_over_eps = 1e5; -
162:
-+163: for p in range(start, end):-
__pyx_t_3 = __pyx_v_end; - __pyx_t_5 = __pyx_t_3; - for (__pyx_t_6 = __pyx_v_start; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_p = __pyx_t_6; -
+164: i = samples[p]-
__pyx_v_i = (__pyx_v_samples[__pyx_v_p]); -
165:
-+166: if sample_weight != NULL:-
__pyx_t_7 = ((__pyx_v_sample_weight != NULL) != 0); - if (__pyx_t_7) { -/* … */ - } -
167: # the weights of 1 and 1 + eps are used for control and treatment respectively-
+168: is_treated = (sample_weight[i] - 1.0) * one_over_eps-
__pyx_v_is_treated = (((__pyx_v_sample_weight[__pyx_v_i]) - 1.0) * __pyx_v_one_over_eps); -
169:
-170: # assume that there is only one output (k = 0)-
+171: y_ik = self.y[i, 0]-
if (unlikely(!__pyx_v_self->__pyx_base.__pyx_base.y.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");__PYX_ERR(0, 171, __pyx_L1_error)} - __pyx_t_8 = __pyx_v_i; - __pyx_t_9 = 0; - __pyx_v_y_ik = (*((__pyx_t_7sklearn_4tree_5_tree_DOUBLE_t const *) ( /* dim=1 */ ((char *) (((__pyx_t_7sklearn_4tree_5_tree_DOUBLE_t const *) ( /* dim=0 */ (__pyx_v_self->__pyx_base.__pyx_base.y.data + __pyx_t_8 * __pyx_v_self->__pyx_base.__pyx_base.y.strides[0]) )) + __pyx_t_9)) ))); -
172:
-+173: if p < pos:-
__pyx_t_7 = ((__pyx_v_p < __pyx_v_pos) != 0); - if (__pyx_t_7) { -/* … */ - goto __pyx_L6; - } -
+174: left_tr += is_treated-
__pyx_v_left_tr = (__pyx_v_left_tr + __pyx_v_is_treated); -
+175: left_ct += 1. - is_treated-
__pyx_v_left_ct = (__pyx_v_left_ct + (1. - __pyx_v_is_treated)); -
+176: left_sum += y_ik-
__pyx_v_left_sum = (__pyx_v_left_sum + __pyx_v_y_ik); -
+177: left_tr_sum += y_ik * is_treated-
__pyx_v_left_tr_sum = (__pyx_v_left_tr_sum + (__pyx_v_y_ik * __pyx_v_is_treated)); -
+178: left_sq_sum += y_ik * y_ik-
__pyx_v_left_sq_sum = (__pyx_v_left_sq_sum + (__pyx_v_y_ik * __pyx_v_y_ik)); -
+179: left_tr_sq_sum += y_ik * y_ik * is_treated-
__pyx_v_left_tr_sq_sum = (__pyx_v_left_tr_sq_sum + ((__pyx_v_y_ik * __pyx_v_y_ik) * __pyx_v_is_treated)); -
180: else:-
+181: right_tr += is_treated-
/*else*/ { - __pyx_v_right_tr = (__pyx_v_right_tr + __pyx_v_is_treated); -
+182: right_ct += 1. - is_treated-
__pyx_v_right_ct = (__pyx_v_right_ct + (1. - __pyx_v_is_treated)); -
+183: right_sum += y_ik-
__pyx_v_right_sum = (__pyx_v_right_sum + __pyx_v_y_ik); -
+184: right_tr_sum += y_ik * is_treated-
__pyx_v_right_tr_sum = (__pyx_v_right_tr_sum + (__pyx_v_y_ik * __pyx_v_is_treated)); -
+185: right_sq_sum += y_ik * y_ik-
__pyx_v_right_sq_sum = (__pyx_v_right_sq_sum + (__pyx_v_y_ik * __pyx_v_y_ik)); -
+186: right_tr_sq_sum += y_ik * y_ik * is_treated-
__pyx_v_right_tr_sq_sum = (__pyx_v_right_tr_sq_sum + ((__pyx_v_y_ik * __pyx_v_y_ik) * __pyx_v_is_treated)); - } - __pyx_L6:; - } -
187:
-+188: right_tau = right_tr_sum / right_tr - (sum_right[0] - right_tr_sum) / right_ct-
__pyx_v_right_tau = ((__pyx_v_right_tr_sum / __pyx_v_right_tr) - (((__pyx_v_sum_right[0]) - __pyx_v_right_tr_sum) / __pyx_v_right_ct)); -
+189: right_tr_var = right_tr_sq_sum / right_tr - right_tr_sum * right_tr_sum / (right_tr * right_tr)-
__pyx_v_right_tr_var = ((__pyx_v_right_tr_sq_sum / __pyx_v_right_tr) - ((__pyx_v_right_tr_sum * __pyx_v_right_tr_sum) / (__pyx_v_right_tr * __pyx_v_right_tr))); -
+190: right_ct_var = ((right_sq_sum - right_tr_sq_sum) / right_ct --
__pyx_v_right_ct_var = (((__pyx_v_right_sq_sum - __pyx_v_right_tr_sq_sum) / __pyx_v_right_ct) - (((__pyx_v_right_sum - __pyx_v_right_tr_sum) * (__pyx_v_right_sum - __pyx_v_right_tr_sum)) / (__pyx_v_right_ct * __pyx_v_right_ct))); -
191: (right_sum - right_tr_sum) * (right_sum - right_tr_sum) / (right_ct * right_ct))-
192:
-+193: left_tau = left_tr_sum / left_tr - (sum_left[0] - left_tr_sum) / left_ct-
__pyx_v_left_tau = ((__pyx_v_left_tr_sum / __pyx_v_left_tr) - (((__pyx_v_sum_left[0]) - __pyx_v_left_tr_sum) / __pyx_v_left_ct)); -
+194: left_tr_var = left_tr_sq_sum / left_tr - left_tr_sum * left_tr_sum / (left_tr * left_tr)-
__pyx_v_left_tr_var = ((__pyx_v_left_tr_sq_sum / __pyx_v_left_tr) - ((__pyx_v_left_tr_sum * __pyx_v_left_tr_sum) / (__pyx_v_left_tr * __pyx_v_left_tr))); -
+195: left_ct_var = ((left_sq_sum - left_tr_sq_sum) / left_ct --
__pyx_v_left_ct_var = (((__pyx_v_left_sq_sum - __pyx_v_left_tr_sq_sum) / __pyx_v_left_ct) - (((__pyx_v_left_sum - __pyx_v_left_tr_sum) * (__pyx_v_left_sum - __pyx_v_left_tr_sum)) / (__pyx_v_left_ct * __pyx_v_left_ct))); -
196: (left_sum - left_tr_sum) * (left_sum - left_tr_sum) / (left_ct * left_ct))-
197:
-+198: impurity_left[0] = (left_tr_var / left_tr + left_ct_var / left_ct) - left_tau * left_tau-
(__pyx_v_impurity_left[0]) = (((__pyx_v_left_tr_var / __pyx_v_left_tr) + (__pyx_v_left_ct_var / __pyx_v_left_ct)) - (__pyx_v_left_tau * __pyx_v_left_tau)); -
+199: impurity_right[0] = (right_tr_var / right_tr + right_ct_var / right_ct) - right_tau * right_tau-
(__pyx_v_impurity_right[0]) = (((__pyx_v_right_tr_var / __pyx_v_right_tr) + (__pyx_v_right_ct_var / __pyx_v_right_ct)) - (__pyx_v_right_tau * __pyx_v_right_tau)); -
200:
- 201:
-+202: class CausalTreeRegressor:-
__pyx_t_2 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_empty_tuple, __pyx_n_s_CausalTreeRegressor, __pyx_n_s_CausalTreeRegressor, (PyObject *) NULL, __pyx_n_s_causalml_inference_tree_causaltr, __pyx_kp_s_A_Causal_Tree_regressor_class_Th); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); -/* … */ - __pyx_t_1 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_n_s_CausalTreeRegressor, __pyx_empty_tuple, __pyx_t_2, NULL, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_CausalTreeRegressor, __pyx_t_1) < 0) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
203: """A Causal Tree regressor class.-
204:
-205: The Causal Tree is a decision tree regressor with a split criteria for treatment effects instead of-
206: outputs.-
207:
-208: Details are available at Athey and Imbens (2015) (https://arxiv.org/abs/1504.01132)-
209: """-
+210: def __init__(self, ate_alpha=.05, control_name=0, max_depth=None,-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor___init__[] = "Initialize a Causal Tree\n\n Args:\n ate_alpha (float, optional): the confidence level alpha of the ATE estimate\n control_name (str or int, optional): name of control group\n max_depth (int, optional): the maximum depth of tree\n min_samples_leaf (int, optional): the minimum number of samples in leaves\n random_state (int or np.RandomState, optional): a random seed or a random state\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_1__init__ = {"__init__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_1__init__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor___init__}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_ate_alpha = 0; - PyObject *__pyx_v_control_name = 0; - PyObject *__pyx_v_max_depth = 0; - PyObject *__pyx_v_min_samples_leaf = 0; - PyObject *__pyx_v_random_state = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_ate_alpha,&__pyx_n_s_control_name,&__pyx_n_s_max_depth,&__pyx_n_s_min_samples_leaf,&__pyx_n_s_random_state,0}; - PyObject* values[6] = {0,0,0,0,0,0}; - values[1] = ((PyObject *)((PyObject*)__pyx_float__05)); - values[2] = ((PyObject *)((PyObject *)__pyx_int_0)); - values[3] = ((PyObject *)((PyObject *)Py_None)); - values[4] = ((PyObject *)((PyObject *)__pyx_int_100)); -/* … */ - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_ate_alpha, PyObject *__pyx_v_control_name, PyObject *__pyx_v_max_depth, PyObject *__pyx_v_min_samples_leaf, PyObject *__pyx_v_random_state) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__", 0); -/* … */ - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__26 = PyTuple_Pack(6, __pyx_n_s_self, __pyx_n_s_ate_alpha, __pyx_n_s_control_name, __pyx_n_s_max_depth, __pyx_n_s_min_samples_leaf, __pyx_n_s_random_state); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__26); - __Pyx_GIVEREF(__pyx_tuple__26); - __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(6, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_causaltr_2, __pyx_n_s_init, 210, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 210, __pyx_L1_error) -/* … */ - __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_1__init__, 0, __pyx_n_s_CausalTreeRegressor___init, NULL, __pyx_n_s_causalml_inference_tree_causaltr, __pyx_d, ((PyObject *)__pyx_codeobj__27)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_1, __pyx_tuple__28); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_init, __pyx_t_1) < 0) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_tuple__28 = PyTuple_Pack(5, ((PyObject*)__pyx_float__05), ((PyObject *)__pyx_int_0), ((PyObject *)Py_None), ((PyObject *)__pyx_int_100), ((PyObject *)Py_None)); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__28); - __Pyx_GIVEREF(__pyx_tuple__28); -
+211: min_samples_leaf=100, random_state=None):-
values[5] = ((PyObject *)((PyObject *)Py_None)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ate_alpha); - if (value) { values[1] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_control_name); - if (value) { values[2] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_depth); - if (value) { values[3] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_samples_leaf); - if (value) { values[4] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_random_state); - if (value) { values[5] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 210, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_ate_alpha = values[1]; - __pyx_v_control_name = values[2]; - __pyx_v_max_depth = values[3]; - __pyx_v_min_samples_leaf = values[4]; - __pyx_v_random_state = values[5]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 210, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor___init__(__pyx_self, __pyx_v_self, __pyx_v_ate_alpha, __pyx_v_control_name, __pyx_v_max_depth, __pyx_v_min_samples_leaf, __pyx_v_random_state); -
212: """Initialize a Causal Tree-
213:
-214: Args:-
215: ate_alpha (float, optional): the confidence level alpha of the ATE estimate-
216: control_name (str or int, optional): name of control group-
217: max_depth (int, optional): the maximum depth of tree-
218: min_samples_leaf (int, optional): the minimum number of samples in leaves-
219: random_state (int or np.RandomState, optional): a random seed or a random state-
220: """-
+221: self.ate_alpha = ate_alpha-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_ate_alpha, __pyx_v_ate_alpha) < 0) __PYX_ERR(0, 221, __pyx_L1_error) -
+222: self.control_name = control_name-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_control_name, __pyx_v_control_name) < 0) __PYX_ERR(0, 222, __pyx_L1_error) -
+223: self.max_depth = max_depth-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_max_depth, __pyx_v_max_depth) < 0) __PYX_ERR(0, 223, __pyx_L1_error) -
+224: self.min_samples_leaf = min_samples_leaf-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_leaf, __pyx_v_min_samples_leaf) < 0) __PYX_ERR(0, 224, __pyx_L1_error) -
+225: self.random_state = random_state-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_random_state, __pyx_v_random_state) < 0) __PYX_ERR(0, 225, __pyx_L1_error) -
226:
-+227: self._classes = {}-
__pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 227, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_classes, __pyx_t_1) < 0) __PYX_ERR(0, 227, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+228: self.tree = None-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_tree, Py_None) < 0) __PYX_ERR(0, 228, __pyx_L1_error) -
229:
-+230: self.eps = 1e-5-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_eps, __pyx_float_1eneg_5) < 0) __PYX_ERR(0, 230, __pyx_L1_error) -
231:
-+232: def fit(self, X, treatment, y):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_3fit(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_2fit[] = "Fit the Causal Tree model\n\n Args:\n X (np.matrix): a feature matrix\n treatment (np.array): a treatment vector\n y (np.array): an outcome vector\n\n Returns:\n self (CausalTree object)\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_3fit = {"fit", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_3fit, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_2fit}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_3fit(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fit (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_treatment,&__pyx_n_s_y,0}; - PyObject* values[4] = {0,0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 1); __PYX_ERR(0, 232, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 2); __PYX_ERR(0, 232, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 3); __PYX_ERR(0, 232, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fit") < 0)) __PYX_ERR(0, 232, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_treatment = values[2]; - __pyx_v_y = values[3]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 232, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.fit", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_2fit(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_treatment, __pyx_v_y); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_2fit(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment, PyObject *__pyx_v_y) { - PyObject *__pyx_v_is_treatment = NULL; - PyObject *__pyx_v_w = NULL; - PyObject *__pyx_v_t_groups = NULL; - PyObject *__pyx_v_random_state = NULL; - PyObject *__pyx_v_n_samples = NULL; - PyObject *__pyx_v_n_features = NULL; - PyObject *__pyx_v_n_outputs = NULL; - PyObject *__pyx_v_min_samples_leaf = NULL; - PyObject *__pyx_v_max_depth = NULL; - PyObject *__pyx_v_splitter = NULL; - PyObject *__pyx_v_builder = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fit", 0); - __Pyx_INCREF(__pyx_v_X); - __Pyx_INCREF(__pyx_v_y); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.fit", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_is_treatment); - __Pyx_XDECREF(__pyx_v_w); - __Pyx_XDECREF(__pyx_v_t_groups); - __Pyx_XDECREF(__pyx_v_random_state); - __Pyx_XDECREF(__pyx_v_n_samples); - __Pyx_XDECREF(__pyx_v_n_features); - __Pyx_XDECREF(__pyx_v_n_outputs); - __Pyx_XDECREF(__pyx_v_min_samples_leaf); - __Pyx_XDECREF(__pyx_v_max_depth); - __Pyx_XDECREF(__pyx_v_splitter); - __Pyx_XDECREF(__pyx_v_builder); - __Pyx_XDECREF(__pyx_v_X); - __Pyx_XDECREF(__pyx_v_y); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__29 = PyTuple_Pack(15, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_treatment, __pyx_n_s_y, __pyx_n_s_is_treatment, __pyx_n_s_w, __pyx_n_s_t_groups, __pyx_n_s_random_state, __pyx_n_s_n_samples, __pyx_n_s_n_features, __pyx_n_s_n_outputs, __pyx_n_s_min_samples_leaf, __pyx_n_s_max_depth, __pyx_n_s_splitter, __pyx_n_s_builder); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 232, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__29); - __Pyx_GIVEREF(__pyx_tuple__29); -/* … */ - __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_3fit, 0, __pyx_n_s_CausalTreeRegressor_fit, NULL, __pyx_n_s_causalml_inference_tree_causaltr, __pyx_d, ((PyObject *)__pyx_codeobj__30)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 232, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_fit, __pyx_t_1) < 0) __PYX_ERR(0, 232, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_codeobj__30 = (PyObject*)__Pyx_PyCode_New(4, 0, 15, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__29, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_causaltr_2, __pyx_n_s_fit, 232, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__30)) __PYX_ERR(0, 232, __pyx_L1_error) -
233: """Fit the Causal Tree model-
234:
-235: Args:-
236: X (np.matrix): a feature matrix-
237: treatment (np.array): a treatment vector-
238: y (np.array): an outcome vector-
239:
-240: Returns:-
241: self (CausalTree object)-
242: """-
+243: check_treatment_vector(treatment, self.control_name)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_check_treatment_vector); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 243, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 243, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_treatment, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 243, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_treatment, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 243, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 243, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; - } - __Pyx_INCREF(__pyx_v_treatment); - __Pyx_GIVEREF(__pyx_v_treatment); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_treatment); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 243, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+244: is_treatment = treatment != self.control_name-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 244, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_RichCompare(__pyx_v_treatment, __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 244, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_is_treatment = __pyx_t_2; - __pyx_t_2 = 0; -
+245: w = is_treatment.astype(int)-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_is_treatment, __pyx_n_s_astype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, ((PyObject *)(&PyInt_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)(&PyInt_Type))); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_w = __pyx_t_2; - __pyx_t_2 = 0; -
246:
-+247: t_groups = np.unique(treatment[is_treatment])-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_unique); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_treatment, __pyx_v_is_treatment); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_t_groups = __pyx_t_2; - __pyx_t_2 = 0; -
+248: self._classes[t_groups[0]] = 0-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 248, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_t_groups, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 248, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (unlikely(PyObject_SetItem(__pyx_t_2, __pyx_t_6, __pyx_int_0) < 0)) __PYX_ERR(0, 248, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; -
249:
-250: # input checking replicated from BaseDecisionTree.fit()-
+251: random_state = check_random_state(self.random_state)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_check_random_state); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_random_state); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_6 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_random_state = __pyx_t_6; - __pyx_t_6 = 0; -
+252: X = check_array(X, dtype=DTYPE, accept_sparse="csc")-
__Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_check_array); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_X); - __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_DTYPE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_3) < 0) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_accept_sparse, __pyx_n_s_csc) < 0) __PYX_ERR(0, 252, __pyx_L1_error) - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_X, __pyx_t_3); - __pyx_t_3 = 0; -
+253: y = check_array(y, ensure_2d=False, dtype=None)-
__Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_check_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 253, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 253, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_y); - __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 253, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_ensure_2d, Py_False) < 0) __PYX_ERR(0, 253, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, Py_None) < 0) __PYX_ERR(0, 253, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 253, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_y, __pyx_t_6); - __pyx_t_6 = 0; -
+254: if issparse(X):-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_issparse); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_v_X) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_X); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 254, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__pyx_t_7) { -/* … */ - } -
+255: X.sort_indices()-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_sort_indices); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 255, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 255, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; -
256:
-+257: if X.indices.dtype != np.intc or X.indptr.dtype != np.intc:-
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indices); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_intc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (!__pyx_t_8) { - } else { - __pyx_t_7 = __pyx_t_8; - goto __pyx_L5_bool_binop_done; - } - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_indptr); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_dtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_intc); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 257, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_7 = __pyx_t_8; - __pyx_L5_bool_binop_done:; - if (unlikely(__pyx_t_7)) { -/* … */ - } -
+258: raise ValueError("No support for np.int64 index based "-
__pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 258, __pyx_L1_error) -/* … */ - __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_No_support_for_np_int64_index_ba); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__3); - __Pyx_GIVEREF(__pyx_tuple__3); -
259: "sparse matrices")-
260:
-+261: y = np.atleast_1d(y)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 261, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_atleast_1d); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 261, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_6 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_y) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_y); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 261, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_y, __pyx_t_6); - __pyx_t_6 = 0; -
+262: if y.ndim == 1:-
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_y, __pyx_n_s_ndim); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 262, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_t_6, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 262, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 262, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_7) { -/* … */ - } -
+263: y = np.reshape(y, (-1, 1))-
__Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_reshape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_y, __pyx_tuple__4}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_y, __pyx_tuple__4}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_6) { - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6); __pyx_t_6 = NULL; - } - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_5, __pyx_v_y); - __Pyx_INCREF(__pyx_tuple__4); - __Pyx_GIVEREF(__pyx_tuple__4); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_5, __pyx_tuple__4); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_y, __pyx_t_1); - __pyx_t_1 = 0; -/* … */ - __pyx_tuple__4 = PyTuple_Pack(2, __pyx_int_neg_1, __pyx_int_1); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__4); - __Pyx_GIVEREF(__pyx_tuple__4); -
+264: if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:-
__pyx_t_1 = __Pyx_GetAttr3(__pyx_v_y, __pyx_n_s_dtype, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_DOUBLE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!__pyx_t_8) { - } else { - __pyx_t_7 = __pyx_t_8; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_y, __pyx_n_s_flags); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_contiguous); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_9 = ((!__pyx_t_8) != 0); - __pyx_t_7 = __pyx_t_9; - __pyx_L9_bool_binop_done:; - if (__pyx_t_7) { -/* … */ - } -
+265: y = np.ascontiguousarray(y, dtype=DOUBLE)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_y); - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_DOUBLE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_y, __pyx_t_6); - __pyx_t_6 = 0; -
+266: n_samples, n_features = X.shape-
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 266, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { - PyObject* sequence = __pyx_t_6; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 266, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_2 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 266, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 266, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_3 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 266, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_10(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_3), 2) < 0) __PYX_ERR(0, 266, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L12_unpacking_done; - __pyx_L11_unpacking_failed:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 266, __pyx_L1_error) - __pyx_L12_unpacking_done:; - } - __pyx_v_n_samples = __pyx_t_1; - __pyx_t_1 = 0; - __pyx_v_n_features = __pyx_t_2; - __pyx_t_2 = 0; -
+267: n_outputs = y.shape[1]-
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_y, __pyx_n_s_shape); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 267, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_6, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 267, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_n_outputs = __pyx_t_2; - __pyx_t_2 = 0; -
268:
-+269: if isinstance(self.min_samples_leaf, numbers.Integral):-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_leaf); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numbers); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_Integral); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_7 = PyObject_IsInstance(__pyx_t_2, __pyx_t_1); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 269, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_9 = (__pyx_t_7 != 0); - if (__pyx_t_9) { -/* … */ - goto __pyx_L13; - } -
+270: if not 1 <= self.min_samples_leaf:-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_leaf); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 270, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_RichCompare(__pyx_int_1, __pyx_t_1, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 270, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 270, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = ((!__pyx_t_9) != 0); - if (unlikely(__pyx_t_7)) { -/* … */ - } -
+271: raise ValueError("min_samples_leaf must be at least 1 "-
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 271, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 271, __pyx_L1_error) -
272: "or in (0, 0.5], got %s"-
+273: % self.min_samples_leaf)-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_leaf); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 273, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyString_FormatSafe(__pyx_kp_s_min_samples_leaf_must_be_at_leas, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 273, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+274: min_samples_leaf = self.min_samples_leaf-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_leaf); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_min_samples_leaf = __pyx_t_2; - __pyx_t_2 = 0; -
275: else: # float-
+276: if not 0. < self.min_samples_leaf <= 0.5:-
/*else*/ { - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_leaf); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 276, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_RichCompare(__pyx_float_0_, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 276, __pyx_L1_error) - if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_float_0_5, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 276, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 276, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_9 = ((!__pyx_t_7) != 0); - if (unlikely(__pyx_t_9)) { -/* … */ - } -
+277: raise ValueError("min_samples_leaf must be at least 1 "-
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 277, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 277, __pyx_L1_error) -
278: "or in (0, 0.5], got %s"-
+279: % self.min_samples_leaf)-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_leaf); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 279, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyString_FormatSafe(__pyx_kp_s_min_samples_leaf_must_be_at_leas, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 279, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+280: min_samples_leaf = int(ceil(self.min_samples_leaf * n_samples))-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ceil); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 280, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_leaf); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 280, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = PyNumber_Multiply(__pyx_t_6, __pyx_v_n_samples); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 280, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_6, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 280, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 280, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_min_samples_leaf = __pyx_t_2; - __pyx_t_2 = 0; - } - __pyx_L13:; -
+281: max_depth = (np.iinfo(np.int32).max if self.max_depth is None-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_max_depth); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = (__pyx_t_1 == Py_None); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if ((__pyx_t_9 != 0)) { - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_iinfo); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_max); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_2 = __pyx_t_6; - __pyx_t_6 = 0; - } else { -
+282: else self.max_depth)-
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_max_depth); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 282, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = __pyx_t_6; - __pyx_t_6 = 0; - } - __pyx_v_max_depth = __pyx_t_2; - __pyx_t_2 = 0; -
283:
-+284: self.tree = Tree(-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Tree); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); -/* … */ - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 284, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_tree, __pyx_t_12) < 0) __PYX_ERR(0, 284, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; -
+285: n_features = n_features,-
__pyx_t_6 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 285, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_n_features, __pyx_v_n_features) < 0) __PYX_ERR(0, 285, __pyx_L1_error) -
286: # line below is taken from DecisionTreeRegressor.fit method source-
287: # which comments that the tree shouldn't need the n_classes parameter-
288: # but it apparently does-
+289: n_classes = np.array([1] * n_outputs, dtype=np.intp),-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_1); - { PyObject* __pyx_temp = PyNumber_InPlaceMultiply(__pyx_t_1, __pyx_v_n_outputs); if (unlikely(!__pyx_temp)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_temp); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_temp; - } - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_np); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_intp); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_12) < 0) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_n_classes, __pyx_t_12) < 0) __PYX_ERR(0, 285, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; -
+290: n_outputs = n_outputs)-
if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_n_outputs, __pyx_v_n_outputs) < 0) __PYX_ERR(0, 285, __pyx_L1_error) -
+291: splitter = BestSplitter(criterion = CausalMSE(1, X.shape[0]),-
__Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_BestSplitter); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_6 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_8causalml_9inference_4tree_10causaltree_CausalMSE), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_criterion, __pyx_t_1) < 0) __PYX_ERR(0, 291, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -/* … */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_splitter = __pyx_t_1; - __pyx_t_1 = 0; -
+292: max_features = n_features,-
if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_max_features, __pyx_v_n_features) < 0) __PYX_ERR(0, 291, __pyx_L1_error) -
+293: min_samples_leaf = min_samples_leaf,-
if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_min_samples_leaf, __pyx_v_min_samples_leaf) < 0) __PYX_ERR(0, 291, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_min_weight_leaf, __pyx_int_0) < 0) __PYX_ERR(0, 291, __pyx_L1_error) -
294: min_weight_leaf = 0, # from DecisionTreeRegressor default-
+295: random_state = random_state)-
if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_random_state, __pyx_v_random_state) < 0) __PYX_ERR(0, 291, __pyx_L1_error) -
296: # hardcoded values below come from defaults values in-
297: # sklearn.tree._classes.DecisionTreeRegressor-
+298: builder = DepthFirstTreeBuilder(-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_DepthFirstTreeBuilder); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 298, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); -/* … */ - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 298, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_builder = __pyx_t_12; - __pyx_t_12 = 0; -
+299: splitter = splitter,-
__pyx_t_6 = __Pyx_PyDict_NewPresized(7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 299, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_splitter, __pyx_v_splitter) < 0) __PYX_ERR(0, 299, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_min_samples_split, __pyx_int_2) < 0) __PYX_ERR(0, 299, __pyx_L1_error) -
300: min_samples_split = 2,-
+301: min_samples_leaf = min_samples_leaf,-
if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_min_samples_leaf, __pyx_v_min_samples_leaf) < 0) __PYX_ERR(0, 299, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_min_weight_leaf, __pyx_int_0) < 0) __PYX_ERR(0, 299, __pyx_L1_error) -
302: min_weight_leaf = 0,-
+303: max_depth = max_depth,-
if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_max_depth, __pyx_v_max_depth) < 0) __PYX_ERR(0, 299, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_min_impurity_decrease, __pyx_int_0) < 0) __PYX_ERR(0, 299, __pyx_L1_error) -
304: min_impurity_decrease = 0,-
+305: min_impurity_split = float("-inf"))-
__pyx_t_12 = __Pyx_PyNumber_Float(__pyx_kp_s_inf); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 305, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_min_impurity_split, __pyx_t_12) < 0) __PYX_ERR(0, 299, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; -
+306: builder.build(-
__pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_builder, __pyx_n_s_build); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); -/* … */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); - __pyx_t_6 = 0; -/* … */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+307: self.tree,-
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tree); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); -
+308: X = X,-
__pyx_t_6 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 308, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_X, __pyx_v_X) < 0) __PYX_ERR(0, 308, __pyx_L1_error) -
+309: y = y,-
if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_y, __pyx_v_y) < 0) __PYX_ERR(0, 308, __pyx_L1_error) -
+310: sample_weight = 1 + self.eps * w)-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_eps); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 310, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_Multiply(__pyx_t_2, __pyx_v_w); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 310, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_AddCObj(__pyx_int_1, __pyx_t_3, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 310, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_sample_weight, __pyx_t_2) < 0) __PYX_ERR(0, 308, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
311:
-+312: return self-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self); - __pyx_r = __pyx_v_self; - goto __pyx_L0; -
313:
-+314: def predict(self, X):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_5predict(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_4predict[] = "Predict treatment effects.\n\n Args:\n X (np.matrix): a feature matrix\n\n Returns:\n (numpy.ndarray): Predictions of treatment effects.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_5predict = {"predict", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_5predict, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_4predict}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_5predict(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("predict (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,0}; - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("predict", 1, 2, 2, 1); __PYX_ERR(0, 314, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "predict") < 0)) __PYX_ERR(0, 314, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("predict", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 314, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.predict", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_4predict(__pyx_self, __pyx_v_self, __pyx_v_X); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_4predict(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("predict", 0); - __Pyx_INCREF(__pyx_v_X); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.predict", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_X); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__31 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_X); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 314, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__31); - __Pyx_GIVEREF(__pyx_tuple__31); -/* … */ - __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_5predict, 0, __pyx_n_s_CausalTreeRegressor_predict, NULL, __pyx_n_s_causalml_inference_tree_causaltr, __pyx_d, ((PyObject *)__pyx_codeobj__32)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 314, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_predict, __pyx_t_1) < 0) __PYX_ERR(0, 314, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_codeobj__32 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__31, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_causaltr_2, __pyx_n_s_predict, 314, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__32)) __PYX_ERR(0, 314, __pyx_L1_error) -
315: """Predict treatment effects.-
316:
-317: Args:-
318: X (np.matrix): a feature matrix-
319:
-320: Returns:-
321: (numpy.ndarray): Predictions of treatment effects.-
322: """-
+323: X = check_array(X, dtype=DTYPE, accept_sparse="csr")-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_check_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_X); - __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_DTYPE); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 323, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_accept_sparse, __pyx_n_s_csr) < 0) __PYX_ERR(0, 323, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF_SET(__pyx_v_X, __pyx_t_4); - __pyx_t_4 = 0; -
+324: return self.tree.predict(X).reshape((-1, 1))-
__Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tree); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 324, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_predict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 324, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_X) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_X); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 324, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_reshape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 324, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_tuple__4) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_tuple__4); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 324, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; -
325:
-+326: def fit_predict(self, X, treatment, y, return_ci=False, n_bootstraps=1000, bootstrap_size=10000, verbose=False):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_7fit_predict(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_6fit_predict[] = "Fit the Causal Tree model and predict treatment effects.\n\n Args:\n X (np.matrix): a feature matrix\n treatment (np.array): a treatment vector\n y (np.array): an outcome vector\n return_ci (bool): whether to return confidence intervals\n n_bootstraps (int): number of bootstrap iterations\n bootstrap_size (int): number of samples per bootstrap\n verbose (str): whether to output progress logs\n\n Returns:\n (tuple):\n\n - te (numpy.ndarray): Predictions of treatment effects.\n - te_lower (numpy.ndarray, optional): lower bounds of treatment effects\n - te_upper (numpy.ndarray, optional): upper bounds of treatment effects\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_7fit_predict = {"fit_predict", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_7fit_predict, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_6fit_predict}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_7fit_predict(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_v_return_ci = 0; - PyObject *__pyx_v_n_bootstraps = 0; - PyObject *__pyx_v_bootstrap_size = 0; - PyObject *__pyx_v_verbose = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fit_predict (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_treatment,&__pyx_n_s_y,&__pyx_n_s_return_ci,&__pyx_n_s_n_bootstraps,&__pyx_n_s_bootstrap_size,&__pyx_n_s_verbose,0}; - PyObject* values[8] = {0,0,0,0,0,0,0,0}; - values[4] = ((PyObject *)((PyObject *)Py_False)); - values[5] = ((PyObject *)((PyObject *)__pyx_int_1000)); - values[6] = ((PyObject *)((PyObject *)__pyx_int_10000)); - values[7] = ((PyObject *)((PyObject *)Py_False)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit_predict", 0, 4, 8, 1); __PYX_ERR(0, 326, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit_predict", 0, 4, 8, 2); __PYX_ERR(0, 326, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit_predict", 0, 4, 8, 3); __PYX_ERR(0, 326, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_return_ci); - if (value) { values[4] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_bootstraps); - if (value) { values[5] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 6: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bootstrap_size); - if (value) { values[6] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 7: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_verbose); - if (value) { values[7] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fit_predict") < 0)) __PYX_ERR(0, 326, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_treatment = values[2]; - __pyx_v_y = values[3]; - __pyx_v_return_ci = values[4]; - __pyx_v_n_bootstraps = values[5]; - __pyx_v_bootstrap_size = values[6]; - __pyx_v_verbose = values[7]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fit_predict", 0, 4, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 326, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.fit_predict", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_6fit_predict(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_treatment, __pyx_v_y, __pyx_v_return_ci, __pyx_v_n_bootstraps, __pyx_v_bootstrap_size, __pyx_v_verbose); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_6fit_predict(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment, PyObject *__pyx_v_y, PyObject *__pyx_v_return_ci, PyObject *__pyx_v_n_bootstraps, PyObject *__pyx_v_bootstrap_size, PyObject *__pyx_v_verbose) { - PyObject *__pyx_v_te = NULL; - PyObject *__pyx_v_start = NULL; - PyObject *__pyx_v_te_bootstraps = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_te_b = NULL; - PyObject *__pyx_v_now = NULL; - PyObject *__pyx_v_lapsed = NULL; - PyObject *__pyx_v_te_lower = NULL; - PyObject *__pyx_v_te_upper = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fit_predict", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.fit_predict", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_te); - __Pyx_XDECREF(__pyx_v_start); - __Pyx_XDECREF(__pyx_v_te_bootstraps); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_te_b); - __Pyx_XDECREF(__pyx_v_now); - __Pyx_XDECREF(__pyx_v_lapsed); - __Pyx_XDECREF(__pyx_v_te_lower); - __Pyx_XDECREF(__pyx_v_te_upper); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__33 = PyTuple_Pack(17, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_treatment, __pyx_n_s_y, __pyx_n_s_return_ci, __pyx_n_s_n_bootstraps, __pyx_n_s_bootstrap_size, __pyx_n_s_verbose, __pyx_n_s_te, __pyx_n_s_start, __pyx_n_s_te_bootstraps, __pyx_n_s_i, __pyx_n_s_te_b, __pyx_n_s_now, __pyx_n_s_lapsed, __pyx_n_s_te_lower, __pyx_n_s_te_upper); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 326, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__33); - __Pyx_GIVEREF(__pyx_tuple__33); - __pyx_codeobj__34 = (PyObject*)__Pyx_PyCode_New(8, 0, 17, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__33, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_causaltr_2, __pyx_n_s_fit_predict, 326, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__34)) __PYX_ERR(0, 326, __pyx_L1_error) -/* … */ - __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_7fit_predict, 0, __pyx_n_s_CausalTreeRegressor_fit_predict, NULL, __pyx_n_s_causalml_inference_tree_causaltr, __pyx_d, ((PyObject *)__pyx_codeobj__34)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 326, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_1, __pyx_tuple__35); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_fit_predict, __pyx_t_1) < 0) __PYX_ERR(0, 326, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_tuple__35 = PyTuple_Pack(4, ((PyObject *)Py_False), ((PyObject *)__pyx_int_1000), ((PyObject *)__pyx_int_10000), ((PyObject *)Py_False)); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 326, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__35); - __Pyx_GIVEREF(__pyx_tuple__35); -
327: """Fit the Causal Tree model and predict treatment effects.-
328:
-329: Args:-
330: X (np.matrix): a feature matrix-
331: treatment (np.array): a treatment vector-
332: y (np.array): an outcome vector-
333: return_ci (bool): whether to return confidence intervals-
334: n_bootstraps (int): number of bootstrap iterations-
335: bootstrap_size (int): number of samples per bootstrap-
336: verbose (str): whether to output progress logs-
337:
-338: Returns:-
339: (tuple):-
340:
-341: - te (numpy.ndarray): Predictions of treatment effects.-
342: - te_lower (numpy.ndarray, optional): lower bounds of treatment effects-
343: - te_upper (numpy.ndarray, optional): upper bounds of treatment effects-
344: """-
+345: self.fit(X, treatment, y)-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fit); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_4 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_4 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_X, __pyx_v_treatment, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_X, __pyx_v_treatment, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_5 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment); - __Pyx_GIVEREF(__pyx_v_treatment); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_treatment); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_y); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+346: te = self.predict(X)-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_predict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_v_X) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_X); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_te = __pyx_t_1; - __pyx_t_1 = 0; -
347:
-+348: if not return_ci:-
__pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_return_ci); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 348, __pyx_L1_error) - __pyx_t_7 = ((!__pyx_t_6) != 0); - if (__pyx_t_7) { -/* … */ - } -
+349: return te-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_te); - __pyx_r = __pyx_v_te; - goto __pyx_L0; -
350: else:-
+351: start = pd.datetime.today()-
/*else*/ { - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_today); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_start = __pyx_t_1; - __pyx_t_1 = 0; -
+352: te_bootstraps = np.zeros(shape=(X.shape[0], n_bootstraps))-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_5, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); - __Pyx_INCREF(__pyx_v_n_bootstraps); - __Pyx_GIVEREF(__pyx_v_n_bootstraps); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_n_bootstraps); - __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_shape, __pyx_t_5) < 0) __PYX_ERR(0, 352, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 352, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_te_bootstraps = __pyx_t_5; - __pyx_t_5 = 0; -
+353: for i in range(n_bootstraps):-
__pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_v_n_bootstraps); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) { - __pyx_t_1 = __pyx_t_5; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 353, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - for (;;) { - if (likely(!__pyx_t_9)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_5); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 353, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } else { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_5); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 353, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 353, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } - } else { - __pyx_t_5 = __pyx_t_9(__pyx_t_1); - if (unlikely(!__pyx_t_5)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 353, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_5); - __pyx_t_5 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+354: te_b = self.bootstrap(X, treatment, y, size=bootstrap_size)-
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_bootstrap); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment); - __Pyx_GIVEREF(__pyx_v_treatment); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_treatment); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_y); - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_size, __pyx_v_bootstrap_size) < 0) __PYX_ERR(0, 354, __pyx_L1_error) - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_te_b, __pyx_t_10); - __pyx_t_10 = 0; -
+355: te_bootstraps[:,i] = np.ravel(te_b)-
__Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_ravel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_10 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_te_b) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_te_b); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_slice__5); - __Pyx_GIVEREF(__pyx_slice__5); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_slice__5); - __Pyx_INCREF(__pyx_v_i); - __Pyx_GIVEREF(__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_i); - if (unlikely(PyObject_SetItem(__pyx_v_te_bootstraps, __pyx_t_2, __pyx_t_10) < 0)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; -/* … */ - __pyx_slice__5 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__5)) __PYX_ERR(0, 355, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__5); - __Pyx_GIVEREF(__pyx_slice__5); -
+356: if verbose:-
__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_verbose); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 356, __pyx_L1_error) - if (__pyx_t_7) { -/* … */ - } -
+357: now = pd.datetime.today()-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_today); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_10 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 357, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_now, __pyx_t_10); - __pyx_t_10 = 0; -
+358: lapsed = (now-start).seconds / 60-
__pyx_t_10 = PyNumber_Subtract(__pyx_v_now, __pyx_v_start); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 358, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_seconds); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_int_60); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 358, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_lapsed, __pyx_t_10); - __pyx_t_10 = 0; -
+359: logger.info('{}/{} bootstraps completed. ({:.01f} min lapsed)'.format(i+1, n_bootstraps, lapsed))-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_logger); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_bootstraps_completed_01f_min_la, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_11 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_12 = NULL; - __pyx_t_4 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - __pyx_t_4 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[4] = {__pyx_t_12, __pyx_t_11, __pyx_v_n_bootstraps, __pyx_v_lapsed}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[4] = {__pyx_t_12, __pyx_t_11, __pyx_v_n_bootstraps, __pyx_v_lapsed}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else - #endif - { - __pyx_t_13 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - if (__pyx_t_12) { - __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); __pyx_t_12 = NULL; - } - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_4, __pyx_t_11); - __Pyx_INCREF(__pyx_v_n_bootstraps); - __Pyx_GIVEREF(__pyx_v_n_bootstraps); - PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_4, __pyx_v_n_bootstraps); - __Pyx_INCREF(__pyx_v_lapsed); - __Pyx_GIVEREF(__pyx_v_lapsed); - PyTuple_SET_ITEM(__pyx_t_13, 2+__pyx_t_4, __pyx_v_lapsed); - __pyx_t_11 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_10 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; -
360:
-+361: te_lower = np.percentile(te_bootstraps, (self.ate_alpha/2)*100, axis=1)-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_percentile); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_ate_alpha); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_int_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Multiply(__pyx_t_3, __pyx_int_100); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_te_bootstraps); - __Pyx_GIVEREF(__pyx_v_te_bootstraps); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_te_bootstraps); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_axis, __pyx_int_1) < 0) __PYX_ERR(0, 361, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 361, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_te_lower = __pyx_t_2; - __pyx_t_2 = 0; -
+362: te_upper = np.percentile(te_bootstraps, (1 - self.ate_alpha/2)*100, axis=1)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_percentile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_ate_alpha); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_int_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_t_3, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Multiply(__pyx_t_2, __pyx_int_100); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_te_bootstraps); - __Pyx_GIVEREF(__pyx_v_te_bootstraps); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_te_bootstraps); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_axis, __pyx_int_1) < 0) __PYX_ERR(0, 362, __pyx_L1_error) - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_te_upper = __pyx_t_10; - __pyx_t_10 = 0; -
363:
-+364: return (te, te_lower, te_upper)-
__Pyx_XDECREF(__pyx_r); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 364, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_v_te); - __Pyx_GIVEREF(__pyx_v_te); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_te); - __Pyx_INCREF(__pyx_v_te_lower); - __Pyx_GIVEREF(__pyx_v_te_lower); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_te_lower); - __Pyx_INCREF(__pyx_v_te_upper); - __Pyx_GIVEREF(__pyx_v_te_upper); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_v_te_upper); - __pyx_r = __pyx_t_10; - __pyx_t_10 = 0; - goto __pyx_L0; - } -
365:
-+366: def bootstrap(self, X, treatment, y, size=10000):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_9bootstrap(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_8bootstrap[] = "Runs a single bootstrap.\n\n Fits on bootstrapped sample, then predicts on whole population.\n\n Args:\n X (np.matrix): a feature matrix\n treatment (np.array): a treatment vector\n y (np.array): an outcome vector\n size (int, optional): bootstrap sample size\n\n Returns:\n (np.array): bootstrap predictions\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_9bootstrap = {"bootstrap", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_9bootstrap, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_8bootstrap}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_9bootstrap(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_v_size = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("bootstrap (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_treatment,&__pyx_n_s_y,&__pyx_n_s_size,0}; - PyObject* values[5] = {0,0,0,0,0}; - values[4] = ((PyObject *)((PyObject *)__pyx_int_10000)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("bootstrap", 0, 4, 5, 1); __PYX_ERR(0, 366, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("bootstrap", 0, 4, 5, 2); __PYX_ERR(0, 366, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("bootstrap", 0, 4, 5, 3); __PYX_ERR(0, 366, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_size); - if (value) { values[4] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bootstrap") < 0)) __PYX_ERR(0, 366, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_treatment = values[2]; - __pyx_v_y = values[3]; - __pyx_v_size = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("bootstrap", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 366, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.bootstrap", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_8bootstrap(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_treatment, __pyx_v_y, __pyx_v_size); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_8bootstrap(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment, PyObject *__pyx_v_y, PyObject *__pyx_v_size) { - PyObject *__pyx_v_idxs = NULL; - PyObject *__pyx_v_X_b = NULL; - PyObject *__pyx_v_treatment_b = NULL; - PyObject *__pyx_v_y_b = NULL; - PyObject *__pyx_v_te_b = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("bootstrap", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.bootstrap", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_idxs); - __Pyx_XDECREF(__pyx_v_X_b); - __Pyx_XDECREF(__pyx_v_treatment_b); - __Pyx_XDECREF(__pyx_v_y_b); - __Pyx_XDECREF(__pyx_v_te_b); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__36 = PyTuple_Pack(10, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_treatment, __pyx_n_s_y, __pyx_n_s_size, __pyx_n_s_idxs, __pyx_n_s_X_b, __pyx_n_s_treatment_b, __pyx_n_s_y_b, __pyx_n_s_te_b); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__36); - __Pyx_GIVEREF(__pyx_tuple__36); - __pyx_codeobj__37 = (PyObject*)__Pyx_PyCode_New(5, 0, 10, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__36, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_causaltr_2, __pyx_n_s_bootstrap, 366, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__37)) __PYX_ERR(0, 366, __pyx_L1_error) -/* … */ - __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_9bootstrap, 0, __pyx_n_s_CausalTreeRegressor_bootstrap, NULL, __pyx_n_s_causalml_inference_tree_causaltr, __pyx_d, ((PyObject *)__pyx_codeobj__37)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_1, __pyx_tuple__38); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_bootstrap, __pyx_t_1) < 0) __PYX_ERR(0, 366, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_tuple__38 = PyTuple_Pack(1, ((PyObject *)__pyx_int_10000)); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__38); - __Pyx_GIVEREF(__pyx_tuple__38); -
367: """Runs a single bootstrap.-
368:
-369: Fits on bootstrapped sample, then predicts on whole population.-
370:
-371: Args:-
372: X (np.matrix): a feature matrix-
373: treatment (np.array): a treatment vector-
374: y (np.array): an outcome vector-
375: size (int, optional): bootstrap sample size-
376:
-377: Returns:-
378: (np.array): bootstrap predictions-
379: """-
+380: idxs = np.random.choice(np.arange(0, X.shape[0]), size=size)-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_random); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_choice); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_arange); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_0, __pyx_t_5}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_0, __pyx_t_5}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_int_0); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_size, __pyx_v_size) < 0) __PYX_ERR(0, 380, __pyx_L1_error) - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_idxs = __pyx_t_7; - __pyx_t_7 = 0; -
+381: X_b = X[idxs]-
__pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_v_idxs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 381, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_v_X_b = __pyx_t_7; - __pyx_t_7 = 0; -
+382: treatment_b = treatment[idxs]-
__pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_treatment, __pyx_v_idxs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_v_treatment_b = __pyx_t_7; - __pyx_t_7 = 0; -
+383: y_b = y[idxs]-
__pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_y, __pyx_v_idxs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 383, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_v_y_b = __pyx_t_7; - __pyx_t_7 = 0; -
+384: self.fit(X=X_b, treatment=treatment_b, y=y_b)-
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fit); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 384, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 384, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_X, __pyx_v_X_b) < 0) __PYX_ERR(0, 384, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_treatment, __pyx_v_treatment_b) < 0) __PYX_ERR(0, 384, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_y, __pyx_v_y_b) < 0) __PYX_ERR(0, 384, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 384, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
+385: te_b = self.predict(X=X)-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_predict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_X, __pyx_v_X) < 0) __PYX_ERR(0, 385, __pyx_L1_error) - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_te_b = __pyx_t_7; - __pyx_t_7 = 0; -
+386: return te_b-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_te_b); - __pyx_r = __pyx_v_te_b; - goto __pyx_L0; -
387:
-+388: def estimate_ate(self, X, treatment, y):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_11estimate_ate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_10estimate_ate[] = "Estimate the Average Treatment Effect (ATE).\n\n Args:\n X (np.matrix): a feature matrix\n treatment (np.array): a treatment vector\n y (np.array): an outcome vector\n\n Returns:\n The mean and confidence interval (LB, UB) of the ATE estimate.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_11estimate_ate = {"estimate_ate", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_11estimate_ate, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_10estimate_ate}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_11estimate_ate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("estimate_ate (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_treatment,&__pyx_n_s_y,0}; - PyObject* values[4] = {0,0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("estimate_ate", 1, 4, 4, 1); __PYX_ERR(0, 388, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("estimate_ate", 1, 4, 4, 2); __PYX_ERR(0, 388, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("estimate_ate", 1, 4, 4, 3); __PYX_ERR(0, 388, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "estimate_ate") < 0)) __PYX_ERR(0, 388, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_treatment = values[2]; - __pyx_v_y = values[3]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("estimate_ate", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 388, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.estimate_ate", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_10estimate_ate(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_treatment, __pyx_v_y); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_10estimate_ate(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment, PyObject *__pyx_v_y) { - PyObject *__pyx_v_dhat = NULL; - PyObject *__pyx_v_te = NULL; - PyObject *__pyx_v_se = NULL; - PyObject *__pyx_v_te_lb = NULL; - PyObject *__pyx_v_te_ub = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("estimate_ate", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("causalml.inference.tree.causaltree.CausalTreeRegressor.estimate_ate", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_dhat); - __Pyx_XDECREF(__pyx_v_te); - __Pyx_XDECREF(__pyx_v_se); - __Pyx_XDECREF(__pyx_v_te_lb); - __Pyx_XDECREF(__pyx_v_te_ub); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__39 = PyTuple_Pack(9, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_treatment, __pyx_n_s_y, __pyx_n_s_dhat, __pyx_n_s_te, __pyx_n_s_se, __pyx_n_s_te_lb, __pyx_n_s_te_ub); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__39); - __Pyx_GIVEREF(__pyx_tuple__39); -/* … */ - __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_10causaltree_19CausalTreeRegressor_11estimate_ate, 0, __pyx_n_s_CausalTreeRegressor_estimate_ate, NULL, __pyx_n_s_causalml_inference_tree_causaltr, __pyx_d, ((PyObject *)__pyx_codeobj__40)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_estimate_ate, __pyx_t_1) < 0) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_codeobj__40 = (PyObject*)__Pyx_PyCode_New(4, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__39, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_causaltr_2, __pyx_n_s_estimate_ate, 388, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__40)) __PYX_ERR(0, 388, __pyx_L1_error) -
389: """Estimate the Average Treatment Effect (ATE).-
390:
-391: Args:-
392: X (np.matrix): a feature matrix-
393: treatment (np.array): a treatment vector-
394: y (np.array): an outcome vector-
395:
-396: Returns:-
397: The mean and confidence interval (LB, UB) of the ATE estimate.-
398: """-
+399: dhat = self.fit_predict(X, treatment, y)-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fit_predict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_4 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_4 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_X, __pyx_v_treatment, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_X, __pyx_v_treatment, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_5 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment); - __Pyx_GIVEREF(__pyx_v_treatment); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_treatment); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_y); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_dhat = __pyx_t_1; - __pyx_t_1 = 0; -
400:
-+401: te = dhat.mean()-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_dhat, __pyx_n_s_mean); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 401, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 401, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_te = __pyx_t_1; - __pyx_t_1 = 0; -
+402: se = dhat.std() / X.shape[0]-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_dhat, __pyx_n_s_std); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_se = __pyx_t_2; - __pyx_t_2 = 0; -
403:
-+404: te_lb = te - se * norm.ppf(1 - self.ate_alpha / 2)-
__Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_norm); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_ppf); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_ate_alpha); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_5, __pyx_int_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_t_3, 1, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Multiply(__pyx_v_se, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Subtract(__pyx_v_te, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_te_lb = __pyx_t_2; - __pyx_t_2 = 0; -
+405: te_ub = te + se * norm.ppf(1 - self.ate_alpha / 2)-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_norm); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_ppf); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_ate_alpha); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_int_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_t_3, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_3, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Multiply(__pyx_v_se, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Add(__pyx_v_te, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_te_ub = __pyx_t_2; - __pyx_t_2 = 0; -
406:
-+407: return te, te_lb, te_ub-
__Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_te); - __Pyx_GIVEREF(__pyx_v_te); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_te); - __Pyx_INCREF(__pyx_v_te_lb); - __Pyx_GIVEREF(__pyx_v_te_lb); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_te_lb); - __Pyx_INCREF(__pyx_v_te_ub); - __Pyx_GIVEREF(__pyx_v_te_ub); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_te_ub); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; -
Generated by Cython 0.29.24
-
- Yellow lines hint at Python interaction.
- Click on a line that starts with a "+
" to see the C code that Cython generated for it.
-
Raw output: uplift.c
-+0001: # cython: cdivision=True-
__pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
0002: # cython: boundscheck=False-
0003: # cython: wraparound=False-
0004: """-
0005: Forest of trees-based ensemble methods for Uplift modeling on Classification-
0006: Problem. Those methods include random forests and extremely randomized trees.-
0007:
-0008: The module structure is the following:-
0009: - The ``UpliftRandomForestClassifier`` base class implements different-
0010: variants of uplift models based on random forest, with 'fit' and 'predict'-
0011: method.-
0012: - The ``UpliftTreeClassifier`` base class implements the uplift trees (without-
0013: Bootstrapping for random forest), this class is called within-
0014: ``UpliftRandomForestClassifier`` for constructing random forest.-
0015: """-
0016:
-0017: # Authors: Zhenyu Zhao <zhenyuz@uber.com>-
0018: # Totte Harinen <totte@uber.com>-
0019:
-+0020: from collections import defaultdict-
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_defaultdict); - __Pyx_GIVEREF(__pyx_n_s_defaultdict); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_defaultdict); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_collections, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_defaultdict, __pyx_t_1) < 0) __PYX_ERR(0, 20, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
0021: import cython-
+0022: from joblib import Parallel, delayed-
__pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_Parallel); - __Pyx_GIVEREF(__pyx_n_s_Parallel); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Parallel); - __Pyx_INCREF(__pyx_n_s_delayed); - __Pyx_GIVEREF(__pyx_n_s_delayed); - PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_delayed); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_joblib, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_Parallel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_Parallel, __pyx_t_2) < 0) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_delayed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_delayed, __pyx_t_2) < 0) __PYX_ERR(0, 22, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0023: import multiprocessing as mp-
__pyx_t_1 = __Pyx_Import(__pyx_n_s_multiprocessing, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_mp, __pyx_t_1) < 0) __PYX_ERR(0, 23, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
0024: cimport numpy as np-
+0025: import numpy as np-
__pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 25, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0026: from packaging import version-
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_version); - __Pyx_GIVEREF(__pyx_n_s_version); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_version); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_packaging, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_version); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_version, __pyx_t_1) < 0) __PYX_ERR(0, 26, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0027: import pandas as pd-
__pyx_t_2 = __Pyx_Import(__pyx_n_s_pandas, 0, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pd, __pyx_t_2) < 0) __PYX_ERR(0, 27, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0028: import scipy.stats as stats-
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 28, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s__14); - __Pyx_GIVEREF(__pyx_n_s__14); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s__14); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_scipy_stats, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_stats, __pyx_t_1) < 0) __PYX_ERR(0, 28, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0029: import sklearn-
__pyx_t_1 = __Pyx_Import(__pyx_n_s_sklearn, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 29, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_sklearn, __pyx_t_1) < 0) __PYX_ERR(0, 29, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0030: from sklearn.utils import check_array, check_random_state, check_X_y-
__pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_check_array); - __Pyx_GIVEREF(__pyx_n_s_check_array); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_check_array); - __Pyx_INCREF(__pyx_n_s_check_random_state); - __Pyx_GIVEREF(__pyx_n_s_check_random_state); - PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_check_random_state); - __Pyx_INCREF(__pyx_n_s_check_X_y); - __Pyx_GIVEREF(__pyx_n_s_check_X_y); - PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_check_X_y); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_sklearn_utils, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_check_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_check_array, __pyx_t_1) < 0) __PYX_ERR(0, 30, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_check_random_state); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_check_random_state, __pyx_t_1) < 0) __PYX_ERR(0, 30, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_check_X_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_check_X_y, __pyx_t_1) < 0) __PYX_ERR(0, 30, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0031: from typing import List-
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_List); - __Pyx_GIVEREF(__pyx_n_s_List); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_List); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_typing, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_List); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_List, __pyx_t_2) < 0) __PYX_ERR(0, 31, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0032: if version.parse(sklearn.__version__) >= version.parse('0.22.0'):-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_version); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_parse); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_sklearn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_version_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_version); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_parse); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_4) { -/* … */ - goto __pyx_L2; - } -/* … */ - __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_0_22_0); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 32, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__15); - __Pyx_GIVEREF(__pyx_tuple__15); -
+0033: from sklearn.utils._testing import ignore_warnings-
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 33, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_ignore_warnings); - __Pyx_GIVEREF(__pyx_n_s_ignore_warnings); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_ignore_warnings); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_sklearn_utils__testing, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 33, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_ignore_warnings); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 33, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_ignore_warnings, __pyx_t_2) < 0) __PYX_ERR(0, 33, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -
0034: else:-
+0035: from sklearn.utils.testing import ignore_warnings-
/*else*/ { - __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 35, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_n_s_ignore_warnings); - __Pyx_GIVEREF(__pyx_n_s_ignore_warnings); - PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_ignore_warnings); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_sklearn_utils_testing, __pyx_t_3, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_ignore_warnings); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 35, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_ignore_warnings, __pyx_t_3) < 0) __PYX_ERR(0, 35, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_L2:; -
0036:
- 0037:
-+0038: MAX_INT = np.iinfo(np.int32).max-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 38, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_iinfo); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 38, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 38, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int32); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 38, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_max); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_MAX_INT, __pyx_t_1) < 0) __PYX_ERR(0, 38, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
0039:
- 0040:
-0041: cdef extern from "math.h":-
0042: double log(double x) nogil-
0043:
- 0044:
-0045: @cython.cfunc-
+0046: def kl_divergence(pk: cython.float, qk: cython.float) -> cython.float:-
static float __pyx_f_8causalml_9inference_4tree_6uplift_kl_divergence(float __pyx_v_pk, float __pyx_v_qk) { - float __pyx_v_eps; - float __pyx_v_S; - float __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("kl_divergence", 0); -/* … */ - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -
0047: '''-
0048: Calculate KL Divergence for binary classification.-
0049:
-0050: sum(np.array(pk) * np.log(np.array(pk) / np.array(qk)))-
0051:
-0052: Args-
0053: -----
0054: pk : float-
0055: The probability of 1 in one distribution.-
0056: qk : float-
0057: The probability of 1 in the other distribution.-
0058:
-0059: Returns-
0060: --------
0061: S : float-
0062: The KL divergence.-
0063: '''-
0064:
-+0065: eps: cython.float = 1e-6-
__pyx_v_eps = 1e-6; -
0066: S: cython.float-
0067:
-+0068: if qk == 0.:-
__pyx_t_1 = ((__pyx_v_qk == 0.) != 0); - if (__pyx_t_1) { -/* … */ - } -
+0069: return 0.-
__pyx_r = 0.; - goto __pyx_L0; -
0070:
-+0071: qk = min(max(qk, eps), 1 - eps)-
__pyx_t_2 = (1.0 - __pyx_v_eps); - __pyx_t_3 = __pyx_v_eps; - __pyx_t_4 = __pyx_v_qk; - if (((__pyx_t_3 > __pyx_t_4) != 0)) { - __pyx_t_5 = __pyx_t_3; - } else { - __pyx_t_5 = __pyx_t_4; - } - __pyx_t_3 = __pyx_t_5; - if (((__pyx_t_2 < __pyx_t_3) != 0)) { - __pyx_t_5 = __pyx_t_2; - } else { - __pyx_t_5 = __pyx_t_3; - } - __pyx_v_qk = __pyx_t_5; -
0072:
-+0073: if pk == 0.:-
__pyx_t_1 = ((__pyx_v_pk == 0.) != 0); - if (__pyx_t_1) { -/* … */ - goto __pyx_L4; - } -
+0074: S = -log(1 - qk)-
__pyx_v_S = (-log((1.0 - __pyx_v_qk))); -
+0075: elif pk == 1.:-
__pyx_t_1 = ((__pyx_v_pk == 1.) != 0); - if (__pyx_t_1) { -/* … */ - goto __pyx_L4; - } -
+0076: S = -log(qk)-
__pyx_v_S = (-log(__pyx_v_qk)); -
0077: else:-
+0078: S = pk * log(pk / qk) + (1 - pk) * log((1 - pk) / (1 - qk))-
/*else*/ { - __pyx_v_S = ((__pyx_v_pk * log((__pyx_v_pk / __pyx_v_qk))) + ((1.0 - __pyx_v_pk) * log(((1.0 - __pyx_v_pk) / (1.0 - __pyx_v_qk))))); - } - __pyx_L4:; -
0079:
-+0080: return S-
__pyx_r = __pyx_v_S; - goto __pyx_L0; -
0081:
- 0082:
-0083: @cython.cfunc-
+0084: def entropyH(p: cython.float, q: cython.float=-1.) -> cython.float:-
static float __pyx_f_8causalml_9inference_4tree_6uplift_entropyH(float __pyx_v_p, struct __pyx_opt_args_8causalml_9inference_4tree_6uplift_entropyH *__pyx_optional_args) { - float __pyx_v_q = __pyx_k_; - float __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("entropyH", 0); - if (__pyx_optional_args) { - if (__pyx_optional_args->__pyx_n > 0) { - __pyx_v_q = __pyx_optional_args->q; - } - } -/* … */ - /* function exit code */ - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_k_ = (-1.); -/* … */ -struct __pyx_opt_args_8causalml_9inference_4tree_6uplift_entropyH { - int __pyx_n; - float q; -}; -
0085: '''-
0086: Entropy-
0087:
-0088: Entropy calculation for normalization.-
0089:
-0090: Args-
0091: -----
0092: p : float-
0093: The probability used in the entropy calculation.-
0094:
-0095: q : float, optional, (default = -1.)-
0096: The second probability used in the entropy calculation.-
0097:
-0098: Returns-
0099: --------
0100: entropy : float-
0101: '''-
0102:
-+0103: if q == -1. and p > 0.:-
__pyx_t_2 = ((__pyx_v_q == -1.) != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_p > 0.) != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L4_bool_binop_done:; - if (__pyx_t_1) { -/* … */ - } -
+0104: return -p * log(p)-
__pyx_r = ((-__pyx_v_p) * log(__pyx_v_p)); - goto __pyx_L0; -
+0105: elif q > 0.:-
__pyx_t_1 = ((__pyx_v_q > 0.) != 0); - if (__pyx_t_1) { -/* … */ - } -
+0106: return -p * log(q)-
__pyx_r = ((-__pyx_v_p) * log(__pyx_v_q)); - goto __pyx_L0; -
0107: else:-
+0108: return 0.-
/*else*/ { - __pyx_r = 0.; - goto __pyx_L0; - } -
0109:
- 0110:
-+0111: class DecisionTree:-
__pyx_t_1 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_empty_tuple, __pyx_n_s_DecisionTree, __pyx_n_s_DecisionTree, (PyObject *) NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_kp_s_Tree_Node_Class_Tree_node_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 111, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); -/* … */ - __pyx_t_2 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_n_s_DecisionTree, __pyx_empty_tuple, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 111, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_DecisionTree, __pyx_t_2) < 0) __PYX_ERR(0, 111, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
0112: """ Tree Node Class-
0113:
-0114: Tree node class to contain all the statistics of the tree node.-
0115:
-0116: Parameters-
0117: -----------
0118: classes_ : list of str-
0119: A list of the control and treatment group names.-
0120:
-0121: col : int, optional (default = -1)-
0122: The column index for splitting the tree node to children nodes.-
0123:
-0124: value : float, optional (default = None)-
0125: The value of the feature column to split the tree node to children nodes.-
0126:
-0127: trueBranch : object of DecisionTree-
0128: The true branch tree node (feature > value).-
0129:
-0130: falseBranch : object of DecisionTree-
0131: The false branch tree node (feature > value).-
0132:
-0133: results : list of float-
0134: The classification probability P(Y=1|T) for each of the control and treatment groups-
0135: in the tree node.-
0136:
-0137: summary : list of list-
0138: Summary statistics of the tree nodes, including impurity, sample size, uplift score, etc.-
0139:
-0140: maxDiffTreatment : int-
0141: The treatment index generating the maximum difference between the treatment and control groups.-
0142:
-0143: maxDiffSign : float-
0144: The sign of the maximum difference (1. or -1.).-
0145:
-0146: nodeSummary : list of list-
0147: Summary statistics of the tree nodes [P(Y=1|T), N(T)], where y_mean stands for the target metric mean-
0148: and n is the sample size.-
0149:
-0150: backupResults : list of float-
0151: The positive probabilities in each of the control and treatment groups in the parent node. The parent node-
0152: information is served as a backup for the children node, in case no valid statistics can be calculated from the-
0153: children node, the parent node information will be used in certain cases.-
0154:
-0155: bestTreatment : int-
0156: The treatment index providing the best uplift (treatment effect).-
0157:
-0158: upliftScore : list-
0159: The uplift score of this node: [max_Diff, p_value], where max_Diff stands for the maximum treatment effect, and-
0160: p_value stands for the p_value of the treatment effect.-
0161:
-0162: matchScore : float-
0163: The uplift score by filling a trained tree with validation dataset or testing dataset.-
0164:
-0165: """-
0166:
-+0167: def __init__(self, classes_, col=-1, value=None, trueBranch=None, falseBranch=None, results=None, summary=None,-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_12DecisionTree_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_12DecisionTree_1__init__ = {"__init__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_12DecisionTree_1__init__, METH_VARARGS|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_12DecisionTree_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_classes_ = 0; - PyObject *__pyx_v_col = 0; - PyObject *__pyx_v_value = 0; - PyObject *__pyx_v_trueBranch = 0; - PyObject *__pyx_v_falseBranch = 0; - PyObject *__pyx_v_results = 0; - PyObject *__pyx_v_summary = 0; - PyObject *__pyx_v_maxDiffTreatment = 0; - PyObject *__pyx_v_maxDiffSign = 0; - PyObject *__pyx_v_nodeSummary = 0; - PyObject *__pyx_v_backupResults = 0; - PyObject *__pyx_v_bestTreatment = 0; - PyObject *__pyx_v_upliftScore = 0; - PyObject *__pyx_v_matchScore = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_classes,&__pyx_n_s_col,&__pyx_n_s_value,&__pyx_n_s_trueBranch,&__pyx_n_s_falseBranch,&__pyx_n_s_results,&__pyx_n_s_summary,&__pyx_n_s_maxDiffTreatment,&__pyx_n_s_maxDiffSign,&__pyx_n_s_nodeSummary,&__pyx_n_s_backupResults,&__pyx_n_s_bestTreatment,&__pyx_n_s_upliftScore,&__pyx_n_s_matchScore,0}; - PyObject* values[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - values[2] = ((PyObject *)((PyObject *)__pyx_int_neg_1)); - values[3] = ((PyObject *)((PyObject *)Py_None)); - values[4] = ((PyObject *)((PyObject *)Py_None)); - values[5] = ((PyObject *)((PyObject *)Py_None)); - values[6] = ((PyObject *)((PyObject *)Py_None)); - values[7] = ((PyObject *)((PyObject *)Py_None)); -/* … */ - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_12DecisionTree___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_classes_, PyObject *__pyx_v_col, PyObject *__pyx_v_value, PyObject *__pyx_v_trueBranch, PyObject *__pyx_v_falseBranch, PyObject *__pyx_v_results, PyObject *__pyx_v_summary, PyObject *__pyx_v_maxDiffTreatment, PyObject *__pyx_v_maxDiffSign, PyObject *__pyx_v_nodeSummary, PyObject *__pyx_v_backupResults, PyObject *__pyx_v_bestTreatment, PyObject *__pyx_v_upliftScore, PyObject *__pyx_v_matchScore) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__", 0); -/* … */ - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.DecisionTree.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__16 = PyTuple_Pack(15, __pyx_n_s_self, __pyx_n_s_classes, __pyx_n_s_col, __pyx_n_s_value, __pyx_n_s_trueBranch, __pyx_n_s_falseBranch, __pyx_n_s_results, __pyx_n_s_summary, __pyx_n_s_maxDiffTreatment, __pyx_n_s_maxDiffSign, __pyx_n_s_nodeSummary, __pyx_n_s_backupResults, __pyx_n_s_bestTreatment, __pyx_n_s_upliftScore, __pyx_n_s_matchScore); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 167, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__16); - __Pyx_GIVEREF(__pyx_tuple__16); - __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(15, 0, 15, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_init, 167, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 167, __pyx_L1_error) -/* … */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_12DecisionTree_1__init__, 0, __pyx_n_s_DecisionTree___init, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__17)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 167, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_tuple__18); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_init, __pyx_t_2) < 0) __PYX_ERR(0, 167, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_tuple__18 = PyTuple_Pack(13, ((PyObject *)__pyx_int_neg_1), ((PyObject *)Py_None), ((PyObject *)Py_None), ((PyObject *)Py_None), ((PyObject *)Py_None), ((PyObject *)Py_None), ((PyObject *)Py_None), ((PyObject*)__pyx_float_1_), ((PyObject *)Py_None), ((PyObject *)Py_None), ((PyObject *)Py_None), ((PyObject *)Py_None), ((PyObject *)Py_None)); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 167, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__18); - __Pyx_GIVEREF(__pyx_tuple__18); -
+0168: maxDiffTreatment=None, maxDiffSign=1., nodeSummary=None, backupResults=None, bestTreatment=None,-
values[8] = ((PyObject *)((PyObject *)Py_None)); - values[9] = ((PyObject *)((PyObject*)__pyx_float_1_)); - values[10] = ((PyObject *)((PyObject *)Py_None)); - values[11] = ((PyObject *)((PyObject *)Py_None)); - values[12] = ((PyObject *)((PyObject *)Py_None)); -
+0169: upliftScore=None, matchScore=None):-
values[13] = ((PyObject *)((PyObject *)Py_None)); - values[14] = ((PyObject *)((PyObject *)Py_None)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); - CYTHON_FALLTHROUGH; - case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); - CYTHON_FALLTHROUGH; - case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); - CYTHON_FALLTHROUGH; - case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); - CYTHON_FALLTHROUGH; - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - CYTHON_FALLTHROUGH; - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - CYTHON_FALLTHROUGH; - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_classes)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 15, 1); __PYX_ERR(0, 167, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_col); - if (value) { values[2] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value); - if (value) { values[3] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_trueBranch); - if (value) { values[4] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_falseBranch); - if (value) { values[5] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 6: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_results); - if (value) { values[6] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 7: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_summary); - if (value) { values[7] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 8: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_maxDiffTreatment); - if (value) { values[8] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 9: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_maxDiffSign); - if (value) { values[9] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 10: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nodeSummary); - if (value) { values[10] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 11: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_backupResults); - if (value) { values[11] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 12: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bestTreatment); - if (value) { values[12] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 13: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_upliftScore); - if (value) { values[13] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 14: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_matchScore); - if (value) { values[14] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 167, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); - CYTHON_FALLTHROUGH; - case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); - CYTHON_FALLTHROUGH; - case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); - CYTHON_FALLTHROUGH; - case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); - CYTHON_FALLTHROUGH; - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - CYTHON_FALLTHROUGH; - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - CYTHON_FALLTHROUGH; - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_classes_ = values[1]; - __pyx_v_col = values[2]; - __pyx_v_value = values[3]; - __pyx_v_trueBranch = values[4]; - __pyx_v_falseBranch = values[5]; - __pyx_v_results = values[6]; - __pyx_v_summary = values[7]; - __pyx_v_maxDiffTreatment = values[8]; - __pyx_v_maxDiffSign = values[9]; - __pyx_v_nodeSummary = values[10]; - __pyx_v_backupResults = values[11]; - __pyx_v_bestTreatment = values[12]; - __pyx_v_upliftScore = values[13]; - __pyx_v_matchScore = values[14]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 15, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 167, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.DecisionTree.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_12DecisionTree___init__(__pyx_self, __pyx_v_self, __pyx_v_classes_, __pyx_v_col, __pyx_v_value, __pyx_v_trueBranch, __pyx_v_falseBranch, __pyx_v_results, __pyx_v_summary, __pyx_v_maxDiffTreatment, __pyx_v_maxDiffSign, __pyx_v_nodeSummary, __pyx_v_backupResults, __pyx_v_bestTreatment, __pyx_v_upliftScore, __pyx_v_matchScore); -
+0170: self.classes_ = classes_-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_classes, __pyx_v_classes_) < 0) __PYX_ERR(0, 170, __pyx_L1_error) -
+0171: self.col = col-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_col, __pyx_v_col) < 0) __PYX_ERR(0, 171, __pyx_L1_error) -
+0172: self.value = value-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_value, __pyx_v_value) < 0) __PYX_ERR(0, 172, __pyx_L1_error) -
+0173: self.trueBranch = trueBranch-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_trueBranch, __pyx_v_trueBranch) < 0) __PYX_ERR(0, 173, __pyx_L1_error) -
+0174: self.falseBranch = falseBranch-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_falseBranch, __pyx_v_falseBranch) < 0) __PYX_ERR(0, 174, __pyx_L1_error) -
+0175: self.results = results # None for nodes, not None for leaves-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_results, __pyx_v_results) < 0) __PYX_ERR(0, 175, __pyx_L1_error) -
+0176: self.summary = summary-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_summary, __pyx_v_summary) < 0) __PYX_ERR(0, 176, __pyx_L1_error) -
0177: # the treatment with max( |p(y|treatment) - p(y|control)| )-
+0178: self.maxDiffTreatment = maxDiffTreatment-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_maxDiffTreatment, __pyx_v_maxDiffTreatment) < 0) __PYX_ERR(0, 178, __pyx_L1_error) -
0179: # the sign for p(y|maxDiffTreatment) - p(y|control)-
+0180: self.maxDiffSign = maxDiffSign-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_maxDiffSign, __pyx_v_maxDiffSign) < 0) __PYX_ERR(0, 180, __pyx_L1_error) -
+0181: self.nodeSummary = nodeSummary-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_nodeSummary, __pyx_v_nodeSummary) < 0) __PYX_ERR(0, 181, __pyx_L1_error) -
+0182: self.backupResults = backupResults-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_backupResults, __pyx_v_backupResults) < 0) __PYX_ERR(0, 182, __pyx_L1_error) -
+0183: self.bestTreatment = bestTreatment-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_bestTreatment, __pyx_v_bestTreatment) < 0) __PYX_ERR(0, 183, __pyx_L1_error) -
+0184: self.upliftScore = upliftScore-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_upliftScore, __pyx_v_upliftScore) < 0) __PYX_ERR(0, 184, __pyx_L1_error) -
0185: # match actual treatment for validation and testing-
+0186: self.matchScore = matchScore-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_matchScore, __pyx_v_matchScore) < 0) __PYX_ERR(0, 186, __pyx_L1_error) -
0187:
- 0188:
-0189: # Uplift Tree Classifier-
+0190: class UpliftTreeClassifier:-
__pyx_t_1 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_empty_tuple, __pyx_n_s_UpliftTreeClassifier, __pyx_n_s_UpliftTreeClassifier, (PyObject *) NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_kp_s_Uplift_Tree_Classifier_for_Clas); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 190, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); -/* … */ - __pyx_t_2 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_n_s_UpliftTreeClassifier, __pyx_empty_tuple, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 190, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_UpliftTreeClassifier, __pyx_t_2) < 0) __PYX_ERR(0, 190, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
0191: """ Uplift Tree Classifier for Classification Task.-
0192:
-0193: A uplift tree classifier estimates the individual treatment effect by modifying the loss function in the-
0194: classification trees.-
0195:
-0196: The uplift tree classifier is used in uplift random forest to construct the trees in the forest.-
0197:
-0198: Parameters-
0199: -----------
0200:
-0201: evaluationFunction : string-
0202: Choose from one of the models: 'KL', 'ED', 'Chi', 'CTS', 'DDP'.-
0203:
-0204: max_features: int, optional (default=None)-
0205: The number of features to consider when looking for the best split.-
0206:
-0207: max_depth: int, optional (default=3)-
0208: The maximum depth of the tree.-
0209:
-0210: min_samples_leaf: int, optional (default=100)-
0211: The minimum number of samples required to be split at a leaf node.-
0212:
-0213: min_samples_treatment: int, optional (default=10)-
0214: The minimum number of samples required of the experiment group to be split at a leaf node.-
0215:
-0216: n_reg: int, optional (default=100)-
0217: The regularization parameter defined in Rzepakowski et al. 2012, the weight (in terms of sample size) of the-
0218: parent node influence on the child node, only effective for 'KL', 'ED', 'Chi', 'CTS' methods.-
0219:
-0220: control_name: string-
0221: The name of the control group (other experiment groups will be regarded as treatment groups).-
0222:
-0223: normalization: boolean, optional (default=True)-
0224: The normalization factor defined in Rzepakowski et al. 2012, correcting for tests with large number of splits-
0225: and imbalanced treatment and control splits.-
0226:
-0227: random_state: int, RandomState instance or None (default=None)-
0228: A random seed or `np.random.RandomState` to control randomness in building a tree.-
0229:
-0230: """-
+0231: def __init__(self, control_name, max_features=None, max_depth=3, min_samples_leaf=100,-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_1__init__ = {"__init__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_1__init__, METH_VARARGS|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_control_name = 0; - PyObject *__pyx_v_max_features = 0; - PyObject *__pyx_v_max_depth = 0; - PyObject *__pyx_v_min_samples_leaf = 0; - PyObject *__pyx_v_min_samples_treatment = 0; - PyObject *__pyx_v_n_reg = 0; - PyObject *__pyx_v_evaluationFunction = 0; - PyObject *__pyx_v_normalization = 0; - PyObject *__pyx_v_random_state = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_control_name,&__pyx_n_s_max_features,&__pyx_n_s_max_depth,&__pyx_n_s_min_samples_leaf,&__pyx_n_s_min_samples_treatment,&__pyx_n_s_n_reg,&__pyx_n_s_evaluationFunction,&__pyx_n_s_normalization,&__pyx_n_s_random_state,0}; - PyObject* values[10] = {0,0,0,0,0,0,0,0,0,0}; - values[2] = ((PyObject *)((PyObject *)Py_None)); - values[3] = ((PyObject *)((PyObject *)__pyx_int_3)); - values[4] = ((PyObject *)((PyObject *)__pyx_int_100)); - values[5] = ((PyObject *)((PyObject *)__pyx_int_10)); - values[6] = ((PyObject *)((PyObject *)__pyx_int_100)); - values[7] = ((PyObject *)((PyObject*)__pyx_n_s_KL)); -/* … */ - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_control_name, PyObject *__pyx_v_max_features, PyObject *__pyx_v_max_depth, PyObject *__pyx_v_min_samples_leaf, PyObject *__pyx_v_min_samples_treatment, PyObject *__pyx_v_n_reg, PyObject *__pyx_v_evaluationFunction, PyObject *__pyx_v_normalization, PyObject *__pyx_v_random_state) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__", 0); -/* … */ - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__19 = PyTuple_Pack(10, __pyx_n_s_self, __pyx_n_s_control_name, __pyx_n_s_max_features, __pyx_n_s_max_depth, __pyx_n_s_min_samples_leaf, __pyx_n_s_min_samples_treatment, __pyx_n_s_n_reg, __pyx_n_s_evaluationFunction, __pyx_n_s_normalization, __pyx_n_s_random_state); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 231, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__19); - __Pyx_GIVEREF(__pyx_tuple__19); - __pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(10, 0, 10, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_init, 231, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) __PYX_ERR(0, 231, __pyx_L1_error) -/* … */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_1__init__, 0, __pyx_n_s_UpliftTreeClassifier___init, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__20)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 231, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_tuple__21); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_init, __pyx_t_2) < 0) __PYX_ERR(0, 231, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_tuple__21 = PyTuple_Pack(8, ((PyObject *)Py_None), ((PyObject *)__pyx_int_3), ((PyObject *)__pyx_int_100), ((PyObject *)__pyx_int_10), ((PyObject *)__pyx_int_100), ((PyObject*)__pyx_n_s_KL), ((PyObject *)Py_True), ((PyObject *)Py_None)); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 231, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); -
0232: min_samples_treatment=10, n_reg=100, evaluationFunction='KL',-
+0233: normalization=True, random_state=None):-
values[8] = ((PyObject *)((PyObject *)Py_True)); - values[9] = ((PyObject *)((PyObject *)Py_None)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - CYTHON_FALLTHROUGH; - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_control_name)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 10, 1); __PYX_ERR(0, 231, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_features); - if (value) { values[2] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_depth); - if (value) { values[3] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_samples_leaf); - if (value) { values[4] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_samples_treatment); - if (value) { values[5] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 6: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_reg); - if (value) { values[6] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 7: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_evaluationFunction); - if (value) { values[7] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 8: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_normalization); - if (value) { values[8] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 9: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_random_state); - if (value) { values[9] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 231, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - CYTHON_FALLTHROUGH; - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_control_name = values[1]; - __pyx_v_max_features = values[2]; - __pyx_v_max_depth = values[3]; - __pyx_v_min_samples_leaf = values[4]; - __pyx_v_min_samples_treatment = values[5]; - __pyx_v_n_reg = values[6]; - __pyx_v_evaluationFunction = values[7]; - __pyx_v_normalization = values[8]; - __pyx_v_random_state = values[9]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 10, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 231, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier___init__(__pyx_self, __pyx_v_self, __pyx_v_control_name, __pyx_v_max_features, __pyx_v_max_depth, __pyx_v_min_samples_leaf, __pyx_v_min_samples_treatment, __pyx_v_n_reg, __pyx_v_evaluationFunction, __pyx_v_normalization, __pyx_v_random_state); -
+0234: self.max_depth = max_depth-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_max_depth, __pyx_v_max_depth) < 0) __PYX_ERR(0, 234, __pyx_L1_error) -
+0235: self.min_samples_leaf = min_samples_leaf-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_leaf, __pyx_v_min_samples_leaf) < 0) __PYX_ERR(0, 235, __pyx_L1_error) -
+0236: self.min_samples_treatment = min_samples_treatment-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_treatment, __pyx_v_min_samples_treatment) < 0) __PYX_ERR(0, 236, __pyx_L1_error) -
+0237: self.n_reg = n_reg-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 237, __pyx_L1_error) -
+0238: self.max_features = max_features-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_max_features, __pyx_v_max_features) < 0) __PYX_ERR(0, 238, __pyx_L1_error) -
+0239: if evaluationFunction == 'KL':-
__pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_evaluationFunction, __pyx_n_s_KL, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 239, __pyx_L1_error) - if (__pyx_t_1) { -/* … */ - goto __pyx_L3; - } -
+0240: self.evaluationFunction = self.evaluate_KL-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluate_KL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction, __pyx_t_2) < 0) __PYX_ERR(0, 240, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0241: elif evaluationFunction == 'ED':-
__pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_evaluationFunction, __pyx_n_s_ED, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 241, __pyx_L1_error) - if (__pyx_t_1) { -/* … */ - goto __pyx_L3; - } -
+0242: self.evaluationFunction = self.evaluate_ED-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluate_ED); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 242, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction, __pyx_t_2) < 0) __PYX_ERR(0, 242, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0243: elif evaluationFunction == 'Chi':-
__pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_evaluationFunction, __pyx_n_s_Chi, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 243, __pyx_L1_error) - if (__pyx_t_1) { -/* … */ - goto __pyx_L3; - } -
+0244: self.evaluationFunction = self.evaluate_Chi-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluate_Chi); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 244, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction, __pyx_t_2) < 0) __PYX_ERR(0, 244, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0245: elif evaluationFunction == 'DDP':-
__pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_evaluationFunction, __pyx_n_s_DDP, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 245, __pyx_L1_error) - if (__pyx_t_1) { -/* … */ - goto __pyx_L3; - } -
+0246: self.evaluationFunction = self.evaluate_DDP-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluate_DDP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction, __pyx_t_2) < 0) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
0247: else:-
+0248: self.evaluationFunction = self.evaluate_CTS-
/*else*/ { - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluate_CTS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 248, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction, __pyx_t_2) < 0) __PYX_ERR(0, 248, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_L3:; -
+0249: self.fitted_uplift_tree = None-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_fitted_uplift_tree, Py_None) < 0) __PYX_ERR(0, 249, __pyx_L1_error) -
0250:
-+0251: assert control_name is not None and isinstance(control_name, str), \-
#ifndef CYTHON_WITHOUT_ASSERTIONS
- if (unlikely(!Py_OptimizeFlag)) {
- __pyx_t_3 = (__pyx_v_control_name != Py_None);
- __pyx_t_4 = (__pyx_t_3 != 0);
- if (__pyx_t_4) {
- } else {
- __pyx_t_1 = __pyx_t_4;
- goto __pyx_L4_bool_binop_done;
- }
- __pyx_t_4 = PyString_Check(__pyx_v_control_name);
- __pyx_t_3 = (__pyx_t_4 != 0);
- __pyx_t_1 = __pyx_t_3;
- __pyx_L4_bool_binop_done:;
- if (unlikely(!__pyx_t_1)) {
-
+0252: f"control_group should be string but {control_name} is passed"-
__pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = 0; - __pyx_t_6 = 127; - __Pyx_INCREF(__pyx_kp_u_control_group_should_be_string_b); - __pyx_t_5 += 35; - __Pyx_GIVEREF(__pyx_kp_u_control_group_should_be_string_b); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_control_group_should_be_string_b); - __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_v_control_name, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6; - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_is_passed); - __pyx_t_5 += 10; - __Pyx_GIVEREF(__pyx_kp_u_is_passed); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_is_passed); - __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_2, 3, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - PyErr_SetObject(PyExc_AssertionError, __pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __PYX_ERR(0, 251, __pyx_L1_error) - } - } - #endif -
+0253: self.control_name = control_name-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_control_name, __pyx_v_control_name) < 0) __PYX_ERR(0, 253, __pyx_L1_error) -
+0254: self.classes_ = [self.control_name]-
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_7); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_7); - __pyx_t_7 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_classes, __pyx_t_2) < 0) __PYX_ERR(0, 254, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0255: self.n_class = 1-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_n_class, __pyx_int_1) < 0) __PYX_ERR(0, 255, __pyx_L1_error) -
0256:
-+0257: self.normalization = normalization-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_normalization, __pyx_v_normalization) < 0) __PYX_ERR(0, 257, __pyx_L1_error) -
+0258: self.random_state = random_state-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_random_state, __pyx_v_random_state) < 0) __PYX_ERR(0, 258, __pyx_L1_error) -
0259:
-+0260: def fit(self, X, treatment, y):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_3fit(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_2fit[] = " Fit the uplift model.\n\n Args\n ----\n X : ndarray, shape = [num_samples, num_features]\n An ndarray of the covariates used to train the uplift model.\n\n treatment : array-like, shape = [num_samples]\n An array containing the treatment group for each unit.\n\n y : array-like, shape = [num_samples]\n An array containing the outcome of interest for each unit.\n\n Returns\n -------\n self : object\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_3fit = {"fit", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_3fit, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_2fit}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_3fit(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fit (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_treatment,&__pyx_n_s_y,0}; - PyObject* values[4] = {0,0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 1); __PYX_ERR(0, 260, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 2); __PYX_ERR(0, 260, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 3); __PYX_ERR(0, 260, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fit") < 0)) __PYX_ERR(0, 260, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_treatment = values[2]; - __pyx_v_y = values[3]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 260, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.fit", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_2fit(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_treatment, __pyx_v_y); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_2fit(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment, PyObject *__pyx_v_y) { - PyObject *__pyx_v_treatment_groups = NULL; - PyObject *__pyx_v_treatment_idx = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_tr = NULL; - PyObject *__pyx_v_col = NULL; - PyObject *__pyx_v_imp = NULL; - PyObject *__pyx_v_x = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fit", 0); - __Pyx_INCREF(__pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment); - __Pyx_INCREF(__pyx_v_y); -/* … */ - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.fit", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_treatment_groups); - __Pyx_XDECREF(__pyx_v_treatment_idx); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_tr); - __Pyx_XDECREF(__pyx_v_col); - __Pyx_XDECREF(__pyx_v_imp); - __Pyx_XDECREF(__pyx_v_x); - __Pyx_XDECREF(__pyx_v_X); - __Pyx_XDECREF(__pyx_v_treatment); - __Pyx_XDECREF(__pyx_v_y); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__22 = PyTuple_Pack(11, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_treatment, __pyx_n_s_y, __pyx_n_s_treatment_groups, __pyx_n_s_treatment_idx, __pyx_n_s_i, __pyx_n_s_tr, __pyx_n_s_col, __pyx_n_s_imp, __pyx_n_s_x); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 260, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__22); - __Pyx_GIVEREF(__pyx_tuple__22); -/* … */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_3fit, 0, __pyx_n_s_UpliftTreeClassifier_fit, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__23)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 260, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_fit, __pyx_t_2) < 0) __PYX_ERR(0, 260, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(4, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_fit, 260, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 260, __pyx_L1_error) -
0261: """ Fit the uplift model.-
0262:
-0263: Args-
0264: -----
0265: X : ndarray, shape = [num_samples, num_features]-
0266: An ndarray of the covariates used to train the uplift model.-
0267:
-0268: treatment : array-like, shape = [num_samples]-
0269: An array containing the treatment group for each unit.-
0270:
-0271: y : array-like, shape = [num_samples]-
0272: An array containing the outcome of interest for each unit.-
0273:
-0274: Returns-
0275: --------
0276: self : object-
0277: """-
0278:
-+0279: self.random_state_ = check_random_state(self.random_state)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_check_random_state); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 279, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_random_state); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 279, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 279, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_random_state_2, __pyx_t_1) < 0) __PYX_ERR(0, 279, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
0280:
-+0281: X, y = check_X_y(X, y)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_check_X_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_X, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_X, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_5, __pyx_v_X); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_5, __pyx_v_y); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 281, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_4 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - #else - __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_4)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_3), 2) < 0) __PYX_ERR(0, 281, __pyx_L1_error) - __pyx_t_6 = NULL; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L4_unpacking_done; - __pyx_L3_unpacking_failed:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 281, __pyx_L1_error) - __pyx_L4_unpacking_done:; - } - __Pyx_DECREF_SET(__pyx_v_X, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_y, __pyx_t_4); - __pyx_t_4 = 0; -
+0282: treatment = np.asarray(treatment)-
__Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 282, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_asarray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v_treatment) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_treatment); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_treatment, __pyx_t_1); - __pyx_t_1 = 0; -
+0283: assert len(y) == len(treatment), 'Data length must be equal for X, treatment, and y.'-
#ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - __pyx_t_7 = PyObject_Length(__pyx_v_y); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 283, __pyx_L1_error) - __pyx_t_8 = PyObject_Length(__pyx_v_treatment); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 283, __pyx_L1_error) - if (unlikely(!((__pyx_t_7 == __pyx_t_8) != 0))) { - PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_Data_length_must_be_equal_for_X); - __PYX_ERR(0, 283, __pyx_L1_error) - } - } - #endif -
0284:
-0285: # Get treatment group keys. self.classes_[0] is reserved for the control group.-
+0286: treatment_groups = sorted([x for x in list(set(treatment)) if x != self.control_name])-
__pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 286, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PySet_New(__pyx_v_treatment); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 286, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PySequence_List(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 286, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_3); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 286, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 286, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 286, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = PyObject_RichCompare(__pyx_v_x, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 286, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 286, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (__pyx_t_10) { - if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_v_x))) __PYX_ERR(0, 286, __pyx_L1_error) - } - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_1 = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_11 = PyList_Sort(__pyx_t_1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 286, __pyx_L1_error) - __pyx_v_treatment_groups = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; -
+0287: self.classes_ = [self.control_name]-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 287, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __pyx_t_1 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_classes, __pyx_t_2) < 0) __PYX_ERR(0, 287, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0288: treatment_idx = np.zeros_like(treatment, dtype=int)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros_like); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_treatment); - __Pyx_GIVEREF(__pyx_v_treatment); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_treatment); - __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 288, __pyx_L1_error) - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_treatment_idx = __pyx_t_9; - __pyx_t_9 = 0; -
+0289: for i, tr in enumerate(treatment_groups, 1):-
__Pyx_INCREF(__pyx_int_1); - __pyx_t_9 = __pyx_int_1; - __pyx_t_4 = __pyx_v_treatment_groups; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - for (;;) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 289, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - __Pyx_XDECREF_SET(__pyx_v_tr, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_INCREF(__pyx_t_9); - __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_9); - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_9, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); - __pyx_t_9 = __pyx_t_2; - __pyx_t_2 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; -
+0290: self.classes_.append(tr)-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyObject_Append(__pyx_t_2, __pyx_v_tr); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 290, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0291: treatment_idx[treatment == tr] = i-
__pyx_t_2 = PyObject_RichCompare(__pyx_v_treatment, __pyx_v_tr, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 291, __pyx_L1_error) - if (unlikely(PyObject_SetItem(__pyx_v_treatment_idx, __pyx_t_2, __pyx_v_i) < 0)) __PYX_ERR(0, 291, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0292: self.n_class = len(self.classes_)-
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = PyObject_Length(__pyx_t_9); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 292, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_n_class, __pyx_t_9) < 0) __PYX_ERR(0, 292, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; -
0293:
-+0294: self.feature_imp_dict = defaultdict(float)-
__Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 294, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_9 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, ((PyObject *)(&PyFloat_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)(&PyFloat_Type))); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 294, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_feature_imp_dict, __pyx_t_9) < 0) __PYX_ERR(0, 294, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; -
0295:
-+0296: if self.evaluationFunction == self.evaluate_DDP and self.n_class > 2:-
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 296, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluate_DDP); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 296, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyObject_RichCompare(__pyx_t_9, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 296, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 296, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_12) { - } else { - __pyx_t_10 = __pyx_t_12; - goto __pyx_L11_bool_binop_done; - } - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 296, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_int_2, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 296, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 296, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_10 = __pyx_t_12; - __pyx_L11_bool_binop_done:; - if (unlikely(__pyx_t_10)) { -/* … */ - } -
+0297: raise ValueError("The DDP approach can only cope with two class problems, that is two different treatment "-
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 297, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 297, __pyx_L1_error) -/* … */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_The_DDP_approach_can_only_cope_w); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 297, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__2); - __Pyx_GIVEREF(__pyx_tuple__2); -
0298: "options (e.g., control vs treatment). Please select another approach or only use a "-
0299: "dataset which employs two treatment options.")-
0300:
-+0301: self.fitted_uplift_tree = self.growDecisionTreeFrom(-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_growDecisionTreeFrom); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 301, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); -/* … */ - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 301, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_y); -/* … */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 301, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_fitted_uplift_tree, __pyx_t_1) < 0) __PYX_ERR(0, 301, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
0302: X, treatment_idx, y,-
+0303: max_depth=self.max_depth, min_samples_leaf=self.min_samples_leaf,-
__pyx_t_9 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 303, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_max_depth); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 303, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_max_depth, __pyx_t_1) < 0) __PYX_ERR(0, 303, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_leaf); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 303, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_min_samples_leaf, __pyx_t_1) < 0) __PYX_ERR(0, 303, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_depth, __pyx_int_1) < 0) __PYX_ERR(0, 303, __pyx_L1_error) -
+0304: depth=1, min_samples_treatment=self.min_samples_treatment,-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_treatment); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 304, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_min_samples_treatment, __pyx_t_1) < 0) __PYX_ERR(0, 303, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0305: n_reg=self.n_reg, parentNodeSummary=None-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n_reg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 305, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_n_reg, __pyx_t_1) < 0) __PYX_ERR(0, 303, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_parentNodeSummary, Py_None) < 0) __PYX_ERR(0, 303, __pyx_L1_error) -
0306: )-
0307:
-+0308: self.feature_importances_ = np.zeros(X.shape[1])-
__Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 308, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 308, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 308, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_9, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 308, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_9, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_feature_importances, __pyx_t_1) < 0) __PYX_ERR(0, 308, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0309: for col, imp in self.feature_imp_dict.items():-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_feature_imp_dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_items); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - __pyx_t_13 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_13 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 309, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_13)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 309, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 309, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_13(__pyx_t_4); - if (unlikely(!__pyx_t_1)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 309, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 309, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_9 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_9); - #else - __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_9 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_9)) goto __pyx_L15_unpacking_failed; - __Pyx_GOTREF(__pyx_t_9); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_3), 2) < 0) __PYX_ERR(0, 309, __pyx_L1_error) - __pyx_t_6 = NULL; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L16_unpacking_done; - __pyx_L15_unpacking_failed:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 309, __pyx_L1_error) - __pyx_L16_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_col, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_imp, __pyx_t_9); - __pyx_t_9 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
+0310: self.feature_importances_[col] = imp-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_feature_importances); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 310, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_col, __pyx_v_imp) < 0)) __PYX_ERR(0, 310, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0311: self.feature_importances_ /= self.feature_importances_.sum() # normalize to add to 1-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_feature_importances); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 311, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_feature_importances); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 311, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_sum); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 311, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 311, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyNumber_InPlaceDivide(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 311, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_feature_importances, __pyx_t_2) < 0) __PYX_ERR(0, 311, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
0312:
-0313: # Prune Trees-
+0314: def prune(self, X, treatment, y, minGain=0.0001, rule='maxAbsDiff'):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_5prune(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_4prune[] = " Prune the uplift model.\n Args\n ----\n X : ndarray, shape = [num_samples, num_features]\n An ndarray of the covariates used to train the uplift model.\n treatment : array-like, shape = [num_samples]\n An array containing the treatment group for each unit.\n y : array-like, shape = [num_samples]\n An array containing the outcome of interest for each unit.\n minGain : float, optional (default = 0.0001)\n The minimum gain required to make a tree node split. The children\n tree branches are trimmed if the actual split gain is less than\n the minimum gain.\n rule : string, optional (default = 'maxAbsDiff')\n The prune rules. Supported values are 'maxAbsDiff' for optimizing\n the maximum absolute difference, and 'bestUplift' for optimizing\n the node-size weighted treatment effect.\n Returns\n -------\n self : object\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_5prune = {"prune", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_5prune, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_4prune}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_5prune(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_v_minGain = 0; - PyObject *__pyx_v_rule = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("prune (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_treatment,&__pyx_n_s_y,&__pyx_n_s_minGain,&__pyx_n_s_rule,0}; - PyObject* values[6] = {0,0,0,0,0,0}; - values[4] = ((PyObject *)((PyObject*)__pyx_float_0_0001)); - values[5] = ((PyObject *)((PyObject*)__pyx_n_s_maxAbsDiff)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("prune", 0, 4, 6, 1); __PYX_ERR(0, 314, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("prune", 0, 4, 6, 2); __PYX_ERR(0, 314, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("prune", 0, 4, 6, 3); __PYX_ERR(0, 314, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_minGain); - if (value) { values[4] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rule); - if (value) { values[5] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "prune") < 0)) __PYX_ERR(0, 314, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_treatment = values[2]; - __pyx_v_y = values[3]; - __pyx_v_minGain = values[4]; - __pyx_v_rule = values[5]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("prune", 0, 4, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 314, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_4prune(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_treatment, __pyx_v_y, __pyx_v_minGain, __pyx_v_rule); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_4prune(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment, PyObject *__pyx_v_y, PyObject *__pyx_v_minGain, PyObject *__pyx_v_rule) { - PyObject *__pyx_v_treatment_idx = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_tr = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("prune", 0); - __Pyx_INCREF(__pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment); - __Pyx_INCREF(__pyx_v_y); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_treatment_idx); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_tr); - __Pyx_XDECREF(__pyx_v_X); - __Pyx_XDECREF(__pyx_v_treatment); - __Pyx_XDECREF(__pyx_v_y); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__24 = PyTuple_Pack(9, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_treatment, __pyx_n_s_y, __pyx_n_s_minGain, __pyx_n_s_rule, __pyx_n_s_treatment_idx, __pyx_n_s_i, __pyx_n_s_tr); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 314, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__24); - __Pyx_GIVEREF(__pyx_tuple__24); - __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(6, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_prune, 314, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 314, __pyx_L1_error) -/* … */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_5prune, 0, __pyx_n_s_UpliftTreeClassifier_prune, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__25)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 314, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_tuple__26); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_prune, __pyx_t_2) < 0) __PYX_ERR(0, 314, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_tuple__26 = PyTuple_Pack(2, ((PyObject*)__pyx_float_0_0001), ((PyObject*)__pyx_n_s_maxAbsDiff)); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 314, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__26); - __Pyx_GIVEREF(__pyx_tuple__26); -
0315: """ Prune the uplift model.-
0316: Args-
0317: -----
0318: X : ndarray, shape = [num_samples, num_features]-
0319: An ndarray of the covariates used to train the uplift model.-
0320: treatment : array-like, shape = [num_samples]-
0321: An array containing the treatment group for each unit.-
0322: y : array-like, shape = [num_samples]-
0323: An array containing the outcome of interest for each unit.-
0324: minGain : float, optional (default = 0.0001)-
0325: The minimum gain required to make a tree node split. The children-
0326: tree branches are trimmed if the actual split gain is less than-
0327: the minimum gain.-
0328: rule : string, optional (default = 'maxAbsDiff')-
0329: The prune rules. Supported values are 'maxAbsDiff' for optimizing-
0330: the maximum absolute difference, and 'bestUplift' for optimizing-
0331: the node-size weighted treatment effect.-
0332: Returns-
0333: --------
0334: self : object-
0335: """-
0336:
-+0337: X, y = check_X_y(X, y)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_check_X_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_4 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_4 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_X, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_X, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_X); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_y); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 337, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_5 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - #else - __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_5 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_5)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_3), 2) < 0) __PYX_ERR(0, 337, __pyx_L1_error) - __pyx_t_6 = NULL; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L4_unpacking_done; - __pyx_L3_unpacking_failed:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 337, __pyx_L1_error) - __pyx_L4_unpacking_done:; - } - __Pyx_DECREF_SET(__pyx_v_X, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_y, __pyx_t_5); - __pyx_t_5 = 0; -
+0338: treatment = np.asarray(treatment)-
__Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 338, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_asarray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 338, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_v_treatment) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_treatment); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 338, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_treatment, __pyx_t_1); - __pyx_t_1 = 0; -
+0339: assert len(y) == len(treatment), 'Data length must be equal for X, treatment, and y.'-
#ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - __pyx_t_7 = PyObject_Length(__pyx_v_y); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 339, __pyx_L1_error) - __pyx_t_8 = PyObject_Length(__pyx_v_treatment); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 339, __pyx_L1_error) - if (unlikely(!((__pyx_t_7 == __pyx_t_8) != 0))) { - PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_Data_length_must_be_equal_for_X); - __PYX_ERR(0, 339, __pyx_L1_error) - } - } - #endif -
0340:
-0341: # Get treatment group keys. self.classes_[0] is reserved for the control group.-
+0342: treatment_idx = np.zeros_like(treatment)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 342, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros_like); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 342, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_2, __pyx_v_treatment) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_treatment); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 342, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_treatment_idx = __pyx_t_1; - __pyx_t_1 = 0; -
+0343: for i, tr in enumerate(self.classes_[1:], 1):-
__Pyx_INCREF(__pyx_int_1); - __pyx_t_1 = __pyx_int_1; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_t_5, 1, 0, NULL, NULL, &__pyx_slice__3, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_5 = __pyx_t_2; __Pyx_INCREF(__pyx_t_5); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 343, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_9)) { - if (likely(PyList_CheckExact(__pyx_t_5))) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_5)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 343, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_5, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 343, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_5, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_9(__pyx_t_5); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 343, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_tr, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_INCREF(__pyx_t_1); - __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_t_2; - __pyx_t_2 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -/* … */ - __pyx_slice__3 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__3)) __PYX_ERR(0, 343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__3); - __Pyx_GIVEREF(__pyx_slice__3); -
+0344: treatment_idx[treatment == tr] = i-
__pyx_t_2 = PyObject_RichCompare(__pyx_v_treatment, __pyx_v_tr, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 344, __pyx_L1_error) - if (unlikely(PyObject_SetItem(__pyx_v_treatment_idx, __pyx_t_2, __pyx_v_i) < 0)) __PYX_ERR(0, 344, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
0345:
-+0346: self.pruneTree(X, treatment_idx, y,-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_pruneTree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_y); -/* … */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -
+0347: tree=self.fitted_uplift_tree,-
__pyx_t_2 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fitted_uplift_tree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 347, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_tree, __pyx_t_3) < 0) __PYX_ERR(0, 347, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -
+0348: rule=rule,-
if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_rule, __pyx_v_rule) < 0) __PYX_ERR(0, 347, __pyx_L1_error) -
+0349: minGain=minGain,-
if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_minGain, __pyx_v_minGain) < 0) __PYX_ERR(0, 347, __pyx_L1_error) -
+0350: n_reg=self.n_reg,-
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n_reg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 350, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_n_reg, __pyx_t_3) < 0) __PYX_ERR(0, 347, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -
+0351: parentNodeSummary=None)-
if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_parentNodeSummary, Py_None) < 0) __PYX_ERR(0, 347, __pyx_L1_error) -
+0352: return self-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self); - __pyx_r = __pyx_v_self; - goto __pyx_L0; -
0353:
-+0354: def pruneTree(self, X, treatment_idx, y, tree, rule='maxAbsDiff', minGain=0.,-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_7pruneTree(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_6pruneTree[] = "Prune one single tree node in the uplift model.\n Args\n ----\n X : ndarray, shape = [num_samples, num_features]\n An ndarray of the covariates used to train the uplift model.\n treatment_idx : array-like, shape = [num_samples]\n An array containing the treatment group index for each unit.\n y : array-like, shape = [num_samples]\n An array containing the outcome of interest for each unit.\n rule : string, optional (default = 'maxAbsDiff')\n The prune rules. Supported values are 'maxAbsDiff' for optimizing the maximum absolute difference, and\n 'bestUplift' for optimizing the node-size weighted treatment effect.\n minGain : float, optional (default = 0.)\n The minimum gain required to make a tree node split. The children tree branches are trimmed if the actual\n split gain is less than the minimum gain.\n n_reg: int, optional (default=0)\n The regularization parameter defined in Rzepakowski et al. 2012, the weight (in terms of sample size) of the\n parent node influence on the child node, only effective for 'KL', 'ED', 'Chi', 'CTS' methods.\n parentNodeSummary : list of list, optional (default = None)\n Node summary statistics, [P(Y=1|T), N(T)] of the parent tree node.\n Returns\n -------\n self : object\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_7pruneTree = {"pruneTree", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_7pruneTree, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_6pruneTree}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_7pruneTree(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment_idx = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_v_tree = 0; - PyObject *__pyx_v_rule = 0; - PyObject *__pyx_v_minGain = 0; - PyObject *__pyx_v_n_reg = 0; - PyObject *__pyx_v_parentNodeSummary = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("pruneTree (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_treatment_idx,&__pyx_n_s_y,&__pyx_n_s_tree,&__pyx_n_s_rule,&__pyx_n_s_minGain,&__pyx_n_s_n_reg,&__pyx_n_s_parentNodeSummary,0}; - PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; - values[5] = ((PyObject *)((PyObject*)__pyx_n_s_maxAbsDiff)); - values[6] = ((PyObject *)((PyObject*)__pyx_float_0_)); - values[7] = ((PyObject *)((PyObject *)__pyx_int_0)); -/* … */ - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_6pruneTree(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment_idx, PyObject *__pyx_v_y, PyObject *__pyx_v_tree, PyObject *__pyx_v_rule, PyObject *__pyx_v_minGain, PyObject *__pyx_v_n_reg, PyObject *__pyx_v_parentNodeSummary) { - PyObject *__pyx_v_currentNodeSummary = NULL; - PyObject *__pyx_v_X_l = NULL; - PyObject *__pyx_v_X_r = NULL; - PyObject *__pyx_v_w_l = NULL; - PyObject *__pyx_v_w_r = NULL; - PyObject *__pyx_v_y_l = NULL; - PyObject *__pyx_v_y_r = NULL; - PyObject *__pyx_v_currentScoreD = NULL; - PyObject *__pyx_v_trueNodeSummary = NULL; - PyObject *__pyx_v_trueScoreD = NULL; - PyObject *__pyx_v_falseNodeSummary = NULL; - PyObject *__pyx_v_falseScoreD = NULL; - PyObject *__pyx_v_gain = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("pruneTree", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.pruneTree", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_currentNodeSummary); - __Pyx_XDECREF(__pyx_v_X_l); - __Pyx_XDECREF(__pyx_v_X_r); - __Pyx_XDECREF(__pyx_v_w_l); - __Pyx_XDECREF(__pyx_v_w_r); - __Pyx_XDECREF(__pyx_v_y_l); - __Pyx_XDECREF(__pyx_v_y_r); - __Pyx_XDECREF(__pyx_v_currentScoreD); - __Pyx_XDECREF(__pyx_v_trueNodeSummary); - __Pyx_XDECREF(__pyx_v_trueScoreD); - __Pyx_XDECREF(__pyx_v_falseNodeSummary); - __Pyx_XDECREF(__pyx_v_falseScoreD); - __Pyx_XDECREF(__pyx_v_gain); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__27 = PyTuple_Pack(22, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_treatment_idx, __pyx_n_s_y, __pyx_n_s_tree, __pyx_n_s_rule, __pyx_n_s_minGain, __pyx_n_s_n_reg, __pyx_n_s_parentNodeSummary, __pyx_n_s_currentNodeSummary, __pyx_n_s_X_l, __pyx_n_s_X_r, __pyx_n_s_w_l, __pyx_n_s_w_r, __pyx_n_s_y_l, __pyx_n_s_y_r, __pyx_n_s_currentScoreD, __pyx_n_s_trueNodeSummary, __pyx_n_s_trueScoreD, __pyx_n_s_falseNodeSummary, __pyx_n_s_falseScoreD, __pyx_n_s_gain); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__27); - __Pyx_GIVEREF(__pyx_tuple__27); - __pyx_codeobj__28 = (PyObject*)__Pyx_PyCode_New(9, 0, 22, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__27, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_pruneTree, 354, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__28)) __PYX_ERR(0, 354, __pyx_L1_error) -/* … */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_7pruneTree, 0, __pyx_n_s_UpliftTreeClassifier_pruneTree, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__28)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_tuple__29); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_pruneTree, __pyx_t_2) < 0) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_tuple__29 = PyTuple_Pack(4, ((PyObject*)__pyx_n_s_maxAbsDiff), ((PyObject*)__pyx_float_0_), ((PyObject *)__pyx_int_0), ((PyObject *)Py_None)); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 354, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__29); - __Pyx_GIVEREF(__pyx_tuple__29); -
0355: n_reg=0,-
+0356: parentNodeSummary=None):-
values[8] = ((PyObject *)((PyObject *)Py_None)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("pruneTree", 0, 5, 9, 1); __PYX_ERR(0, 354, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment_idx)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("pruneTree", 0, 5, 9, 2); __PYX_ERR(0, 354, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("pruneTree", 0, 5, 9, 3); __PYX_ERR(0, 354, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tree)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("pruneTree", 0, 5, 9, 4); __PYX_ERR(0, 354, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rule); - if (value) { values[5] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 6: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_minGain); - if (value) { values[6] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 7: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_reg); - if (value) { values[7] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 8: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parentNodeSummary); - if (value) { values[8] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "pruneTree") < 0)) __PYX_ERR(0, 354, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_treatment_idx = values[2]; - __pyx_v_y = values[3]; - __pyx_v_tree = values[4]; - __pyx_v_rule = values[5]; - __pyx_v_minGain = values[6]; - __pyx_v_n_reg = values[7]; - __pyx_v_parentNodeSummary = values[8]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("pruneTree", 0, 5, 9, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 354, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.pruneTree", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_6pruneTree(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_treatment_idx, __pyx_v_y, __pyx_v_tree, __pyx_v_rule, __pyx_v_minGain, __pyx_v_n_reg, __pyx_v_parentNodeSummary); -
0357: """Prune one single tree node in the uplift model.-
0358: Args-
0359: -----
0360: X : ndarray, shape = [num_samples, num_features]-
0361: An ndarray of the covariates used to train the uplift model.-
0362: treatment_idx : array-like, shape = [num_samples]-
0363: An array containing the treatment group index for each unit.-
0364: y : array-like, shape = [num_samples]-
0365: An array containing the outcome of interest for each unit.-
0366: rule : string, optional (default = 'maxAbsDiff')-
0367: The prune rules. Supported values are 'maxAbsDiff' for optimizing the maximum absolute difference, and-
0368: 'bestUplift' for optimizing the node-size weighted treatment effect.-
0369: minGain : float, optional (default = 0.)-
0370: The minimum gain required to make a tree node split. The children tree branches are trimmed if the actual-
0371: split gain is less than the minimum gain.-
0372: n_reg: int, optional (default=0)-
0373: The regularization parameter defined in Rzepakowski et al. 2012, the weight (in terms of sample size) of the-
0374: parent node influence on the child node, only effective for 'KL', 'ED', 'Chi', 'CTS' methods.-
0375: parentNodeSummary : list of list, optional (default = None)-
0376: Node summary statistics, [P(Y=1|T), N(T)] of the parent tree node.-
0377: Returns-
0378: --------
0379: self : object-
0380: """-
0381: # Current Node Summary for Validation Data Set-
+0382: currentNodeSummary = self.tree_node_summary(-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tree_node_summary); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); -/* … */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_y); -/* … */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_currentNodeSummary = __pyx_t_4; - __pyx_t_4 = 0; -
+0383: treatment_idx, y, min_samples_treatment=self.min_samples_treatment,-
__pyx_t_3 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 383, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_treatment); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 383, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_min_samples_treatment, __pyx_t_4) < 0) __PYX_ERR(0, 383, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
+0384: n_reg=n_reg, parentNodeSummary=parentNodeSummary-
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 383, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_parentNodeSummary, __pyx_v_parentNodeSummary) < 0) __PYX_ERR(0, 383, __pyx_L1_error) -
0385: )-
+0386: tree.nodeSummary = currentNodeSummary-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_tree, __pyx_n_s_nodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 386, __pyx_L1_error) -
0387: # Divide sets for child nodes-
+0388: if (tree.trueBranch is None) or (tree.falseBranch is None):-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = (__pyx_t_4 == Py_None); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_7 = (__pyx_t_6 != 0); - if (!__pyx_t_7) { - } else { - __pyx_t_5 = __pyx_t_7; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = (__pyx_t_4 == Py_None); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = (__pyx_t_7 != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L4_bool_binop_done:; - if (__pyx_t_5) { -/* … */ - } -
+0389: X_l, X_r, w_l, w_r, y_l, y_r = self.divideSet(X, treatment_idx, y, tree.col, tree.value)-
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_divideSet); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_col); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[6] = {__pyx_t_8, __pyx_v_X, __pyx_v_treatment_idx, __pyx_v_y, __pyx_t_2, __pyx_t_1}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[6] = {__pyx_t_8, __pyx_v_X, __pyx_v_treatment_idx, __pyx_v_y, __pyx_t_2, __pyx_t_1}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_10 = PyTuple_New(5+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_9, __pyx_v_y); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_10, 3+__pyx_t_9, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 4+__pyx_t_9, __pyx_t_1); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { - PyObject* sequence = __pyx_t_4; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 6)) { - if (size > 6) __Pyx_RaiseTooManyValuesError(6); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 389, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 3); - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 4); - __pyx_t_11 = PyTuple_GET_ITEM(sequence, 5); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_10 = PyList_GET_ITEM(sequence, 1); - __pyx_t_1 = PyList_GET_ITEM(sequence, 2); - __pyx_t_2 = PyList_GET_ITEM(sequence, 3); - __pyx_t_8 = PyList_GET_ITEM(sequence, 4); - __pyx_t_11 = PyList_GET_ITEM(sequence, 5); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_11); - #else - { - Py_ssize_t i; - PyObject** temps[6] = {&__pyx_t_3,&__pyx_t_10,&__pyx_t_1,&__pyx_t_2,&__pyx_t_8,&__pyx_t_11}; - for (i=0; i < 6; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } - } - #endif - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - Py_ssize_t index = -1; - PyObject** temps[6] = {&__pyx_t_3,&__pyx_t_10,&__pyx_t_1,&__pyx_t_2,&__pyx_t_8,&__pyx_t_11}; - __pyx_t_12 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext; - for (index=0; index < 6; index++) { - PyObject* item = __pyx_t_13(__pyx_t_12); if (unlikely(!item)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 6) < 0) __PYX_ERR(0, 389, __pyx_L1_error) - __pyx_t_13 = NULL; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_13 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 389, __pyx_L1_error) - __pyx_L7_unpacking_done:; - } - __pyx_v_X_l = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_v_X_r = __pyx_t_10; - __pyx_t_10 = 0; - __pyx_v_w_l = __pyx_t_1; - __pyx_t_1 = 0; - __pyx_v_w_r = __pyx_t_2; - __pyx_t_2 = 0; - __pyx_v_y_l = __pyx_t_8; - __pyx_t_8 = 0; - __pyx_v_y_r = __pyx_t_11; - __pyx_t_11 = 0; -
0390:
-0391: # recursive call for each branch-
+0392: if tree.trueBranch.results is None:-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_results); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = (__pyx_t_11 == Py_None); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { -/* … */ - } -
+0393: self.pruneTree(X_l, w_l, y_l, tree.trueBranch, rule, minGain,-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_pruneTree); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 393, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 393, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); -/* … */ - __pyx_t_8 = PyTuple_New(7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 393, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v_X_l); - __Pyx_GIVEREF(__pyx_v_X_l); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_X_l); - __Pyx_INCREF(__pyx_v_w_l); - __Pyx_GIVEREF(__pyx_v_w_l); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_w_l); - __Pyx_INCREF(__pyx_v_y_l); - __Pyx_GIVEREF(__pyx_v_y_l); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_y_l); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_4); - __Pyx_INCREF(__pyx_v_rule); - __Pyx_GIVEREF(__pyx_v_rule); - PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_v_rule); - __Pyx_INCREF(__pyx_v_minGain); - __Pyx_GIVEREF(__pyx_v_minGain); - PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_v_minGain); - __Pyx_INCREF(__pyx_v_n_reg); - __Pyx_GIVEREF(__pyx_v_n_reg); - PyTuple_SET_ITEM(__pyx_t_8, 6, __pyx_v_n_reg); - __pyx_t_4 = 0; -/* … */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_8, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 393, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
0394: n_reg,-
+0395: parentNodeSummary=currentNodeSummary)-
__pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 395, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_parentNodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 395, __pyx_L1_error) -
+0396: if tree.falseBranch.results is None:-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 396, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_results); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 396, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = (__pyx_t_4 == Py_None); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = (__pyx_t_6 != 0); - if (__pyx_t_5) { -/* … */ - } -
+0397: self.pruneTree(X_r, w_r, y_r, tree.falseBranch, rule, minGain,-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_pruneTree); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 397, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 397, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); -/* … */ - __pyx_t_8 = PyTuple_New(7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 397, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v_X_r); - __Pyx_GIVEREF(__pyx_v_X_r); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_X_r); - __Pyx_INCREF(__pyx_v_w_r); - __Pyx_GIVEREF(__pyx_v_w_r); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_w_r); - __Pyx_INCREF(__pyx_v_y_r); - __Pyx_GIVEREF(__pyx_v_y_r); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_y_r); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_2); - __Pyx_INCREF(__pyx_v_rule); - __Pyx_GIVEREF(__pyx_v_rule); - PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_v_rule); - __Pyx_INCREF(__pyx_v_minGain); - __Pyx_GIVEREF(__pyx_v_minGain); - PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_v_minGain); - __Pyx_INCREF(__pyx_v_n_reg); - __Pyx_GIVEREF(__pyx_v_n_reg); - PyTuple_SET_ITEM(__pyx_t_8, 6, __pyx_v_n_reg); - __pyx_t_2 = 0; -/* … */ - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 397, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -
0398: n_reg,-
+0399: parentNodeSummary=currentNodeSummary)-
__pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_parentNodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 399, __pyx_L1_error) -
0400:
-0401: # merge leaves (potentially)-
+0402: if (tree.trueBranch.results is not None and-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_results); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_6 = (__pyx_t_2 != Py_None); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = (__pyx_t_6 != 0); - if (__pyx_t_7) { - } else { - __pyx_t_5 = __pyx_t_7; - goto __pyx_L11_bool_binop_done; - } -/* … */ - if (__pyx_t_5) { -/* … */ - } -
+0403: tree.falseBranch.results is not None):-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 403, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_results); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 403, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = (__pyx_t_11 != Py_None); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_6 = (__pyx_t_7 != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L11_bool_binop_done:; -
+0404: if rule == 'maxAbsDiff':-
__pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_rule, __pyx_n_s_maxAbsDiff, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 404, __pyx_L1_error) - if (__pyx_t_5) { -/* … */ - goto __pyx_L13; - } -
0405: # Current D-
+0406: if (tree.maxDiffTreatment in currentNodeSummary and-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_maxDiffTreatment); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 406, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_t_11, __pyx_v_currentNodeSummary, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 406, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_7 = (__pyx_t_6 != 0); - if (__pyx_t_7) { - } else { - __pyx_t_5 = __pyx_t_7; - goto __pyx_L15_bool_binop_done; - } -/* … */ - if (__pyx_t_5) { -/* … */ - goto __pyx_L14; - } -
+0407: self.control_name in currentNodeSummary):-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_t_11, __pyx_v_currentNodeSummary, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_6 = (__pyx_t_7 != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L15_bool_binop_done:; -
+0408: currentScoreD = tree.maxDiffSign * (currentNodeSummary[tree.maxDiffTreatment][0]-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_maxDiffSign); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 408, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_maxDiffTreatment); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 408, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 408, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 408, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -/* … */ - __pyx_t_8 = PyNumber_Multiply(__pyx_t_11, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 408, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_currentScoreD = __pyx_t_8; - __pyx_t_8 = 0; -
+0409: - currentNodeSummary[self.control_name][0])-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 409, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 409, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 409, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Subtract(__pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 409, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -
0410: else:-
+0411: currentScoreD = 0-
/*else*/ {
- __Pyx_INCREF(__pyx_int_0);
- __pyx_v_currentScoreD = __pyx_int_0;
- }
- __pyx_L14:;
-
0412:
-0413: # trueBranch D-
+0414: trueNodeSummary = self.tree_node_summary(-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tree_node_summary); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); -/* … */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_w_l); - __Pyx_GIVEREF(__pyx_v_w_l); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_w_l); - __Pyx_INCREF(__pyx_v_y_l); - __Pyx_GIVEREF(__pyx_v_y_l); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_y_l); -/* … */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_4, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_v_trueNodeSummary = __pyx_t_2; - __pyx_t_2 = 0; -
+0415: w_l, y_l, min_samples_treatment=self.min_samples_treatment,-
if (unlikely(!__pyx_v_w_l)) { __Pyx_RaiseUnboundLocalError("w_l"); __PYX_ERR(0, 415, __pyx_L1_error) } - if (unlikely(!__pyx_v_y_l)) { __Pyx_RaiseUnboundLocalError("y_l"); __PYX_ERR(0, 415, __pyx_L1_error) } -/* … */ - __pyx_t_11 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 415, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_treatment); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 415, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_min_samples_treatment, __pyx_t_2) < 0) __PYX_ERR(0, 415, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0416: n_reg=n_reg, parentNodeSummary=currentNodeSummary-
if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 415, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_parentNodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 415, __pyx_L1_error) -
0417: )-
+0418: if (tree.trueBranch.maxDiffTreatment in trueNodeSummary and-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 418, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_maxDiffTreatment); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 418, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_t_11, __pyx_v_trueNodeSummary, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 418, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_7 = (__pyx_t_6 != 0); - if (__pyx_t_7) { - } else { - __pyx_t_5 = __pyx_t_7; - goto __pyx_L18_bool_binop_done; - } -/* … */ - if (__pyx_t_5) { -/* … */ - goto __pyx_L17; - } -
+0419: self.control_name in trueNodeSummary):-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 419, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_t_11, __pyx_v_trueNodeSummary, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 419, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_6 = (__pyx_t_7 != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L18_bool_binop_done:; -
+0420: trueScoreD = tree.trueBranch.maxDiffSign * (trueNodeSummary[tree.trueBranch.maxDiffTreatment][0]-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_maxDiffSign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_maxDiffTreatment); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_trueNodeSummary, __pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_11, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -/* … */ - __pyx_t_11 = PyNumber_Multiply(__pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_trueScoreD = __pyx_t_11; - __pyx_t_11 = 0; -
+0421: - trueNodeSummary[self.control_name][0])-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_trueNodeSummary, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyNumber_Subtract(__pyx_t_4, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -
0422: trueScoreD = (-
0423: trueScoreD-
+0424: * (trueNodeSummary[tree.trueBranch.maxDiffTreatment][1]-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 424, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_maxDiffTreatment); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 424, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_trueNodeSummary, __pyx_t_8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 424, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_11, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 424, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -/* … */ - __pyx_t_11 = PyNumber_Multiply(__pyx_v_trueScoreD, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 424, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0425: + trueNodeSummary[self.control_name][1])-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 425, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_trueNodeSummary, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 425, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 425, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Add(__pyx_t_8, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 425, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -
+0426: / (currentNodeSummary[tree.trueBranch.maxDiffTreatment][1]-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_maxDiffTreatment); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -/* … */ - __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_11, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF_SET(__pyx_v_trueScoreD, __pyx_t_2); - __pyx_t_2 = 0; -
+0427: + currentNodeSummary[self.control_name][1])-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_4, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Add(__pyx_t_8, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
0428: )-
0429: else:-
+0430: trueScoreD = 0-
/*else*/ {
- __Pyx_INCREF(__pyx_int_0);
- __pyx_v_trueScoreD = __pyx_int_0;
- }
- __pyx_L17:;
-
0431:
-0432: # falseBranch D-
+0433: falseNodeSummary = self.tree_node_summary(-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tree_node_summary); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 433, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); -/* … */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 433, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_w_r); - __Pyx_GIVEREF(__pyx_v_w_r); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_w_r); - __Pyx_INCREF(__pyx_v_y_r); - __Pyx_GIVEREF(__pyx_v_y_r); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_y_r); -/* … */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 433, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_v_falseNodeSummary = __pyx_t_8; - __pyx_t_8 = 0; -
+0434: w_r, y_r, min_samples_treatment=self.min_samples_treatment,-
if (unlikely(!__pyx_v_w_r)) { __Pyx_RaiseUnboundLocalError("w_r"); __PYX_ERR(0, 434, __pyx_L1_error) } - if (unlikely(!__pyx_v_y_r)) { __Pyx_RaiseUnboundLocalError("y_r"); __PYX_ERR(0, 434, __pyx_L1_error) } -/* … */ - __pyx_t_11 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 434, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_treatment); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 434, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_min_samples_treatment, __pyx_t_8) < 0) __PYX_ERR(0, 434, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -
+0435: n_reg=n_reg, parentNodeSummary=currentNodeSummary-
if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 434, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_parentNodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 434, __pyx_L1_error) -
0436: )-
+0437: if (tree.falseBranch.maxDiffTreatment in falseNodeSummary and-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 437, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_maxDiffTreatment); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 437, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_t_11, __pyx_v_falseNodeSummary, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 437, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_7 = (__pyx_t_6 != 0); - if (__pyx_t_7) { - } else { - __pyx_t_5 = __pyx_t_7; - goto __pyx_L21_bool_binop_done; - } -/* … */ - if (__pyx_t_5) { -/* … */ - goto __pyx_L20; - } -
+0438: self.control_name in falseNodeSummary):-
- /* "causalml/inference/tree/uplift.pyx":438 - * ) - * if (tree.falseBranch.maxDiffTreatment in falseNodeSummary and - * self.control_name in falseNodeSummary): # <<<<<<<<<<<<<< - * falseScoreD = ( - * tree.falseBranch.maxDiffSign * - */ - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 438, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_t_11, __pyx_v_falseNodeSummary, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 438, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_6 = (__pyx_t_7 != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L21_bool_binop_done:; -
0439: falseScoreD = (-
+0440: tree.falseBranch.maxDiffSign *-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_maxDiffSign); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -/* … */ - __pyx_t_11 = PyNumber_Multiply(__pyx_t_8, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_falseScoreD = __pyx_t_11; - __pyx_t_11 = 0; -
+0441: (falseNodeSummary[tree.falseBranch.maxDiffTreatment][0]-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 441, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_maxDiffTreatment); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 441, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_falseNodeSummary, __pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 441, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_11, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 441, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -
+0442: - falseNodeSummary[self.control_name][0])-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_falseNodeSummary, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Subtract(__pyx_t_4, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -
0443: )-
0444:
-0445: falseScoreD = (-
+0446: falseScoreD *-
__pyx_t_11 = PyNumber_Multiply(__pyx_v_falseScoreD, __pyx_t_8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 446, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -
+0447: (falseNodeSummary[tree.falseBranch.maxDiffTreatment][1]-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_maxDiffTreatment); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_falseNodeSummary, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_11, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 447, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -
+0448: + falseNodeSummary[self.control_name][1])-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_falseNodeSummary, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_GetItemInt(__pyx_t_8, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyNumber_Add(__pyx_t_2, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -
+0449: / (currentNodeSummary[tree.falseBranch.maxDiffTreatment][1]-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_maxDiffTreatment); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_8, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -/* … */ - __pyx_t_8 = __Pyx_PyNumber_Divide(__pyx_t_11, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF_SET(__pyx_v_falseScoreD, __pyx_t_8); - __pyx_t_8 = 0; -
+0450: + currentNodeSummary[self.control_name][1])-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 450, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 450, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_4, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 450, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Add(__pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 450, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -
0451: )-
0452: else:-
+0453: falseScoreD = 0-
/*else*/ {
- __Pyx_INCREF(__pyx_int_0);
- __pyx_v_falseScoreD = __pyx_int_0;
- }
- __pyx_L20:;
-
0454:
-+0455: if ((trueScoreD + falseScoreD) - currentScoreD <= minGain or-
__pyx_t_8 = PyNumber_Add(__pyx_v_trueScoreD, __pyx_v_falseScoreD); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 455, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = PyNumber_Subtract(__pyx_t_8, __pyx_v_currentScoreD); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 455, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyObject_RichCompare(__pyx_t_4, __pyx_v_minGain, Py_LE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 455, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 455, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L24_bool_binop_done; - } -/* … */ - if (__pyx_t_5) { -/* … */ - } -
+0456: (trueScoreD + falseScoreD < 0.)):-
__pyx_t_8 = PyNumber_Add(__pyx_v_trueScoreD, __pyx_v_falseScoreD); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 456, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = PyObject_RichCompare(__pyx_t_8, __pyx_float_0_, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 456, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 456, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = __pyx_t_6; - __pyx_L24_bool_binop_done:; -
+0457: tree.trueBranch, tree.falseBranch = None, None-
__pyx_t_4 = Py_None; - __Pyx_INCREF(__pyx_t_4); - __pyx_t_8 = Py_None; - __Pyx_INCREF(__pyx_t_8); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch, __pyx_t_4) < 0) __PYX_ERR(0, 457, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch, __pyx_t_8) < 0) __PYX_ERR(0, 457, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -
+0458: tree.results = tree.backupResults-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_backupResults); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 458, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_tree, __pyx_n_s_results, __pyx_t_8) < 0) __PYX_ERR(0, 458, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -
0459:
-+0460: elif rule == 'bestUplift':-
__pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_rule, __pyx_n_s_bestUplift, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 460, __pyx_L1_error) - if (__pyx_t_5) { -/* … */ - } - __pyx_L13:; -
0461: # Current D-
+0462: if (tree.bestTreatment in currentNodeSummary and-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_bestTreatment); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 462, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_t_8, __pyx_v_currentNodeSummary, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 462, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_7 = (__pyx_t_6 != 0); - if (__pyx_t_7) { - } else { - __pyx_t_5 = __pyx_t_7; - goto __pyx_L27_bool_binop_done; - } -/* … */ - if (__pyx_t_5) { -/* … */ - goto __pyx_L26; - } -
+0463: self.control_name in currentNodeSummary):-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 463, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_t_8, __pyx_v_currentNodeSummary, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 463, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_6 = (__pyx_t_7 != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L27_bool_binop_done:; -
0464: currentScoreD = (-
+0465: currentNodeSummary[tree.bestTreatment][0]-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_bestTreatment); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 465, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 465, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 465, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
+0466: - currentNodeSummary[self.control_name][0]-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 466, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 466, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_11, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 466, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = PyNumber_Subtract(__pyx_t_8, __pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 466, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_currentScoreD = __pyx_t_11; - __pyx_t_11 = 0; -
0467: )-
0468: else:-
+0469: currentScoreD = 0-
/*else*/ {
- __Pyx_INCREF(__pyx_int_0);
- __pyx_v_currentScoreD = __pyx_int_0;
- }
- __pyx_L26:;
-
0470:
-0471: # trueBranch D-
+0472: trueNodeSummary = self.tree_node_summary(-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tree_node_summary); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 472, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); -/* … */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 472, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_w_l); - __Pyx_GIVEREF(__pyx_v_w_l); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_w_l); - __Pyx_INCREF(__pyx_v_y_l); - __Pyx_GIVEREF(__pyx_v_y_l); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_y_l); -/* … */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_4, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 472, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_trueNodeSummary = __pyx_t_2; - __pyx_t_2 = 0; -
+0473: w_l, y_l, min_samples_treatment=self.min_samples_treatment,-
if (unlikely(!__pyx_v_w_l)) { __Pyx_RaiseUnboundLocalError("w_l"); __PYX_ERR(0, 473, __pyx_L1_error) } - if (unlikely(!__pyx_v_y_l)) { __Pyx_RaiseUnboundLocalError("y_l"); __PYX_ERR(0, 473, __pyx_L1_error) } -/* … */ - __pyx_t_8 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 473, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_treatment); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 473, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_min_samples_treatment, __pyx_t_2) < 0) __PYX_ERR(0, 473, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0474: n_reg=n_reg, parentNodeSummary=currentNodeSummary-
if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 473, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_parentNodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 473, __pyx_L1_error) -
0475: )-
+0476: if (tree.trueBranch.bestTreatment in trueNodeSummary and-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 476, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_bestTreatment); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 476, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_t_8, __pyx_v_trueNodeSummary, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 476, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_7 = (__pyx_t_6 != 0); - if (__pyx_t_7) { - } else { - __pyx_t_5 = __pyx_t_7; - goto __pyx_L30_bool_binop_done; - } -/* … */ - if (__pyx_t_5) { -/* … */ - goto __pyx_L29; - } -
+0477: self.control_name in trueNodeSummary):-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 477, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_t_8, __pyx_v_trueNodeSummary, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 477, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_6 = (__pyx_t_7 != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L30_bool_binop_done:; -
0478: trueScoreD = (-
+0479: trueNodeSummary[tree.trueBranch.bestTreatment][0]-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 479, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_bestTreatment); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 479, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_trueNodeSummary, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 479, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 479, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -
+0480: - trueNodeSummary[self.control_name][0]-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 480, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_trueNodeSummary, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 480, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 480, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Subtract(__pyx_t_2, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 480, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_trueScoreD = __pyx_t_4; - __pyx_t_4 = 0; -
0481: )-
0482: else:-
+0483: trueScoreD = 0-
/*else*/ {
- __Pyx_INCREF(__pyx_int_0);
- __pyx_v_trueScoreD = __pyx_int_0;
- }
- __pyx_L29:;
-
0484:
-0485: # falseBranch D-
+0486: falseNodeSummary = self.tree_node_summary(-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tree_node_summary); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); -/* … */ - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v_w_r); - __Pyx_GIVEREF(__pyx_v_w_r); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_w_r); - __Pyx_INCREF(__pyx_v_y_r); - __Pyx_GIVEREF(__pyx_v_y_r); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_y_r); -/* … */ - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_falseNodeSummary = __pyx_t_11; - __pyx_t_11 = 0; -
+0487: w_r, y_r, min_samples_treatment=self.min_samples_treatment,-
if (unlikely(!__pyx_v_w_r)) { __Pyx_RaiseUnboundLocalError("w_r"); __PYX_ERR(0, 487, __pyx_L1_error) } - if (unlikely(!__pyx_v_y_r)) { __Pyx_RaiseUnboundLocalError("y_r"); __PYX_ERR(0, 487, __pyx_L1_error) } -/* … */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_treatment); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_min_samples_treatment, __pyx_t_11) < 0) __PYX_ERR(0, 487, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -
+0488: n_reg=n_reg, parentNodeSummary=currentNodeSummary-
if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 487, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_parentNodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 487, __pyx_L1_error) -
0489: )-
+0490: if (tree.falseBranch.bestTreatment in falseNodeSummary and-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 490, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_bestTreatment); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 490, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, __pyx_v_falseNodeSummary, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 490, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = (__pyx_t_6 != 0); - if (__pyx_t_7) { - } else { - __pyx_t_5 = __pyx_t_7; - goto __pyx_L33_bool_binop_done; - } -/* … */ - if (__pyx_t_5) { -/* … */ - goto __pyx_L32; - } -
+0491: self.control_name in falseNodeSummary):-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 491, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, __pyx_v_falseNodeSummary, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 491, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = (__pyx_t_7 != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L33_bool_binop_done:; -
0492: falseScoreD = (-
+0493: falseNodeSummary[tree.falseBranch.bestTreatment][0]-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 493, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_bestTreatment); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 493, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_falseNodeSummary, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 493, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 493, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0494: - falseNodeSummary[self.control_name][0]-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 494, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_falseNodeSummary, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 494, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 494, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyNumber_Subtract(__pyx_t_11, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 494, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_falseScoreD = __pyx_t_8; - __pyx_t_8 = 0; -
0495: )-
0496: else:-
+0497: falseScoreD = 0-
/*else*/ {
- __Pyx_INCREF(__pyx_int_0);
- __pyx_v_falseScoreD = __pyx_int_0;
- }
- __pyx_L32:;
-
+0498: gain = ((1. * len(y_l) / len(y) * trueScoreD-
if (unlikely(!__pyx_v_y_l)) { __Pyx_RaiseUnboundLocalError("y_l"); __PYX_ERR(0, 498, __pyx_L1_error) } - __pyx_t_14 = PyObject_Length(__pyx_v_y_l); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 498, __pyx_L1_error) - __pyx_t_15 = PyObject_Length(__pyx_v_y); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 498, __pyx_L1_error) - __pyx_t_8 = PyFloat_FromDouble(((1. * __pyx_t_14) / __pyx_t_15)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 498, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = PyNumber_Multiply(__pyx_t_8, __pyx_v_trueScoreD); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 498, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -
+0499: + 1. * len(y_r) / len(y) * falseScoreD)-
if (unlikely(!__pyx_v_y_r)) { __Pyx_RaiseUnboundLocalError("y_r"); __PYX_ERR(0, 499, __pyx_L1_error) } - __pyx_t_15 = PyObject_Length(__pyx_v_y_r); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 499, __pyx_L1_error) - __pyx_t_14 = PyObject_Length(__pyx_v_y); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 499, __pyx_L1_error) - __pyx_t_8 = PyFloat_FromDouble(((1. * __pyx_t_15) / __pyx_t_14)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 499, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_11 = PyNumber_Multiply(__pyx_t_8, __pyx_v_falseScoreD); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 499, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyNumber_Add(__pyx_t_2, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 499, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -
+0500: - currentScoreD)-
__pyx_t_11 = PyNumber_Subtract(__pyx_t_8, __pyx_v_currentScoreD); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_gain = __pyx_t_11; - __pyx_t_11 = 0; -
+0501: if gain <= minGain or (trueScoreD + falseScoreD < 0.):-
__pyx_t_11 = PyObject_RichCompare(__pyx_v_gain, __pyx_v_minGain, Py_LE); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 501, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 501, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L36_bool_binop_done; - } - __pyx_t_11 = PyNumber_Add(__pyx_v_trueScoreD, __pyx_v_falseScoreD); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_8 = PyObject_RichCompare(__pyx_t_11, __pyx_float_0_, Py_LT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 501, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 501, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_5 = __pyx_t_6; - __pyx_L36_bool_binop_done:; - if (__pyx_t_5) { -/* … */ - } -
+0502: tree.trueBranch, tree.falseBranch = None, None-
__pyx_t_8 = Py_None; - __Pyx_INCREF(__pyx_t_8); - __pyx_t_11 = Py_None; - __Pyx_INCREF(__pyx_t_11); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch, __pyx_t_8) < 0) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch, __pyx_t_11) < 0) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -
+0503: tree.results = tree.backupResults-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_backupResults); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_tree, __pyx_n_s_results, __pyx_t_11) < 0) __PYX_ERR(0, 503, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; -
+0504: return self-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self); - __pyx_r = __pyx_v_self; - goto __pyx_L0; -
0505:
-+0506: def fill(self, X, treatment, y):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_9fill(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8fill[] = " Fill the data into an existing tree.\n This is a higher-level function to transform the original data inputs\n into lower level data inputs (list of list and tree).\n\n Args\n ----\n X : ndarray, shape = [num_samples, num_features]\n An ndarray of the covariates used to train the uplift model.\n treatment : array-like, shape = [num_samples]\n An array containing the treatment group for each unit.\n y : array-like, shape = [num_samples]\n An array containing the outcome of interest for each unit.\n\n Returns\n -------\n self : object\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_9fill = {"fill", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_9fill, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8fill}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_9fill(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fill (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_treatment,&__pyx_n_s_y,0}; - PyObject* values[4] = {0,0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fill", 1, 4, 4, 1); __PYX_ERR(0, 506, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fill", 1, 4, 4, 2); __PYX_ERR(0, 506, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fill", 1, 4, 4, 3); __PYX_ERR(0, 506, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fill") < 0)) __PYX_ERR(0, 506, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_treatment = values[2]; - __pyx_v_y = values[3]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fill", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 506, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.fill", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8fill(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_treatment, __pyx_v_y); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8fill(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment, PyObject *__pyx_v_y) { - PyObject *__pyx_v_treatment_idx = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_tr = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fill", 0); - __Pyx_INCREF(__pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment); - __Pyx_INCREF(__pyx_v_y); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.fill", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_treatment_idx); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_tr); - __Pyx_XDECREF(__pyx_v_X); - __Pyx_XDECREF(__pyx_v_treatment); - __Pyx_XDECREF(__pyx_v_y); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__30 = PyTuple_Pack(7, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_treatment, __pyx_n_s_y, __pyx_n_s_treatment_idx, __pyx_n_s_i, __pyx_n_s_tr); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__30); - __Pyx_GIVEREF(__pyx_tuple__30); -/* … */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_9fill, 0, __pyx_n_s_UpliftTreeClassifier_fill, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__31)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_fill, __pyx_t_2) < 0) __PYX_ERR(0, 506, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(4, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_fill, 506, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) __PYX_ERR(0, 506, __pyx_L1_error) -
0507: """ Fill the data into an existing tree.-
0508: This is a higher-level function to transform the original data inputs-
0509: into lower level data inputs (list of list and tree).-
0510:
-0511: Args-
0512: -----
0513: X : ndarray, shape = [num_samples, num_features]-
0514: An ndarray of the covariates used to train the uplift model.-
0515: treatment : array-like, shape = [num_samples]-
0516: An array containing the treatment group for each unit.-
0517: y : array-like, shape = [num_samples]-
0518: An array containing the outcome of interest for each unit.-
0519:
-0520: Returns-
0521: --------
0522: self : object-
0523: """-
0524:
-+0525: X, y = check_X_y(X, y)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_check_X_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_4 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_4 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_X, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_X, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_X); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_y); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 525, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_5 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - #else - __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_5 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_5)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_3), 2) < 0) __PYX_ERR(0, 525, __pyx_L1_error) - __pyx_t_6 = NULL; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L4_unpacking_done; - __pyx_L3_unpacking_failed:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 525, __pyx_L1_error) - __pyx_L4_unpacking_done:; - } - __Pyx_DECREF_SET(__pyx_v_X, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_y, __pyx_t_5); - __pyx_t_5 = 0; -
+0526: treatment = np.asarray(treatment)-
__Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 526, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_asarray); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 526, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_v_treatment) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_treatment); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 526, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_treatment, __pyx_t_1); - __pyx_t_1 = 0; -
+0527: assert len(y) == len(treatment), 'Data length must be equal for X, treatment, and y.'-
#ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - __pyx_t_7 = PyObject_Length(__pyx_v_y); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 527, __pyx_L1_error) - __pyx_t_8 = PyObject_Length(__pyx_v_treatment); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 527, __pyx_L1_error) - if (unlikely(!((__pyx_t_7 == __pyx_t_8) != 0))) { - PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_Data_length_must_be_equal_for_X); - __PYX_ERR(0, 527, __pyx_L1_error) - } - } - #endif -
0528:
-0529: # Get treatment group keys. self.classes_[0] is reserved for the control group.-
+0530: treatment_idx = np.zeros_like(treatment)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 530, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros_like); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 530, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_2, __pyx_v_treatment) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_treatment); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 530, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_treatment_idx = __pyx_t_1; - __pyx_t_1 = 0; -
+0531: for i, tr in enumerate(self.classes_[1:], 1):-
__Pyx_INCREF(__pyx_int_1); - __pyx_t_1 = __pyx_int_1; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_t_5, 1, 0, NULL, NULL, &__pyx_slice__3, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_5 = __pyx_t_2; __Pyx_INCREF(__pyx_t_5); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 531, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_9)) { - if (likely(PyList_CheckExact(__pyx_t_5))) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_5)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 531, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_5, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 531, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_5, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_9(__pyx_t_5); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 531, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_tr, __pyx_t_2); - __pyx_t_2 = 0; - __Pyx_INCREF(__pyx_t_1); - __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_t_2; - __pyx_t_2 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0532: treatment_idx[treatment == tr] = i-
__pyx_t_2 = PyObject_RichCompare(__pyx_v_treatment, __pyx_v_tr, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 532, __pyx_L1_error) - if (unlikely(PyObject_SetItem(__pyx_v_treatment_idx, __pyx_t_2, __pyx_v_i) < 0)) __PYX_ERR(0, 532, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
0533:
-+0534: self.fillTree(X, treatment_idx, y, tree=self.fitted_uplift_tree)-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fillTree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 534, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 534, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_y); - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 534, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fitted_uplift_tree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 534, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_tree, __pyx_t_3) < 0) __PYX_ERR(0, 534, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 534, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -
+0535: return self-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self); - __pyx_r = __pyx_v_self; - goto __pyx_L0; -
0536:
-+0537: def fillTree(self, X, treatment_idx, y, tree):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_11fillTree(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_10fillTree[] = " Fill the data into an existing tree.\n This is a lower-level function to execute on the tree filling task.\n\n Args\n ----\n X : ndarray, shape = [num_samples, num_features]\n An ndarray of the covariates used to train the uplift model.\n treatment_idx : array-like, shape = [num_samples]\n An array containing the treatment group index for each unit.\n y : array-like, shape = [num_samples]\n An array containing the outcome of interest for each unit.\n tree : object\n object of DecisionTree class\n\n Returns\n -------\n self : object\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_11fillTree = {"fillTree", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_11fillTree, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_10fillTree}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_11fillTree(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment_idx = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_v_tree = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fillTree (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_treatment_idx,&__pyx_n_s_y,&__pyx_n_s_tree,0}; - PyObject* values[5] = {0,0,0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fillTree", 1, 5, 5, 1); __PYX_ERR(0, 537, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment_idx)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fillTree", 1, 5, 5, 2); __PYX_ERR(0, 537, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fillTree", 1, 5, 5, 3); __PYX_ERR(0, 537, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tree)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fillTree", 1, 5, 5, 4); __PYX_ERR(0, 537, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fillTree") < 0)) __PYX_ERR(0, 537, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_treatment_idx = values[2]; - __pyx_v_y = values[3]; - __pyx_v_tree = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fillTree", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 537, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.fillTree", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_10fillTree(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_treatment_idx, __pyx_v_y, __pyx_v_tree); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_10fillTree(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment_idx, PyObject *__pyx_v_y, PyObject *__pyx_v_tree) { - PyObject *__pyx_v_currentNodeSummary = NULL; - PyObject *__pyx_v_X_l = NULL; - PyObject *__pyx_v_X_r = NULL; - PyObject *__pyx_v_w_l = NULL; - PyObject *__pyx_v_w_r = NULL; - PyObject *__pyx_v_y_l = NULL; - PyObject *__pyx_v_y_r = NULL; - PyObject *__pyx_v_matchScore = NULL; - PyObject *__pyx_v_treatment_group = NULL; - PyObject *__pyx_v_summary = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fillTree", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_15); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.fillTree", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_currentNodeSummary); - __Pyx_XDECREF(__pyx_v_X_l); - __Pyx_XDECREF(__pyx_v_X_r); - __Pyx_XDECREF(__pyx_v_w_l); - __Pyx_XDECREF(__pyx_v_w_r); - __Pyx_XDECREF(__pyx_v_y_l); - __Pyx_XDECREF(__pyx_v_y_r); - __Pyx_XDECREF(__pyx_v_matchScore); - __Pyx_XDECREF(__pyx_v_treatment_group); - __Pyx_XDECREF(__pyx_v_summary); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__32 = PyTuple_Pack(15, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_treatment_idx, __pyx_n_s_y, __pyx_n_s_tree, __pyx_n_s_currentNodeSummary, __pyx_n_s_X_l, __pyx_n_s_X_r, __pyx_n_s_w_l, __pyx_n_s_w_r, __pyx_n_s_y_l, __pyx_n_s_y_r, __pyx_n_s_matchScore, __pyx_n_s_treatment_group, __pyx_n_s_summary); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__32); - __Pyx_GIVEREF(__pyx_tuple__32); -/* … */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_11fillTree, 0, __pyx_n_s_UpliftTreeClassifier_fillTree, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__33)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_fillTree, __pyx_t_2) < 0) __PYX_ERR(0, 537, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(5, 0, 15, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_fillTree, 537, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 537, __pyx_L1_error) -
0538: """ Fill the data into an existing tree.-
0539: This is a lower-level function to execute on the tree filling task.-
0540:
-0541: Args-
0542: -----
0543: X : ndarray, shape = [num_samples, num_features]-
0544: An ndarray of the covariates used to train the uplift model.-
0545: treatment_idx : array-like, shape = [num_samples]-
0546: An array containing the treatment group index for each unit.-
0547: y : array-like, shape = [num_samples]-
0548: An array containing the outcome of interest for each unit.-
0549: tree : object-
0550: object of DecisionTree class-
0551:
-0552: Returns-
0553: --------
0554: self : object-
0555: """-
0556: # Current Node Summary for Validation Data Set-
+0557: currentNodeSummary = self.tree_node_summary(treatment_idx, y,-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tree_node_summary); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_y); -/* … */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_currentNodeSummary = __pyx_t_4; - __pyx_t_4 = 0; -
+0558: min_samples_treatment=0,-
__pyx_t_3 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_min_samples_treatment, __pyx_int_0) < 0) __PYX_ERR(0, 558, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_n_reg, __pyx_int_0) < 0) __PYX_ERR(0, 558, __pyx_L1_error) -
0559: n_reg=0,-
+0560: parentNodeSummary=None)-
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_parentNodeSummary, Py_None) < 0) __PYX_ERR(0, 558, __pyx_L1_error) -
+0561: tree.nodeSummary = currentNodeSummary-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_tree, __pyx_n_s_nodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 561, __pyx_L1_error) -
0562:
-0563: # Divide sets for child nodes-
+0564: if tree.trueBranch or tree.falseBranch:-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 564, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 564, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 564, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 564, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = __pyx_t_6; - __pyx_L4_bool_binop_done:; - if (__pyx_t_5) { -/* … */ - } -
+0565: X_l, X_r, w_l, w_r, y_l, y_r = self.divideSet(X, treatment_idx, y, tree.col, tree.value)-
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_divideSet); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 565, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_col); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 565, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 565, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = NULL; - __pyx_t_8 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[6] = {__pyx_t_7, __pyx_v_X, __pyx_v_treatment_idx, __pyx_v_y, __pyx_t_2, __pyx_t_1}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 5+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 565, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[6] = {__pyx_t_7, __pyx_v_X, __pyx_v_treatment_idx, __pyx_v_y, __pyx_t_2, __pyx_t_1}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 5+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 565, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(5+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 565, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_8, __pyx_v_y); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_9, 3+__pyx_t_8, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_9, 4+__pyx_t_8, __pyx_t_1); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 565, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { - PyObject* sequence = __pyx_t_4; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 6)) { - if (size > 6) __Pyx_RaiseTooManyValuesError(6); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 565, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 3); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 4); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 5); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_9 = PyList_GET_ITEM(sequence, 1); - __pyx_t_1 = PyList_GET_ITEM(sequence, 2); - __pyx_t_2 = PyList_GET_ITEM(sequence, 3); - __pyx_t_7 = PyList_GET_ITEM(sequence, 4); - __pyx_t_10 = PyList_GET_ITEM(sequence, 5); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_10); - #else - { - Py_ssize_t i; - PyObject** temps[6] = {&__pyx_t_3,&__pyx_t_9,&__pyx_t_1,&__pyx_t_2,&__pyx_t_7,&__pyx_t_10}; - for (i=0; i < 6; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 565, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } - } - #endif - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - Py_ssize_t index = -1; - PyObject** temps[6] = {&__pyx_t_3,&__pyx_t_9,&__pyx_t_1,&__pyx_t_2,&__pyx_t_7,&__pyx_t_10}; - __pyx_t_11 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 565, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; - for (index=0; index < 6; index++) { - PyObject* item = __pyx_t_12(__pyx_t_11); if (unlikely(!item)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 6) < 0) __PYX_ERR(0, 565, __pyx_L1_error) - __pyx_t_12 = NULL; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_12 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 565, __pyx_L1_error) - __pyx_L7_unpacking_done:; - } - __pyx_v_X_l = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_v_X_r = __pyx_t_9; - __pyx_t_9 = 0; - __pyx_v_w_l = __pyx_t_1; - __pyx_t_1 = 0; - __pyx_v_w_r = __pyx_t_2; - __pyx_t_2 = 0; - __pyx_v_y_l = __pyx_t_7; - __pyx_t_7 = 0; - __pyx_v_y_r = __pyx_t_10; - __pyx_t_10 = 0; -
0566:
-0567: # recursive call for each branch-
+0568: if tree.trueBranch is not None:-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 568, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = (__pyx_t_4 != Py_None); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { -/* … */ - } -
+0569: self.fillTree(X_l, w_l, y_l, tree.trueBranch)-
__pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fillTree); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = NULL; - __pyx_t_8 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - __pyx_t_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[5] = {__pyx_t_2, __pyx_v_X_l, __pyx_v_w_l, __pyx_v_y_l, __pyx_t_7}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_8, 4+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 569, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[5] = {__pyx_t_2, __pyx_v_X_l, __pyx_v_w_l, __pyx_v_y_l, __pyx_t_7}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_8, 4+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 569, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_1 = PyTuple_New(4+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_v_X_l); - __Pyx_GIVEREF(__pyx_v_X_l); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_8, __pyx_v_X_l); - __Pyx_INCREF(__pyx_v_w_l); - __Pyx_GIVEREF(__pyx_v_w_l); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_8, __pyx_v_w_l); - __Pyx_INCREF(__pyx_v_y_l); - __Pyx_GIVEREF(__pyx_v_y_l); - PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_8, __pyx_v_y_l); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_8, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
+0570: if tree.falseBranch is not None:-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 570, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = (__pyx_t_4 != Py_None); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = (__pyx_t_6 != 0); - if (__pyx_t_5) { -/* … */ - } -
+0571: self.fillTree(X_r, w_r, y_r, tree.falseBranch)-
__pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fillTree); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = NULL; - __pyx_t_8 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - __pyx_t_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_X_r, __pyx_v_w_r, __pyx_v_y_r, __pyx_t_1}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_8, 4+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_X_r, __pyx_v_w_r, __pyx_v_y_r, __pyx_t_1}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_8, 4+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_2 = PyTuple_New(4+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_INCREF(__pyx_v_X_r); - __Pyx_GIVEREF(__pyx_v_X_r); - PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_8, __pyx_v_X_r); - __Pyx_INCREF(__pyx_v_w_r); - __Pyx_GIVEREF(__pyx_v_w_r); - PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_8, __pyx_v_w_r); - __Pyx_INCREF(__pyx_v_y_r); - __Pyx_GIVEREF(__pyx_v_y_r); - PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_8, __pyx_v_y_r); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 3+__pyx_t_8, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
0572:
-0573: # Update Information-
0574:
-0575: # matchScore-
+0576: matchScore = (currentNodeSummary[tree.bestTreatment][0] - currentNodeSummary[0][0])-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_bestTreatment); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 576, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 576, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_10, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 576, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_currentNodeSummary, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 576, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_10, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 576, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyNumber_Subtract(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 576, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_matchScore = __pyx_t_10; - __pyx_t_10 = 0; -
+0577: tree.matchScore = round(matchScore, 4)-
__pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_v_matchScore); - __Pyx_GIVEREF(__pyx_v_matchScore); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_matchScore); - __Pyx_INCREF(__pyx_int_4); - __Pyx_GIVEREF(__pyx_int_4); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_int_4); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_tree, __pyx_n_s_matchScore, __pyx_t_2) < 0) __PYX_ERR(0, 577, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0578: tree.summary['matchScore'] = round(matchScore, 4)-
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 578, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_matchScore); - __Pyx_GIVEREF(__pyx_v_matchScore); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_matchScore); - __Pyx_INCREF(__pyx_int_4); - __Pyx_GIVEREF(__pyx_int_4); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_4); - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_2, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 578, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_summary); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 578, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (unlikely(PyObject_SetItem(__pyx_t_2, __pyx_n_s_matchScore, __pyx_t_10) < 0)) __PYX_ERR(0, 578, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; -
0579:
-0580: # Samples, Group_size-
+0581: tree.summary['samples'] = len(y)-
__pyx_t_13 = PyObject_Length(__pyx_v_y); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 581, __pyx_L1_error) - __pyx_t_10 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 581, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_summary); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 581, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (unlikely(PyObject_SetItem(__pyx_t_2, __pyx_n_s_samples, __pyx_t_10) < 0)) __PYX_ERR(0, 581, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; -
+0582: tree.summary['group_size'] = ''-
__pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_summary); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 582, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - if (unlikely(PyObject_SetItem(__pyx_t_10, __pyx_n_s_group_size, __pyx_kp_s__4) < 0)) __PYX_ERR(0, 582, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; -
+0583: for treatment_group, summary in zip(self.classes_, currentNodeSummary):-
__pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 583, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 583, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_10); - __Pyx_INCREF(__pyx_v_currentNodeSummary); - __Pyx_GIVEREF(__pyx_v_currentNodeSummary); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_currentNodeSummary); - __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_2, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 583, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (likely(PyList_CheckExact(__pyx_t_10)) || PyTuple_CheckExact(__pyx_t_10)) { - __pyx_t_2 = __pyx_t_10; __Pyx_INCREF(__pyx_t_2); __pyx_t_13 = 0; - __pyx_t_14 = NULL; - } else { - __pyx_t_13 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 583, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 583, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - for (;;) { - if (likely(!__pyx_t_14)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_10 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_13); __Pyx_INCREF(__pyx_t_10); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 583, __pyx_L1_error) - #else - __pyx_t_10 = PySequence_ITEM(__pyx_t_2, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 583, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - #endif - } else { - if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_13); __Pyx_INCREF(__pyx_t_10); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 583, __pyx_L1_error) - #else - __pyx_t_10 = PySequence_ITEM(__pyx_t_2, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 583, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - #endif - } - } else { - __pyx_t_10 = __pyx_t_14(__pyx_t_2); - if (unlikely(!__pyx_t_10)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 583, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_10); - } - if ((likely(PyTuple_CheckExact(__pyx_t_10))) || (PyList_CheckExact(__pyx_t_10))) { - PyObject* sequence = __pyx_t_10; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 583, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_4 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_1); - #else - __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 583, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 583, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_7 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 583, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_7)->tp_iternext; - index = 0; __pyx_t_4 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_4)) goto __pyx_L12_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - index = 1; __pyx_t_1 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L12_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_7), 2) < 0) __PYX_ERR(0, 583, __pyx_L1_error) - __pyx_t_12 = NULL; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L13_unpacking_done; - __pyx_L12_unpacking_failed:; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_12 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 583, __pyx_L1_error) - __pyx_L13_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_treatment_group, __pyx_t_4); - __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_summary, __pyx_t_1); - __pyx_t_1 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0584: tree.summary['group_size'] += ' ' + treatment_group + ': ' + str(summary[1])-
__pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_summary); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_n_s_group_size); - __pyx_t_15 = __pyx_n_s_group_size; - __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_10, __pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyNumber_Add(__pyx_kp_s__5, __pyx_v_treatment_group); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = PyNumber_Add(__pyx_t_4, __pyx_kp_s__6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_summary, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Add(__pyx_t_7, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(PyObject_SetItem(__pyx_t_10, __pyx_t_15, __pyx_t_9) < 0)) __PYX_ERR(0, 584, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; -
0585: # classProb-
+0586: if tree.results is not None:-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_results); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 586, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = (__pyx_t_2 != Py_None); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { -/* … */ - } -
+0587: tree.results = self.uplift_classification_results(treatment_idx, y)-
__pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_uplift_classification_results); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = NULL; - __pyx_t_8 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - __pyx_t_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 587, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 587, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9); __pyx_t_9 = NULL; - } - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_8, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_8, __pyx_v_y); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_tree, __pyx_n_s_results, __pyx_t_2) < 0) __PYX_ERR(0, 587, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0588: return self-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self); - __pyx_r = __pyx_v_self; - goto __pyx_L0; -
0589:
-+0590: def predict(self, X):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_13predict(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_12predict[] = "\n Returns the recommended treatment group and predicted optimal\n probability conditional on using the recommended treatment group.\n\n Args\n ----\n X : ndarray, shape = [num_samples, num_features]\n An ndarray of the covariates used to train the uplift model.\n\n Returns\n -------\n pred: ndarray, shape = [num_samples, num_treatments]\n An ndarray of predicted treatment effects across treatments.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_13predict = {"predict", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_13predict, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_12predict}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_13predict(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("predict (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,0}; - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("predict", 1, 2, 2, 1); __PYX_ERR(0, 590, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "predict") < 0)) __PYX_ERR(0, 590, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("predict", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 590, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.predict", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_12predict(__pyx_self, __pyx_v_self, __pyx_v_X); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_12predict(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X) { - PyObject *__pyx_v_pred_nodes = NULL; - Py_ssize_t __pyx_v_i_row; - PyObject *__pyx_v_pred_leaf = NULL; - CYTHON_UNUSED PyObject *__pyx_v__ = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("predict", 0); - __Pyx_INCREF(__pyx_v_X); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.predict", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_pred_nodes); - __Pyx_XDECREF(__pyx_v_pred_leaf); - __Pyx_XDECREF(__pyx_v__); - __Pyx_XDECREF(__pyx_v_X); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__35 = PyTuple_Pack(6, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_pred_nodes, __pyx_n_s_i_row, __pyx_n_s_pred_leaf, __pyx_n_s__34); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 590, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__35); - __Pyx_GIVEREF(__pyx_tuple__35); -/* … */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_13predict, 0, __pyx_n_s_UpliftTreeClassifier_predict, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__36)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 590, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_predict, __pyx_t_2) < 0) __PYX_ERR(0, 590, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_codeobj__36 = (PyObject*)__Pyx_PyCode_New(2, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__35, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_predict, 590, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__36)) __PYX_ERR(0, 590, __pyx_L1_error) -
0591: '''-
0592: Returns the recommended treatment group and predicted optimal-
0593: probability conditional on using the recommended treatment group.-
0594:
-0595: Args-
0596: -----
0597: X : ndarray, shape = [num_samples, num_features]-
0598: An ndarray of the covariates used to train the uplift model.-
0599:
-0600: Returns-
0601: --------
0602: pred: ndarray, shape = [num_samples, num_treatments]-
0603: An ndarray of predicted treatment effects across treatments.-
0604: '''-
0605:
-+0606: X = check_array(X)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_check_array); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 606, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_X) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_X); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 606, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_X, __pyx_t_1); - __pyx_t_1 = 0; -
0607:
-+0608: pred_nodes = []-
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 608, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_pred_nodes = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; -
+0609: for i_row in range(len(X)):-
__pyx_t_4 = PyObject_Length(__pyx_v_X); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 609, __pyx_L1_error) - __pyx_t_5 = __pyx_t_4; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_i_row = __pyx_t_6; -
+0610: pred_leaf, _ = self.classify(X[i_row], self.fitted_uplift_tree, dataMissing=False)-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classify); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_X, __pyx_v_i_row, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fitted_uplift_tree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_3); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dataMissing, Py_False) < 0) __PYX_ERR(0, 610, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 610, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_7)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_1), 2) < 0) __PYX_ERR(0, 610, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L6_unpacking_done; - __pyx_L5_unpacking_failed:; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_8 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 610, __pyx_L1_error) - __pyx_L6_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_pred_leaf, __pyx_t_3); - __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_7); - __pyx_t_7 = 0; -
+0611: pred_nodes.append(pred_leaf)-
__pyx_t_9 = __Pyx_PyList_Append(__pyx_v_pred_nodes, __pyx_v_pred_leaf); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 611, __pyx_L1_error) - } -
+0612: return np.array(pred_nodes)-
__Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_2 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_v_pred_nodes) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_pred_nodes); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 612, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; -
0613:
-+0614: @staticmethod-
__pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 614, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_divideSet, __pyx_t_3) < 0) __PYX_ERR(0, 615, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -
+0615: def divideSet(X, treatment_idx, y, column, value):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_15divideSet(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_14divideSet[] = "\n Tree node split.\n\n Args\n ----\n X : ndarray, shape = [num_samples, num_features]\n An ndarray of the covariates used to train the uplift model.\n treatment_idx : array-like, shape = [num_samples]\n An array containing the treatment group index for each unit.\n y : array-like, shape = [num_samples]\n An array containing the outcome of interest for each unit.\n column : int\n The column used to split the data.\n value : float or int\n The value in the column for splitting the data.\n\n Returns\n -------\n (X_l, X_r, treatment_l, treatment_r, y_l, y_r) : list of ndarray\n The covariates, treatments and outcomes of left node and the right node.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_15divideSet = {"divideSet", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_15divideSet, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_14divideSet}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_15divideSet(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment_idx = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_v_column = 0; - PyObject *__pyx_v_value = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("divideSet (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_treatment_idx,&__pyx_n_s_y,&__pyx_n_s_column,&__pyx_n_s_value,0}; - PyObject* values[5] = {0,0,0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment_idx)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("divideSet", 1, 5, 5, 1); __PYX_ERR(0, 615, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("divideSet", 1, 5, 5, 2); __PYX_ERR(0, 615, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_column)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("divideSet", 1, 5, 5, 3); __PYX_ERR(0, 615, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("divideSet", 1, 5, 5, 4); __PYX_ERR(0, 615, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "divideSet") < 0)) __PYX_ERR(0, 615, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - } - __pyx_v_X = values[0]; - __pyx_v_treatment_idx = values[1]; - __pyx_v_y = values[2]; - __pyx_v_column = values[3]; - __pyx_v_value = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("divideSet", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 615, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.divideSet", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_14divideSet(__pyx_self, __pyx_v_X, __pyx_v_treatment_idx, __pyx_v_y, __pyx_v_column, __pyx_v_value); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_14divideSet(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment_idx, PyObject *__pyx_v_y, PyObject *__pyx_v_column, PyObject *__pyx_v_value) { - PyObject *__pyx_v_filt = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("divideSet", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.divideSet", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_filt); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__37 = PyTuple_Pack(6, __pyx_n_s_X, __pyx_n_s_treatment_idx, __pyx_n_s_y, __pyx_n_s_column, __pyx_n_s_value, __pyx_n_s_filt); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 615, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__37); - __Pyx_GIVEREF(__pyx_tuple__37); -/* … */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_15divideSet, __Pyx_CYFUNCTION_STATICMETHOD, __pyx_n_s_UpliftTreeClassifier_divideSet, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__38)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 615, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(5, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_divideSet, 615, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 615, __pyx_L1_error) -
0616: '''-
0617: Tree node split.-
0618:
-0619: Args-
0620: -----
0621: X : ndarray, shape = [num_samples, num_features]-
0622: An ndarray of the covariates used to train the uplift model.-
0623: treatment_idx : array-like, shape = [num_samples]-
0624: An array containing the treatment group index for each unit.-
0625: y : array-like, shape = [num_samples]-
0626: An array containing the outcome of interest for each unit.-
0627: column : int-
0628: The column used to split the data.-
0629: value : float or int-
0630: The value in the column for splitting the data.-
0631:
-0632: Returns-
0633: --------
0634: (X_l, X_r, treatment_l, treatment_r, y_l, y_r) : list of ndarray-
0635: The covariates, treatments and outcomes of left node and the right node.-
0636: '''-
0637: # for int and float values-
+0638: if np.issubdtype(value.dtype, np.number):-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_issubdtype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_2, ((PyObject *)__pyx_ptype_5numpy_number)}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 638, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_2, ((PyObject *)__pyx_ptype_5numpy_number)}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 638, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; - } - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_ptype_5numpy_number)); - __Pyx_GIVEREF(((PyObject *)__pyx_ptype_5numpy_number)); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, ((PyObject *)__pyx_ptype_5numpy_number)); - __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 638, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_7) { -/* … */ - goto __pyx_L3; - } -
+0639: filt = X[:, column] >= value-
__pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 639, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_slice__7); - __Pyx_GIVEREF(__pyx_slice__7); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_slice__7); - __Pyx_INCREF(__pyx_v_column); - __Pyx_GIVEREF(__pyx_v_column); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_column); - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 639, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_v_value, Py_GE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 639, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_filt = __pyx_t_1; - __pyx_t_1 = 0; -/* … */ - __pyx_slice__7 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__7)) __PYX_ERR(0, 639, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__7); - __Pyx_GIVEREF(__pyx_slice__7); -
0640: else: # for strings-
+0641: filt = X[:, column] == value-
/*else*/ { - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 641, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_slice__7); - __Pyx_GIVEREF(__pyx_slice__7); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_slice__7); - __Pyx_INCREF(__pyx_v_column); - __Pyx_GIVEREF(__pyx_v_column); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_column); - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 641, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_v_value, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 641, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_filt = __pyx_t_1; - __pyx_t_1 = 0; - } - __pyx_L3:; -
0642:
-+0643: return X[filt], X[~filt], treatment_idx[filt], treatment_idx[~filt], y[filt], y[~filt]-
__Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_v_filt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyNumber_Invert(__pyx_v_filt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_treatment_idx, __pyx_v_filt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyNumber_Invert(__pyx_v_filt); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_treatment_idx, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_y, __pyx_v_filt); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_8 = PyNumber_Invert(__pyx_v_filt); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_v_y, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_9); - __pyx_t_1 = 0; - __pyx_t_6 = 0; - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_t_2 = 0; - __pyx_t_9 = 0; - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; - goto __pyx_L0; -
0644:
-+0645: def group_uniqueCounts(self, treatment_idx, y):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_17group_uniqueCounts(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_16group_uniqueCounts[] = "\n Count sample size by experiment group.\n\n Args\n ----\n treatment_idx : array-like, shape = [num_samples]\n An array containing the treatment group index for each unit.\n y : array-like, shape = [num_samples]\n An array containing the outcome of interest for each unit.\n\n Returns\n -------\n results : list of list\n The negative and positive outcome sample sizes for each of the control and treatment groups.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_17group_uniqueCounts = {"group_uniqueCounts", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_17group_uniqueCounts, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_16group_uniqueCounts}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_17group_uniqueCounts(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_treatment_idx = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("group_uniqueCounts (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_treatment_idx,&__pyx_n_s_y,0}; - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment_idx)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("group_uniqueCounts", 1, 3, 3, 1); __PYX_ERR(0, 645, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("group_uniqueCounts", 1, 3, 3, 2); __PYX_ERR(0, 645, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "group_uniqueCounts") < 0)) __PYX_ERR(0, 645, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - } - __pyx_v_self = values[0]; - __pyx_v_treatment_idx = values[1]; - __pyx_v_y = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("group_uniqueCounts", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 645, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.group_uniqueCounts", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_16group_uniqueCounts(__pyx_self, __pyx_v_self, __pyx_v_treatment_idx, __pyx_v_y); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_16group_uniqueCounts(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_treatment_idx, PyObject *__pyx_v_y) { - PyObject *__pyx_v_results = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_filt = NULL; - PyObject *__pyx_v_n_pos = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("group_uniqueCounts", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.group_uniqueCounts", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_results); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_filt); - __Pyx_XDECREF(__pyx_v_n_pos); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__39 = PyTuple_Pack(7, __pyx_n_s_self, __pyx_n_s_treatment_idx, __pyx_n_s_y, __pyx_n_s_results, __pyx_n_s_i, __pyx_n_s_filt, __pyx_n_s_n_pos); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 645, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__39); - __Pyx_GIVEREF(__pyx_tuple__39); -/* … */ - __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_17group_uniqueCounts, 0, __pyx_n_s_UpliftTreeClassifier_group_uniqu, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__40)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 645, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_group_uniqueCounts, __pyx_t_3) < 0) __PYX_ERR(0, 645, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_codeobj__40 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__39, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_group_uniqueCounts, 645, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__40)) __PYX_ERR(0, 645, __pyx_L1_error) -
0646: '''-
0647: Count sample size by experiment group.-
0648:
-0649: Args-
0650: -----
0651: treatment_idx : array-like, shape = [num_samples]-
0652: An array containing the treatment group index for each unit.-
0653: y : array-like, shape = [num_samples]-
0654: An array containing the outcome of interest for each unit.-
0655:
-0656: Returns-
0657: --------
0658: results : list of list-
0659: The negative and positive outcome sample sizes for each of the control and treatment groups.-
0660: '''-
+0661: results = []-
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 661, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_results = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; -
+0662: for i in range(self.n_class):-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 662, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 662, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 662, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 662, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 662, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 662, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 662, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 662, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_4(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 662, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_2); - __pyx_t_2 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0663: filt = treatment_idx == i-
__pyx_t_2 = PyObject_RichCompare(__pyx_v_treatment_idx, __pyx_v_i, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 663, __pyx_L1_error) - __Pyx_XDECREF_SET(__pyx_v_filt, __pyx_t_2); - __pyx_t_2 = 0; -
+0664: n_pos = y[filt].sum()-
__pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_y, __pyx_v_filt); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 664, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_sum); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 664, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 664, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF_SET(__pyx_v_n_pos, __pyx_t_2); - __pyx_t_2 = 0; -
0665:
-0666: # [N(Y = 0, T = 1), N(Y = 1, T = 1)]-
+0667: results.append([filt.sum() - n_pos, n_pos])-
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_filt, __pyx_n_s_sum); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 667, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 667, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyNumber_Subtract(__pyx_t_2, __pyx_v_n_pos); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 667, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 667, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_6); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); - __Pyx_INCREF(__pyx_v_n_pos); - __Pyx_GIVEREF(__pyx_v_n_pos); - PyList_SET_ITEM(__pyx_t_2, 1, __pyx_v_n_pos); - __pyx_t_6 = 0; - __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_results, __pyx_t_2); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 667, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
0668:
-+0669: return results-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_results); - __pyx_r = __pyx_v_results; - goto __pyx_L0; -
0670:
-+0671: @staticmethod-
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 671, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_evaluate_KL, __pyx_t_2) < 0) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0672: def evaluate_KL(nodeSummary):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_19evaluate_KL(PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_18evaluate_KL[] = "\n Calculate KL Divergence as split evaluation criterion for a given node.\n\n Args\n ----\n nodeSummary : list of list\n The tree node summary statistics, [P(Y=1|T), N(T)], produced by tree_node_summary()\n method.\n\n Returns\n -------\n d_res : KL Divergence\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_19evaluate_KL = {"evaluate_KL", (PyCFunction)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_19evaluate_KL, METH_O, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_18evaluate_KL}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_19evaluate_KL(PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate_KL (wrapper)", 0); - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_18evaluate_KL(__pyx_self, ((PyObject *)__pyx_v_nodeSummary)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_18evaluate_KL(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary) { - PyObject *__pyx_v_p_c = NULL; - double __pyx_v_d_res; - PyObject *__pyx_v_treatment_group = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate_KL", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.evaluate_KL", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_p_c); - __Pyx_XDECREF(__pyx_v_treatment_group); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__41 = PyTuple_Pack(4, __pyx_n_s_nodeSummary, __pyx_n_s_p_c, __pyx_n_s_d_res, __pyx_n_s_treatment_group); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__41); - __Pyx_GIVEREF(__pyx_tuple__41); -/* … */ - __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_19evaluate_KL, __Pyx_CYFUNCTION_STATICMETHOD, __pyx_n_s_UpliftTreeClassifier_evaluate_KL, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__42)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_codeobj__42 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__41, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_evaluate_KL, 672, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__42)) __PYX_ERR(0, 672, __pyx_L1_error) -
0673: '''-
0674: Calculate KL Divergence as split evaluation criterion for a given node.-
0675:
-0676: Args-
0677: -----
0678: nodeSummary : list of list-
0679: The tree node summary statistics, [P(Y=1|T), N(T)], produced by tree_node_summary()-
0680: method.-
0681:
-0682: Returns-
0683: --------
0684: d_res : KL Divergence-
0685: '''-
+0686: p_c = nodeSummary[0][0]-
__pyx_t_1 = __Pyx_GetItemInt(__pyx_v_nodeSummary, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 686, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 686, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_p_c = __pyx_t_2; - __pyx_t_2 = 0; -
+0687: d_res = 0.-
__pyx_v_d_res = 0.; -
+0688: for treatment_group in nodeSummary[1:]:-
__pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_nodeSummary, 1, 0, NULL, NULL, &__pyx_slice__3, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 688, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 688, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 688, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_4(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 688, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_treatment_group, __pyx_t_2); - __pyx_t_2 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0689: d_res += kl_divergence(treatment_group[0], p_c)-
__pyx_t_2 = __Pyx_GetItemInt(__pyx_v_treatment_group, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 689, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 689, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_v_p_c); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 689, __pyx_L1_error) - __pyx_t_7 = __pyx_f_8causalml_9inference_4tree_6uplift_kl_divergence(__pyx_t_5, __pyx_t_6); if (unlikely(__pyx_t_7 == ((float)-1) && PyErr_Occurred())) __PYX_ERR(0, 689, __pyx_L1_error) - __pyx_v_d_res = (__pyx_v_d_res + __pyx_t_7); -
+0690: return d_res-
__Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_d_res); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; -
0691:
-+0692: @staticmethod-
__pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 692, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_evaluate_ED, __pyx_t_3) < 0) __PYX_ERR(0, 693, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -
+0693: def evaluate_ED(nodeSummary):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_21evaluate_ED(PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_20evaluate_ED[] = "\n Calculate Euclidean Distance as split evaluation criterion for a given node.\n\n Args\n ----\n nodeSummary : dictionary\n The tree node summary statistics, produced by tree_node_summary()\n method.\n\n Returns\n -------\n d_res : Euclidean Distance\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_21evaluate_ED = {"evaluate_ED", (PyCFunction)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_21evaluate_ED, METH_O, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_20evaluate_ED}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_21evaluate_ED(PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate_ED (wrapper)", 0); - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_20evaluate_ED(__pyx_self, ((PyObject *)__pyx_v_nodeSummary)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_20evaluate_ED(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary) { - PyObject *__pyx_v_pc = NULL; - PyObject *__pyx_v_d_res = NULL; - PyObject *__pyx_v_treatment_group = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate_ED", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.evaluate_ED", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_pc); - __Pyx_XDECREF(__pyx_v_d_res); - __Pyx_XDECREF(__pyx_v_treatment_group); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__43 = PyTuple_Pack(4, __pyx_n_s_nodeSummary, __pyx_n_s_pc, __pyx_n_s_d_res, __pyx_n_s_treatment_group); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__43); - __Pyx_GIVEREF(__pyx_tuple__43); -/* … */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_21evaluate_ED, __Pyx_CYFUNCTION_STATICMETHOD, __pyx_n_s_UpliftTreeClassifier_evaluate_ED, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__44)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_codeobj__44 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__43, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_evaluate_ED, 693, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__44)) __PYX_ERR(0, 693, __pyx_L1_error) -
0694: '''-
0695: Calculate Euclidean Distance as split evaluation criterion for a given node.-
0696:
-0697: Args-
0698: -----
0699: nodeSummary : dictionary-
0700: The tree node summary statistics, produced by tree_node_summary()-
0701: method.-
0702:
-0703: Returns-
0704: --------
0705: d_res : Euclidean Distance-
0706: '''-
+0707: pc = nodeSummary[0][0]-
__pyx_t_1 = __Pyx_GetItemInt(__pyx_v_nodeSummary, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_pc = __pyx_t_2; - __pyx_t_2 = 0; -
+0708: d_res = 0-
__Pyx_INCREF(__pyx_int_0);
- __pyx_v_d_res = __pyx_int_0;
-
+0709: for treatment_group in nodeSummary[1:]:-
__pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_nodeSummary, 1, 0, NULL, NULL, &__pyx_slice__3, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 709, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 709, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 709, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_4(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 709, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_treatment_group, __pyx_t_2); - __pyx_t_2 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0710: d_res += 2*(treatment_group[0] - pc)**2-
__pyx_t_2 = __Pyx_GetItemInt(__pyx_v_treatment_group, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyNumber_Subtract(__pyx_t_2, __pyx_v_pc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Power(__pyx_t_5, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Multiply(__pyx_int_2, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_d_res, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF_SET(__pyx_v_d_res, __pyx_t_2); - __pyx_t_2 = 0; -
+0711: return d_res-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_d_res); - __pyx_r = __pyx_v_d_res; - goto __pyx_L0; -
0712:
-+0713: @staticmethod-
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 713, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_evaluate_Chi, __pyx_t_2) < 0) __PYX_ERR(0, 714, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0714: def evaluate_Chi(nodeSummary):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_23evaluate_Chi(PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_22evaluate_Chi[] = "\n Calculate Chi-Square statistic as split evaluation criterion for a given node.\n\n Args\n ----\n nodeSummary : dictionary\n The tree node summary statistics, produced by tree_node_summary() method.\n\n Returns\n -------\n d_res : Chi-Square\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_23evaluate_Chi = {"evaluate_Chi", (PyCFunction)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_23evaluate_Chi, METH_O, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_22evaluate_Chi}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_23evaluate_Chi(PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate_Chi (wrapper)", 0); - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_22evaluate_Chi(__pyx_self, ((PyObject *)__pyx_v_nodeSummary)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_22evaluate_Chi(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary) { - PyObject *__pyx_v_pc = NULL; - PyObject *__pyx_v_d_res = NULL; - PyObject *__pyx_v_treatment_group = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate_Chi", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.evaluate_Chi", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_pc); - __Pyx_XDECREF(__pyx_v_d_res); - __Pyx_XDECREF(__pyx_v_treatment_group); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__45 = PyTuple_Pack(4, __pyx_n_s_nodeSummary, __pyx_n_s_pc, __pyx_n_s_d_res, __pyx_n_s_treatment_group); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 714, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__45); - __Pyx_GIVEREF(__pyx_tuple__45); -/* … */ - __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_23evaluate_Chi, __Pyx_CYFUNCTION_STATICMETHOD, __pyx_n_s_UpliftTreeClassifier_evaluate_Ch, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__46)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 714, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_codeobj__46 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__45, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_evaluate_Chi, 714, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__46)) __PYX_ERR(0, 714, __pyx_L1_error) -
0715: '''-
0716: Calculate Chi-Square statistic as split evaluation criterion for a given node.-
0717:
-0718: Args-
0719: -----
0720: nodeSummary : dictionary-
0721: The tree node summary statistics, produced by tree_node_summary() method.-
0722:
-0723: Returns-
0724: --------
0725: d_res : Chi-Square-
0726: '''-
+0727: pc = nodeSummary[0][0]-
__pyx_t_1 = __Pyx_GetItemInt(__pyx_v_nodeSummary, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_pc = __pyx_t_2; - __pyx_t_2 = 0; -
+0728: d_res = 0-
__Pyx_INCREF(__pyx_int_0);
- __pyx_v_d_res = __pyx_int_0;
-
+0729: for treatment_group in nodeSummary[1:]:-
__pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_nodeSummary, 1, 0, NULL, NULL, &__pyx_slice__3, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 729, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 729, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 729, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 729, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_4(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 729, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_treatment_group, __pyx_t_2); - __pyx_t_2 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0730: d_res += ((treatment_group[0] - pc) ** 2 / max(0.1 ** 6, pc)-
__pyx_t_2 = __Pyx_GetItemInt(__pyx_v_treatment_group, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyNumber_Subtract(__pyx_t_2, __pyx_v_pc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Power(__pyx_t_5, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_INCREF(__pyx_v_pc); - __pyx_t_5 = __pyx_v_pc; - __pyx_t_6 = pow(0.1, 6.0); - __pyx_t_8 = PyFloat_FromDouble(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = PyObject_RichCompare(__pyx_t_5, __pyx_t_8, Py_GT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (__pyx_t_10) { - __Pyx_INCREF(__pyx_t_5); - __pyx_t_7 = __pyx_t_5; - } else { - __pyx_t_9 = PyFloat_FromDouble(__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = __pyx_t_9; - __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -/* … */ - __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_d_res, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF_SET(__pyx_v_d_res, __pyx_t_2); - __pyx_t_2 = 0; -
+0731: + (treatment_group[0] - pc) ** 2 / max(0.1 ** 6, 1 - pc))-
__pyx_t_7 = __Pyx_GetItemInt(__pyx_v_treatment_group, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = PyNumber_Subtract(__pyx_t_7, __pyx_v_pc); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Power(__pyx_t_2, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_v_pc, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = pow(0.1, 6.0); - __pyx_t_8 = PyFloat_FromDouble(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_11 = PyObject_RichCompare(__pyx_t_2, __pyx_t_8, Py_GT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (__pyx_t_10) { - __Pyx_INCREF(__pyx_t_2); - __pyx_t_9 = __pyx_t_2; - } else { - __pyx_t_11 = PyFloat_FromDouble(__pyx_t_6); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_9 = __pyx_t_11; - __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Add(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0732: return d_res-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_d_res); - __pyx_r = __pyx_v_d_res; - goto __pyx_L0; -
0733:
-+0734: @staticmethod-
__pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 734, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_evaluate_DDP, __pyx_t_3) < 0) __PYX_ERR(0, 735, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -
+0735: def evaluate_DDP(nodeSummary):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_25evaluate_DDP(PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_24evaluate_DDP[] = "\n Calculate Delta P as split evaluation criterion for a given node.\n\n Args\n ----\n nodeSummary : list of list\n The tree node summary statistics, [P(Y=1|T), N(T)], produced by tree_node_summary() method.\n\n Returns\n -------\n d_res : Delta P\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_25evaluate_DDP = {"evaluate_DDP", (PyCFunction)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_25evaluate_DDP, METH_O, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_24evaluate_DDP}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_25evaluate_DDP(PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate_DDP (wrapper)", 0); - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_24evaluate_DDP(__pyx_self, ((PyObject *)__pyx_v_nodeSummary)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_24evaluate_DDP(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary) { - PyObject *__pyx_v_pc = NULL; - PyObject *__pyx_v_d_res = NULL; - PyObject *__pyx_v_treatment_group = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate_DDP", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.evaluate_DDP", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_pc); - __Pyx_XDECREF(__pyx_v_d_res); - __Pyx_XDECREF(__pyx_v_treatment_group); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__47 = PyTuple_Pack(4, __pyx_n_s_nodeSummary, __pyx_n_s_pc, __pyx_n_s_d_res, __pyx_n_s_treatment_group); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 735, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__47); - __Pyx_GIVEREF(__pyx_tuple__47); -/* … */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_25evaluate_DDP, __Pyx_CYFUNCTION_STATICMETHOD, __pyx_n_s_UpliftTreeClassifier_evaluate_DD, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__48)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 735, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_codeobj__48 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__47, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_evaluate_DDP, 735, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__48)) __PYX_ERR(0, 735, __pyx_L1_error) -
0736: '''-
0737: Calculate Delta P as split evaluation criterion for a given node.-
0738:
-0739: Args-
0740: -----
0741: nodeSummary : list of list-
0742: The tree node summary statistics, [P(Y=1|T), N(T)], produced by tree_node_summary() method.-
0743:
-0744: Returns-
0745: --------
0746: d_res : Delta P-
0747: '''-
+0748: pc = nodeSummary[0][0]-
__pyx_t_1 = __Pyx_GetItemInt(__pyx_v_nodeSummary, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_pc = __pyx_t_2; - __pyx_t_2 = 0; -
+0749: d_res = 0-
__Pyx_INCREF(__pyx_int_0);
- __pyx_v_d_res = __pyx_int_0;
-
+0750: for treatment_group in nodeSummary[1:]:-
__pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_nodeSummary, 1, 0, NULL, NULL, &__pyx_slice__3, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 750, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 750, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 750, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_4(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 750, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_treatment_group, __pyx_t_2); - __pyx_t_2 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0751: d_res += treatment_group[0] - pc-
__pyx_t_2 = __Pyx_GetItemInt(__pyx_v_treatment_group, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 751, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyNumber_Subtract(__pyx_t_2, __pyx_v_pc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 751, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_d_res, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 751, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF_SET(__pyx_v_d_res, __pyx_t_2); - __pyx_t_2 = 0; -
+0752: return d_res-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_d_res); - __pyx_r = __pyx_v_d_res; - goto __pyx_L0; -
0753:
-+0754: @staticmethod-
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 754, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_evaluate_CTS, __pyx_t_2) < 0) __PYX_ERR(0, 755, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+0755: def evaluate_CTS(nodeSummary):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_27evaluate_CTS(PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_26evaluate_CTS[] = "\n Calculate CTS (conditional treatment selection) as split evaluation criterion for a given node.\n\n Args\n ----\n nodeSummary : list of list\n The tree node summary statistics, [P(Y=1|T), N(T)], produced by tree_node_summary() method.\n\n Returns\n -------\n d_res : Chi-Square\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_27evaluate_CTS = {"evaluate_CTS", (PyCFunction)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_27evaluate_CTS, METH_O, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_26evaluate_CTS}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_27evaluate_CTS(PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate_CTS (wrapper)", 0); - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_26evaluate_CTS(__pyx_self, ((PyObject *)__pyx_v_nodeSummary)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_26evaluate_CTS(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_nodeSummary) { - PyObject *__pyx_v_stat = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate_CTS", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.evaluate_CTS", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_stat); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__49 = PyTuple_Pack(2, __pyx_n_s_nodeSummary, __pyx_n_s_stat); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__49); - __Pyx_GIVEREF(__pyx_tuple__49); -/* … */ - __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_27evaluate_CTS, __Pyx_CYFUNCTION_STATICMETHOD, __pyx_n_s_UpliftTreeClassifier_evaluate_CT, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__50)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_codeobj__50 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_evaluate_CTS, 755, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__50)) __PYX_ERR(0, 755, __pyx_L1_error) -
0756: '''-
0757: Calculate CTS (conditional treatment selection) as split evaluation criterion for a given node.-
0758:
-0759: Args-
0760: -----
0761: nodeSummary : list of list-
0762: The tree node summary statistics, [P(Y=1|T), N(T)], produced by tree_node_summary() method.-
0763:
-0764: Returns-
0765: --------
0766: d_res : Chi-Square-
0767: '''-
+0768: return -max([stat[0] for stat in nodeSummary])-
__Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (likely(PyList_CheckExact(__pyx_v_nodeSummary)) || PyTuple_CheckExact(__pyx_v_nodeSummary)) { - __pyx_t_2 = __pyx_v_nodeSummary; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_nodeSummary); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 768, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 768, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 768, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } - } else { - __pyx_t_5 = __pyx_t_4(__pyx_t_2); - if (unlikely(!__pyx_t_5)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 768, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - __Pyx_XDECREF_SET(__pyx_v_stat, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_stat, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_max, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Negative(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; -
0769:
-+0770: def normI(self, n_c: cython.int, n_c_left: cython.int, n_t: list, n_t_left: list,-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_29normI(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_28normI[] = "\n Normalization factor.\n\n Args\n ----\n currentNodeSummary : list of list\n The summary statistics of the current tree node, [P(Y=1|T), N(T)].\n\n leftNodeSummary : list of list\n The summary statistics of the left tree node, [P(Y=1|T), N(T)].\n\n alpha : float\n The weight used to balance different normalization parts.\n\n Returns\n -------\n norm_res : float\n Normalization factor.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_29normI = {"normI", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_29normI, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_28normI}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_29normI(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - CYTHON_UNUSED PyObject *__pyx_v_self = 0; - int __pyx_v_n_c; - int __pyx_v_n_c_left; - PyObject *__pyx_v_n_t = 0; - PyObject *__pyx_v_n_t_left = 0; - float __pyx_v_alpha; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("normI (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_n_c,&__pyx_n_s_n_c_left,&__pyx_n_s_n_t,&__pyx_n_s_n_t_left,&__pyx_n_s_alpha,0}; - PyObject* values[6] = {0,0,0,0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_c)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("normI", 0, 5, 6, 1); __PYX_ERR(0, 770, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_c_left)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("normI", 0, 5, 6, 2); __PYX_ERR(0, 770, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_t)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("normI", 0, 5, 6, 3); __PYX_ERR(0, 770, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_t_left)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("normI", 0, 5, 6, 4); __PYX_ERR(0, 770, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_alpha); - if (value) { values[5] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "normI") < 0)) __PYX_ERR(0, 770, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_n_c = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_n_c == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 770, __pyx_L3_error) - __pyx_v_n_c_left = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_n_c_left == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 770, __pyx_L3_error) - __pyx_v_n_t = ((PyObject*)values[3]); - __pyx_v_n_t_left = ((PyObject*)values[4]); - if (values[5]) { - __pyx_v_alpha = __pyx_PyFloat_AsFloat(values[5]); if (unlikely((__pyx_v_alpha == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 771, __pyx_L3_error) - } else { - __pyx_v_alpha = ((float)((double)0.9)); - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("normI", 0, 5, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 770, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.normI", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_n_t), (&PyList_Type), 1, "n_t", 1))) __PYX_ERR(0, 770, __pyx_L1_error) - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_n_t_left), (&PyList_Type), 1, "n_t_left", 1))) __PYX_ERR(0, 770, __pyx_L1_error) - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_28normI(__pyx_self, __pyx_v_self, __pyx_v_n_c, __pyx_v_n_c_left, __pyx_v_n_t, __pyx_v_n_t_left, __pyx_v_alpha); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_28normI(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self, int __pyx_v_n_c, int __pyx_v_n_c_left, PyObject *__pyx_v_n_t, PyObject *__pyx_v_n_t_left, float __pyx_v_alpha) { - float __pyx_v_norm_res; - float __pyx_v_pt_a; - float __pyx_v_pc_a; - Py_ssize_t __pyx_v_i; - PyObject *__pyx_v_pt_a_i = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("normI", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.normI", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_pt_a_i); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__51 = PyTuple_Pack(11, __pyx_n_s_self, __pyx_n_s_n_c, __pyx_n_s_n_c_left, __pyx_n_s_n_t, __pyx_n_s_n_t_left, __pyx_n_s_alpha, __pyx_n_s_norm_res, __pyx_n_s_pt_a, __pyx_n_s_pc_a, __pyx_n_s_i, __pyx_n_s_pt_a_i); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 770, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__51); - __Pyx_GIVEREF(__pyx_tuple__51); -/* … */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 770, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 770, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_n_c, __pyx_n_u_int) < 0) __PYX_ERR(0, 770, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_n_c_left, __pyx_n_u_int) < 0) __PYX_ERR(0, 770, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_n_t, __pyx_n_u_list) < 0) __PYX_ERR(0, 770, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_n_t_left, __pyx_n_u_list) < 0) __PYX_ERR(0, 770, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_alpha, __pyx_n_u_float) < 0) __PYX_ERR(0, 770, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_return, __pyx_n_u_float) < 0) __PYX_ERR(0, 770, __pyx_L1_error) - __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_29normI, 0, __pyx_n_s_UpliftTreeClassifier_normI, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__52)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 770, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_t_3); - __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_5, __pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_normI, __pyx_t_5) < 0) __PYX_ERR(0, 770, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_codeobj__52 = (PyObject*)__Pyx_PyCode_New(6, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__51, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_normI, 770, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__52)) __PYX_ERR(0, 770, __pyx_L1_error) -
+0771: alpha: cython.float=0.9) -> cython.float:-
__pyx_t_2 = PyFloat_FromDouble(((double)0.9)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 771, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); -
0772: '''-
0773: Normalization factor.-
0774:
-0775: Args-
0776: -----
0777: currentNodeSummary : list of list-
0778: The summary statistics of the current tree node, [P(Y=1|T), N(T)].-
0779:
-0780: leftNodeSummary : list of list-
0781: The summary statistics of the left tree node, [P(Y=1|T), N(T)].-
0782:
-0783: alpha : float-
0784: The weight used to balance different normalization parts.-
0785:
-0786: Returns-
0787: --------
0788: norm_res : float-
0789: Normalization factor.-
0790: '''-
0791:
-+0792: norm_res: cython.float = 0.-
__pyx_v_norm_res = 0.; -
0793: pt_a: cython.float-
0794: pc_a: cython.float-
0795:
-+0796: pt_a = 1. * np.sum(n_t_left) / (np.sum(n_t) + 0.1)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 796, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_sum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 796, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_n_t_left) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_n_t_left); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 796, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Multiply(__pyx_float_1_, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 796, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 796, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_sum); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 796, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_v_n_t) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_n_t); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 796, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyFloat_AddObjC(__pyx_t_1, __pyx_float_0_1, 0.1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 796, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 796, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 796, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_pt_a = __pyx_t_5; -
+0797: pc_a = 1. * n_c_left / (n_c + 0.1)-
__pyx_v_pc_a = ((1. * __pyx_v_n_c_left) / (__pyx_v_n_c + 0.1)); -
0798:
-0799: # Normalization Part 1-
+0800: norm_res += (-
__pyx_v_norm_res = (__pyx_v_norm_res + ((__pyx_v_alpha * __pyx_t_7) * __pyx_t_6)); -
+0801: alpha * entropyH(1. * np.sum(n_t) / (np.sum(n_t) + n_c), 1. * n_c / (np.sum(n_t) + n_c))-
__Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_sum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_v_n_t) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_n_t); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Multiply(__pyx_float_1_, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_sum); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v_n_t) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_n_t); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_n_c); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_2); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyFloat_FromDouble((1. * __pyx_v_n_c)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_sum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_v_n_t) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_n_t); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_c); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_8.__pyx_n = 1; - __pyx_t_8.q = __pyx_t_6; - __pyx_t_7 = __pyx_f_8causalml_9inference_4tree_6uplift_entropyH(__pyx_t_5, &__pyx_t_8); if (unlikely(__pyx_t_7 == ((float)-1) && PyErr_Occurred())) __PYX_ERR(0, 801, __pyx_L1_error) -
+0802: * kl_divergence(pt_a, pc_a)-
__pyx_t_6 = __pyx_f_8causalml_9inference_4tree_6uplift_kl_divergence(__pyx_v_pt_a, __pyx_v_pc_a); if (unlikely(__pyx_t_6 == ((float)-1) && PyErr_Occurred())) __PYX_ERR(0, 802, __pyx_L1_error) -
0803: )-
0804: # Normalization Part 2 & 3-
+0805: for i in range(len(n_t)):-
if (unlikely(__pyx_v_n_t == Py_None)) { - PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 805, __pyx_L1_error) - } - __pyx_t_9 = PyList_GET_SIZE(__pyx_v_n_t); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 805, __pyx_L1_error) - __pyx_t_10 = __pyx_t_9; - for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { - __pyx_v_i = __pyx_t_11; -
+0806: pt_a_i = 1. * n_t_left[i] / (n_t[i] + 0.1)-
if (unlikely(__pyx_v_n_t_left == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 806, __pyx_L1_error) - } - __pyx_t_1 = PyNumber_Multiply(__pyx_float_1_, PyList_GET_ITEM(__pyx_v_n_t_left, __pyx_v_i)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (unlikely(__pyx_v_n_t == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 806, __pyx_L1_error) - } - __pyx_t_3 = __Pyx_PyFloat_AddObjC(PyList_GET_ITEM(__pyx_v_n_t, __pyx_v_i), __pyx_float_0_1, 0.1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 806, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_pt_a_i, __pyx_t_2); - __pyx_t_2 = 0; -
+0807: norm_res += (-
__pyx_v_norm_res = (__pyx_v_norm_res + (((1.0 - __pyx_v_alpha) * __pyx_t_5) * __pyx_t_6)); -
+0808: (1 - alpha) * entropyH(1. * n_t[i] / (n_t[i] + n_c), 1. * n_c / (n_t[i] + n_c))-
if (unlikely(__pyx_v_n_t == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 808, __pyx_L1_error) - } - __pyx_t_2 = PyNumber_Multiply(__pyx_float_1_, PyList_GET_ITEM(__pyx_v_n_t, __pyx_v_i)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (unlikely(__pyx_v_n_t == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 808, __pyx_L1_error) - } - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_c); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyNumber_Add(PyList_GET_ITEM(__pyx_v_n_t, __pyx_v_i), __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyFloat_FromDouble((1. * __pyx_v_n_c)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(__pyx_v_n_t == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 808, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_c); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Add(PyList_GET_ITEM(__pyx_v_n_t, __pyx_v_i), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_7 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_8.__pyx_n = 1; - __pyx_t_8.q = __pyx_t_7; - __pyx_t_5 = __pyx_f_8causalml_9inference_4tree_6uplift_entropyH(__pyx_t_6, &__pyx_t_8); if (unlikely(__pyx_t_5 == ((float)-1) && PyErr_Occurred())) __PYX_ERR(0, 808, __pyx_L1_error) -
+0809: * kl_divergence(1. * pt_a_i, pc_a)-
__pyx_t_1 = PyNumber_Multiply(__pyx_float_1_, __pyx_v_pt_a_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 809, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __pyx_PyFloat_AsFloat(__pyx_t_1); if (unlikely((__pyx_t_7 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 809, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __pyx_f_8causalml_9inference_4tree_6uplift_kl_divergence(__pyx_t_7, __pyx_v_pc_a); if (unlikely(__pyx_t_6 == ((float)-1) && PyErr_Occurred())) __PYX_ERR(0, 809, __pyx_L1_error) -
0810: )-
+0811: norm_res += (1. * n_t[i] / (np.sum(n_t) + n_c) * entropyH(pt_a_i))-
__pyx_t_1 = PyFloat_FromDouble(__pyx_v_norm_res); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (unlikely(__pyx_v_n_t == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 811, __pyx_L1_error) - } - __pyx_t_2 = PyNumber_Multiply(__pyx_float_1_, PyList_GET_ITEM(__pyx_v_n_t, __pyx_v_i)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_sum); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_4, __pyx_v_n_t) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_v_n_t); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_n_c); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_v_pt_a_i); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 811, __pyx_L1_error) - __pyx_t_5 = __pyx_f_8causalml_9inference_4tree_6uplift_entropyH(__pyx_t_6, NULL); if (unlikely(__pyx_t_5 == ((float)-1) && PyErr_Occurred())) __PYX_ERR(0, 811, __pyx_L1_error) - __pyx_t_4 = PyFloat_FromDouble(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyNumber_Multiply(__pyx_t_12, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 811, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_norm_res = __pyx_t_5; - } -
0812: # Normalization Part 4-
+0813: norm_res += 1. * n_c/(np.sum(n_t) + n_c) * entropyH(pc_a)-
__pyx_t_4 = PyFloat_FromDouble(__pyx_v_norm_res); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyFloat_FromDouble((1. * __pyx_v_n_c)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_sum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_1 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_12, __pyx_v_n_t) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_n_t); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_c); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_12 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_5 = __pyx_f_8causalml_9inference_4tree_6uplift_entropyH(__pyx_v_pc_a, NULL); if (unlikely(__pyx_t_5 == ((float)-1) && PyErr_Occurred())) __PYX_ERR(0, 813, __pyx_L1_error) - __pyx_t_12 = PyFloat_FromDouble(__pyx_t_5); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_2 = PyNumber_Multiply(__pyx_t_3, __pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = PyNumber_InPlaceAdd(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_12); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 813, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_v_norm_res = __pyx_t_5; -
0814:
-0815: # Normalization Part 5-
+0816: norm_res += 0.5-
__pyx_v_norm_res = (__pyx_v_norm_res + 0.5); -
+0817: return norm_res-
__Pyx_XDECREF(__pyx_r); - __pyx_t_12 = PyFloat_FromDouble(__pyx_v_norm_res); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 817, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_r = __pyx_t_12; - __pyx_t_12 = 0; - goto __pyx_L0; -
0818:
-+0819: def tree_node_summary(self, treatment_idx, y, min_samples_treatment=10, n_reg=100, parentNodeSummary=None):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_31tree_node_summary(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_30tree_node_summary[] = "\n Tree node summary statistics.\n\n Args\n ----\n treatment_idx : array-like, shape = [num_samples]\n An array containing the treatment group index for each unit.\n y : array-like, shape = [num_samples]\n An array containing the outcome of interest for each unit.\n min_samples_treatment: int, optional (default=10)\n The minimum number of samples required of the experiment group t be split at a leaf node.\n n_reg : int, optional (default=10)\n The regularization parameter defined in Rzepakowski et al. 2012,\n the weight (in terms of sample size) of the parent node influence\n on the child node, only effective for 'KL', 'ED', 'Chi', 'CTS' methods.\n parentNodeSummary : list of list\n The positive probabilities and sample sizes of each of the control and treatment groups\n in the parent node.\n\n Returns\n -------\n nodeSummary : list of list\n The positive probabilities and sample sizes of each of the control and treatment groups\n in the current node.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_31tree_node_summary = {"tree_node_summary", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_31tree_node_summary, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_30tree_node_summary}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_31tree_node_summary(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_treatment_idx = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_v_min_samples_treatment = 0; - PyObject *__pyx_v_n_reg = 0; - PyObject *__pyx_v_parentNodeSummary = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("tree_node_summary (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_treatment_idx,&__pyx_n_s_y,&__pyx_n_s_min_samples_treatment,&__pyx_n_s_n_reg,&__pyx_n_s_parentNodeSummary,0}; - PyObject* values[6] = {0,0,0,0,0,0}; - values[3] = ((PyObject *)((PyObject *)__pyx_int_10)); - values[4] = ((PyObject *)((PyObject *)__pyx_int_100)); - values[5] = ((PyObject *)((PyObject *)Py_None)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment_idx)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("tree_node_summary", 0, 3, 6, 1); __PYX_ERR(0, 819, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("tree_node_summary", 0, 3, 6, 2); __PYX_ERR(0, 819, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_samples_treatment); - if (value) { values[3] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_reg); - if (value) { values[4] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parentNodeSummary); - if (value) { values[5] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tree_node_summary") < 0)) __PYX_ERR(0, 819, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_treatment_idx = values[1]; - __pyx_v_y = values[2]; - __pyx_v_min_samples_treatment = values[3]; - __pyx_v_n_reg = values[4]; - __pyx_v_parentNodeSummary = values[5]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("tree_node_summary", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 819, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.tree_node_summary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_30tree_node_summary(__pyx_self, __pyx_v_self, __pyx_v_treatment_idx, __pyx_v_y, __pyx_v_min_samples_treatment, __pyx_v_n_reg, __pyx_v_parentNodeSummary); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_30tree_node_summary(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_treatment_idx, PyObject *__pyx_v_y, PyObject *__pyx_v_min_samples_treatment, PyObject *__pyx_v_n_reg, PyObject *__pyx_v_parentNodeSummary) { - PyObject *__pyx_v_counts = NULL; - PyObject *__pyx_v_nodeSummary = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_count = NULL; - PyObject *__pyx_v_n_pos = NULL; - PyObject *__pyx_v_n = NULL; - PyObject *__pyx_v_p = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("tree_node_summary", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.tree_node_summary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_counts); - __Pyx_XDECREF(__pyx_v_nodeSummary); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_count); - __Pyx_XDECREF(__pyx_v_n_pos); - __Pyx_XDECREF(__pyx_v_n); - __Pyx_XDECREF(__pyx_v_p); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__53 = PyTuple_Pack(13, __pyx_n_s_self, __pyx_n_s_treatment_idx, __pyx_n_s_y, __pyx_n_s_min_samples_treatment, __pyx_n_s_n_reg, __pyx_n_s_parentNodeSummary, __pyx_n_s_counts, __pyx_n_s_nodeSummary, __pyx_n_s_i, __pyx_n_s_count, __pyx_n_s_n_pos, __pyx_n_s_n, __pyx_n_s_p); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 819, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__53); - __Pyx_GIVEREF(__pyx_tuple__53); - __pyx_codeobj__54 = (PyObject*)__Pyx_PyCode_New(6, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__53, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_tree_node_summary, 819, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__54)) __PYX_ERR(0, 819, __pyx_L1_error) -/* … */ - __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_31tree_node_summary, 0, __pyx_n_s_UpliftTreeClassifier_tree_node_s, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__54)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 819, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_tuple__55); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_tree_node_summary, __pyx_t_5) < 0) __PYX_ERR(0, 819, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_tuple__55 = PyTuple_Pack(3, ((PyObject *)__pyx_int_10), ((PyObject *)__pyx_int_100), ((PyObject *)Py_None)); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 819, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__55); - __Pyx_GIVEREF(__pyx_tuple__55); -
0820: '''-
0821: Tree node summary statistics.-
0822:
-0823: Args-
0824: -----
0825: treatment_idx : array-like, shape = [num_samples]-
0826: An array containing the treatment group index for each unit.-
0827: y : array-like, shape = [num_samples]-
0828: An array containing the outcome of interest for each unit.-
0829: min_samples_treatment: int, optional (default=10)-
0830: The minimum number of samples required of the experiment group t be split at a leaf node.-
0831: n_reg : int, optional (default=10)-
0832: The regularization parameter defined in Rzepakowski et al. 2012,-
0833: the weight (in terms of sample size) of the parent node influence-
0834: on the child node, only effective for 'KL', 'ED', 'Chi', 'CTS' methods.-
0835: parentNodeSummary : list of list-
0836: The positive probabilities and sample sizes of each of the control and treatment groups-
0837: in the parent node.-
0838:
-0839: Returns-
0840: --------
0841: nodeSummary : list of list-
0842: The positive probabilities and sample sizes of each of the control and treatment groups-
0843: in the current node.-
0844: '''-
0845: # counts: [[N(Y=0, T=0), N(Y=1, T=0)], [N(Y=0, T=1), N(Y=1, T=1)], ...]-
+0846: counts = self.group_uniqueCounts(treatment_idx, y)-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_group_uniqueCounts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 846, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_4 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_4 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 846, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 846, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 846, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_y); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 846, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_counts = __pyx_t_1; - __pyx_t_1 = 0; -
0847:
-0848: # nodeSummary: [[P(Y=1|T=0), N(T=0)], [P(Y=1|T=1), N(T=1)], ...]-
+0849: nodeSummary = []-
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 849, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_nodeSummary = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; -
0850: # Iterate the control and treatment groups-
+0851: for i, count in enumerate(counts):-
__Pyx_INCREF(__pyx_int_0); - __pyx_t_1 = __pyx_int_0; - if (likely(PyList_CheckExact(__pyx_v_counts)) || PyTuple_CheckExact(__pyx_v_counts)) { - __pyx_t_2 = __pyx_v_counts; __Pyx_INCREF(__pyx_t_2); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_counts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 851, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 851, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_7)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 851, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 851, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } else { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 851, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 851, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } - } else { - __pyx_t_5 = __pyx_t_7(__pyx_t_2); - if (unlikely(!__pyx_t_5)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 851, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - __Pyx_XDECREF_SET(__pyx_v_count, __pyx_t_5); - __pyx_t_5 = 0; - __Pyx_INCREF(__pyx_t_1); - __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1); - __pyx_t_5 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 851, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_t_5; - __pyx_t_5 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0852: n_pos = count[1]-
__pyx_t_5 = __Pyx_GetItemInt(__pyx_v_count, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 852, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_XDECREF_SET(__pyx_v_n_pos, __pyx_t_5); - __pyx_t_5 = 0; -
+0853: n = count[0] + n_pos-
__pyx_t_5 = __Pyx_GetItemInt(__pyx_v_count, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 853, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyNumber_Add(__pyx_t_5, __pyx_v_n_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 853, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_3); - __pyx_t_3 = 0; -
+0854: if parentNodeSummary is None:-
__pyx_t_8 = (__pyx_v_parentNodeSummary == Py_None); - __pyx_t_9 = (__pyx_t_8 != 0); - if (__pyx_t_9) { -/* … */ - goto __pyx_L5; - } -
+0855: p = n_pos / n if n > 0 else 0.-
__pyx_t_5 = PyObject_RichCompare(__pyx_v_n, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 855, __pyx_L1_error) - __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 855, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_9) { - __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_v_n_pos, __pyx_v_n); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 855, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __pyx_t_5; - __pyx_t_5 = 0; - } else { - __Pyx_INCREF(__pyx_float_0_); - __pyx_t_3 = __pyx_float_0_; - } - __Pyx_XDECREF_SET(__pyx_v_p, __pyx_t_3); - __pyx_t_3 = 0; -
+0856: elif n > min_samples_treatment:-
__pyx_t_3 = PyObject_RichCompare(__pyx_v_n, __pyx_v_min_samples_treatment, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 856, __pyx_L1_error) - __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 856, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_9) { -/* … */ - goto __pyx_L5; - } -
+0857: p = (n_pos + parentNodeSummary[i][0] * n_reg) / (n + n_reg)-
__pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_parentNodeSummary, __pyx_v_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 857, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 857, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Multiply(__pyx_t_5, __pyx_v_n_reg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 857, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Add(__pyx_v_n_pos, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 857, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Add(__pyx_v_n, __pyx_v_n_reg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 857, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = __Pyx_PyNumber_Divide(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 857, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_p, __pyx_t_10); - __pyx_t_10 = 0; -
0858: else:-
+0859: p = parentNodeSummary[i][0]-
/*else*/ { - __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_v_parentNodeSummary, __pyx_v_i); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 859, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_10, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 859, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF_SET(__pyx_v_p, __pyx_t_3); - __pyx_t_3 = 0; - } - __pyx_L5:; -
0860:
-+0861: nodeSummary.append([p, n])-
__pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 861, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_p); - __Pyx_GIVEREF(__pyx_v_p); - PyList_SET_ITEM(__pyx_t_3, 0, __pyx_v_p); - __Pyx_INCREF(__pyx_v_n); - __Pyx_GIVEREF(__pyx_v_n); - PyList_SET_ITEM(__pyx_t_3, 1, __pyx_v_n); - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_nodeSummary, __pyx_t_3); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 861, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -
0862:
-+0863: return nodeSummary-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_nodeSummary); - __pyx_r = __pyx_v_nodeSummary; - goto __pyx_L0; -
0864:
-+0865: def uplift_classification_results(self, treatment_idx, y):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_33uplift_classification_results(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_32uplift_classification_results[] = "\n Classification probability for each treatment in the tree node.\n\n Args\n ----\n treatment_idx : array-like, shape = [num_samples]\n An array containing the treatment group index for each unit.\n y : array-like, shape = [num_samples]\n An array containing the outcome of interest for each unit.\n\n Returns\n -------\n res : list of list\n The positive probabilities P(Y = 1) of each of the control and treatment groups\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_33uplift_classification_results = {"uplift_classification_results", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_33uplift_classification_results, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_32uplift_classification_results}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_33uplift_classification_results(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_treatment_idx = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("uplift_classification_results (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_treatment_idx,&__pyx_n_s_y,0}; - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment_idx)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("uplift_classification_results", 1, 3, 3, 1); __PYX_ERR(0, 865, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("uplift_classification_results", 1, 3, 3, 2); __PYX_ERR(0, 865, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "uplift_classification_results") < 0)) __PYX_ERR(0, 865, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - } - __pyx_v_self = values[0]; - __pyx_v_treatment_idx = values[1]; - __pyx_v_y = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("uplift_classification_results", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 865, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.uplift_classification_results", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_32uplift_classification_results(__pyx_self, __pyx_v_self, __pyx_v_treatment_idx, __pyx_v_y); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_32uplift_classification_results(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_treatment_idx, PyObject *__pyx_v_y) { - PyObject *__pyx_v_counts = NULL; - PyObject *__pyx_v_res = NULL; - PyObject *__pyx_v_count = NULL; - PyObject *__pyx_v_n_pos = NULL; - PyObject *__pyx_v_n = NULL; - PyObject *__pyx_v_p = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("uplift_classification_results", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.uplift_classification_results", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_counts); - __Pyx_XDECREF(__pyx_v_res); - __Pyx_XDECREF(__pyx_v_count); - __Pyx_XDECREF(__pyx_v_n_pos); - __Pyx_XDECREF(__pyx_v_n); - __Pyx_XDECREF(__pyx_v_p); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__56 = PyTuple_Pack(9, __pyx_n_s_self, __pyx_n_s_treatment_idx, __pyx_n_s_y, __pyx_n_s_counts, __pyx_n_s_res, __pyx_n_s_count, __pyx_n_s_n_pos, __pyx_n_s_n, __pyx_n_s_p); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__56); - __Pyx_GIVEREF(__pyx_tuple__56); -/* … */ - __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_33uplift_classification_results, 0, __pyx_n_s_UpliftTreeClassifier_uplift_clas, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__57)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_uplift_classification_results, __pyx_t_5) < 0) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_codeobj__57 = (PyObject*)__Pyx_PyCode_New(3, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__56, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_uplift_classification_results, 865, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__57)) __PYX_ERR(0, 865, __pyx_L1_error) -
0866: '''-
0867: Classification probability for each treatment in the tree node.-
0868:
-0869: Args-
0870: -----
0871: treatment_idx : array-like, shape = [num_samples]-
0872: An array containing the treatment group index for each unit.-
0873: y : array-like, shape = [num_samples]-
0874: An array containing the outcome of interest for each unit.-
0875:
-0876: Returns-
0877: --------
0878: res : list of list-
0879: The positive probabilities P(Y = 1) of each of the control and treatment groups-
0880: '''-
0881: # counts: [[N(Y=0, T=0), N(Y=1, T=0)], [N(Y=0, T=1), N(Y=1, T=1)], ...]-
+0882: counts = self.group_uniqueCounts(treatment_idx, y)-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_group_uniqueCounts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 882, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_4 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_4 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 882, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 882, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 882, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_y); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 882, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_counts = __pyx_t_1; - __pyx_t_1 = 0; -
+0883: res = []-
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 883, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_res = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; -
+0884: for count in counts:-
if (likely(PyList_CheckExact(__pyx_v_counts)) || PyTuple_CheckExact(__pyx_v_counts)) { - __pyx_t_1 = __pyx_v_counts; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_counts); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 884, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 884, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_7)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 884, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 884, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 884, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 884, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_7(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 884, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_count, __pyx_t_2); - __pyx_t_2 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+0885: n_pos = count[1]-
__pyx_t_2 = __Pyx_GetItemInt(__pyx_v_count, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 885, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XDECREF_SET(__pyx_v_n_pos, __pyx_t_2); - __pyx_t_2 = 0; -
+0886: n = count[0] + n_pos-
__pyx_t_2 = __Pyx_GetItemInt(__pyx_v_count, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 886, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyNumber_Add(__pyx_t_2, __pyx_v_n_pos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 886, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_5); - __pyx_t_5 = 0; -
+0887: p = n_pos / n if n > 0 else 0.-
__pyx_t_2 = PyObject_RichCompare(__pyx_v_n, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 887, __pyx_L1_error) - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 887, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_8) { - __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_v_n_pos, __pyx_v_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 887, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __pyx_t_2; - __pyx_t_2 = 0; - } else { - __Pyx_INCREF(__pyx_float_0_); - __pyx_t_5 = __pyx_float_0_; - } - __Pyx_XDECREF_SET(__pyx_v_p, __pyx_t_5); - __pyx_t_5 = 0; -
+0888: res.append(p)-
__pyx_t_9 = __Pyx_PyList_Append(__pyx_v_res, __pyx_v_p); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 888, __pyx_L1_error) -
+0889: return res-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_res); - __pyx_r = __pyx_v_res; - goto __pyx_L0; -
0890:
-+0891: def growDecisionTreeFrom(self, X, treatment_idx, y, max_depth=10,-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_35growDecisionTreeFrom(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_34growDecisionTreeFrom[] = "\n Train the uplift decision tree.\n\n Args\n ----\n X : ndarray, shape = [num_samples, num_features]\n An ndarray of the covariates used to train the uplift model.\n treatment_idx : array-like, shape = [num_samples]\n An array containing the treatment group idx for each unit.\n y : array-like, shape = [num_samples]\n An array containing the outcome of interest for each unit.\n max_depth: int, optional (default=10)\n The maximum depth of the tree.\n min_samples_leaf: int, optional (default=100)\n The minimum number of samples required to be split at a leaf node.\n depth : int, optional (default = 1)\n The current depth.\n min_samples_treatment: int, optional (default=10)\n The minimum number of samples required of the experiment group to be split at a leaf node.\n n_reg: int, optional (default=10)\n The regularization parameter defined in Rzepakowski et al. 2012,\n the weight (in terms of sample size) of the parent node influence\n on the child node, only effective for 'KL', 'ED', 'Chi', 'CTS' methods.\n parentNodeSummary : dictionary, optional (default = None)\n Node summary statistics of the parent tree node.\n\n Returns\n -------\n object of DecisionTree class\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_35growDecisionTreeFrom = {"growDecisionTreeFrom", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_35growDecisionTreeFrom, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_34growDecisionTreeFrom}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_35growDecisionTreeFrom(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment_idx = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_v_max_depth = 0; - PyObject *__pyx_v_min_samples_leaf = 0; - PyObject *__pyx_v_depth = 0; - PyObject *__pyx_v_min_samples_treatment = 0; - PyObject *__pyx_v_n_reg = 0; - PyObject *__pyx_v_parentNodeSummary = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("growDecisionTreeFrom (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_treatment_idx,&__pyx_n_s_y,&__pyx_n_s_max_depth,&__pyx_n_s_min_samples_leaf,&__pyx_n_s_depth,&__pyx_n_s_min_samples_treatment,&__pyx_n_s_n_reg,&__pyx_n_s_parentNodeSummary,0}; - PyObject* values[10] = {0,0,0,0,0,0,0,0,0,0}; - values[4] = ((PyObject *)((PyObject *)__pyx_int_10)); - values[5] = ((PyObject *)((PyObject *)__pyx_int_100)); - values[6] = ((PyObject *)((PyObject *)__pyx_int_1)); - values[7] = ((PyObject *)((PyObject *)__pyx_int_10)); - values[8] = ((PyObject *)((PyObject *)__pyx_int_100)); -/* … */ - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_34growDecisionTreeFrom(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment_idx, PyObject *__pyx_v_y, PyObject *__pyx_v_max_depth, PyObject *__pyx_v_min_samples_leaf, PyObject *__pyx_v_depth, PyObject *__pyx_v_min_samples_treatment, PyObject *__pyx_v_n_reg, PyObject *__pyx_v_parentNodeSummary) { - PyObject *__pyx_v_currentNodeSummary = NULL; - PyObject *__pyx_v_currentScore = NULL; - PyObject *__pyx_v_maxAbsDiff = NULL; - PyObject *__pyx_v_maxDiff = NULL; - PyObject *__pyx_v_bestTreatment = NULL; - PyObject *__pyx_v_suboptTreatment = NULL; - PyObject *__pyx_v_maxDiffTreatment = NULL; - PyObject *__pyx_v_maxDiffSign = NULL; - PyObject *__pyx_v_p_c = NULL; - PyObject *__pyx_v_n_c = NULL; - PyObject *__pyx_v_i_tr = NULL; - PyObject *__pyx_v_p_t = NULL; - CYTHON_UNUSED PyObject *__pyx_v__ = NULL; - PyObject *__pyx_v_diff = NULL; - PyObject *__pyx_v_n_t = NULL; - PyObject *__pyx_v_p_value = NULL; - PyObject *__pyx_v_upliftScore = NULL; - PyObject *__pyx_v_bestGain = NULL; - PyObject *__pyx_v_bestGainImp = NULL; - PyObject *__pyx_v_bestAttribute = NULL; - PyObject *__pyx_v_columnCount = NULL; - PyObject *__pyx_v_max_features = NULL; - PyObject *__pyx_v_col = NULL; - PyObject *__pyx_v_columnValues = NULL; - PyObject *__pyx_v_lsUnique = NULL; - PyObject *__pyx_v_lspercentile = NULL; - PyObject *__pyx_v_value = NULL; - PyObject *__pyx_v_X_l = NULL; - PyObject *__pyx_v_X_r = NULL; - PyObject *__pyx_v_w_l = NULL; - PyObject *__pyx_v_w_r = NULL; - PyObject *__pyx_v_y_l = NULL; - PyObject *__pyx_v_y_r = NULL; - double __pyx_v_p; - PyObject *__pyx_v_leftNodeSummary = NULL; - PyObject *__pyx_v_rightNodeSummary = NULL; - PyObject *__pyx_v_node_mst = NULL; - PyObject *__pyx_v_leftScore1 = NULL; - PyObject *__pyx_v_rightScore2 = NULL; - PyObject *__pyx_v_gain = NULL; - PyObject *__pyx_v_gain_for_imp = NULL; - PyObject *__pyx_v_n_c_left = NULL; - PyObject *__pyx_v_n_t_left = NULL; - PyObject *__pyx_v_norm_factor = NULL; - PyObject *__pyx_v_best_set_left = NULL; - PyObject *__pyx_v_best_set_right = NULL; - PyObject *__pyx_v_dcY = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_summary = NULL; - PyObject *__pyx_v_trueBranch = NULL; - PyObject *__pyx_v_falseBranch = NULL; - PyObject *__pyx_v_stat = NULL; - PyObject *__pyx_v_tr = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("growDecisionTreeFrom", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_16); - __Pyx_XDECREF(__pyx_t_17); - __Pyx_XDECREF(__pyx_t_21); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.growDecisionTreeFrom", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_currentNodeSummary); - __Pyx_XDECREF(__pyx_v_currentScore); - __Pyx_XDECREF(__pyx_v_maxAbsDiff); - __Pyx_XDECREF(__pyx_v_maxDiff); - __Pyx_XDECREF(__pyx_v_bestTreatment); - __Pyx_XDECREF(__pyx_v_suboptTreatment); - __Pyx_XDECREF(__pyx_v_maxDiffTreatment); - __Pyx_XDECREF(__pyx_v_maxDiffSign); - __Pyx_XDECREF(__pyx_v_p_c); - __Pyx_XDECREF(__pyx_v_n_c); - __Pyx_XDECREF(__pyx_v_i_tr); - __Pyx_XDECREF(__pyx_v_p_t); - __Pyx_XDECREF(__pyx_v__); - __Pyx_XDECREF(__pyx_v_diff); - __Pyx_XDECREF(__pyx_v_n_t); - __Pyx_XDECREF(__pyx_v_p_value); - __Pyx_XDECREF(__pyx_v_upliftScore); - __Pyx_XDECREF(__pyx_v_bestGain); - __Pyx_XDECREF(__pyx_v_bestGainImp); - __Pyx_XDECREF(__pyx_v_bestAttribute); - __Pyx_XDECREF(__pyx_v_columnCount); - __Pyx_XDECREF(__pyx_v_max_features); - __Pyx_XDECREF(__pyx_v_col); - __Pyx_XDECREF(__pyx_v_columnValues); - __Pyx_XDECREF(__pyx_v_lsUnique); - __Pyx_XDECREF(__pyx_v_lspercentile); - __Pyx_XDECREF(__pyx_v_value); - __Pyx_XDECREF(__pyx_v_X_l); - __Pyx_XDECREF(__pyx_v_X_r); - __Pyx_XDECREF(__pyx_v_w_l); - __Pyx_XDECREF(__pyx_v_w_r); - __Pyx_XDECREF(__pyx_v_y_l); - __Pyx_XDECREF(__pyx_v_y_r); - __Pyx_XDECREF(__pyx_v_leftNodeSummary); - __Pyx_XDECREF(__pyx_v_rightNodeSummary); - __Pyx_XDECREF(__pyx_v_node_mst); - __Pyx_XDECREF(__pyx_v_leftScore1); - __Pyx_XDECREF(__pyx_v_rightScore2); - __Pyx_XDECREF(__pyx_v_gain); - __Pyx_XDECREF(__pyx_v_gain_for_imp); - __Pyx_XDECREF(__pyx_v_n_c_left); - __Pyx_XDECREF(__pyx_v_n_t_left); - __Pyx_XDECREF(__pyx_v_norm_factor); - __Pyx_XDECREF(__pyx_v_best_set_left); - __Pyx_XDECREF(__pyx_v_best_set_right); - __Pyx_XDECREF(__pyx_v_dcY); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_summary); - __Pyx_XDECREF(__pyx_v_trueBranch); - __Pyx_XDECREF(__pyx_v_falseBranch); - __Pyx_XDECREF(__pyx_v_stat); - __Pyx_XDECREF(__pyx_v_tr); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__58 = PyTuple_Pack(63, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_treatment_idx, __pyx_n_s_y, __pyx_n_s_max_depth, __pyx_n_s_min_samples_leaf, __pyx_n_s_depth, __pyx_n_s_min_samples_treatment, __pyx_n_s_n_reg, __pyx_n_s_parentNodeSummary, __pyx_n_s_currentNodeSummary, __pyx_n_s_currentScore, __pyx_n_s_maxAbsDiff, __pyx_n_s_maxDiff, __pyx_n_s_bestTreatment, __pyx_n_s_suboptTreatment, __pyx_n_s_maxDiffTreatment, __pyx_n_s_maxDiffSign, __pyx_n_s_p_c, __pyx_n_s_n_c, __pyx_n_s_i_tr, __pyx_n_s_p_t, __pyx_n_s__34, __pyx_n_s_diff, __pyx_n_s_n_t, __pyx_n_s_p_value, __pyx_n_s_upliftScore, __pyx_n_s_bestGain, __pyx_n_s_bestGainImp, __pyx_n_s_bestAttribute, __pyx_n_s_columnCount, __pyx_n_s_max_features, __pyx_n_s_col, __pyx_n_s_columnValues, __pyx_n_s_lsUnique, __pyx_n_s_lspercentile, __pyx_n_s_value, __pyx_n_s_X_l, __pyx_n_s_X_r, __pyx_n_s_w_l, __pyx_n_s_w_r, __pyx_n_s_y_l, __pyx_n_s_y_r, __pyx_n_s_p, __pyx_n_s_leftNodeSummary, __pyx_n_s_rightNodeSummary, __pyx_n_s_node_mst, __pyx_n_s_leftScore1, __pyx_n_s_rightScore2, __pyx_n_s_gain, __pyx_n_s_gain_for_imp, __pyx_n_s_n_c_left, __pyx_n_s_n_t_left, __pyx_n_s_norm_factor, __pyx_n_s_best_set_left, __pyx_n_s_best_set_right, __pyx_n_s_dcY, __pyx_n_s_i, __pyx_n_s_summary, __pyx_n_s_trueBranch, __pyx_n_s_falseBranch, __pyx_n_s_stat, __pyx_n_s_tr); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(0, 891, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__58); - __Pyx_GIVEREF(__pyx_tuple__58); - __pyx_codeobj__59 = (PyObject*)__Pyx_PyCode_New(10, 0, 63, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__58, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_growDecisionTreeFrom, 891, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__59)) __PYX_ERR(0, 891, __pyx_L1_error) -/* … */ - __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_35growDecisionTreeFrom, 0, __pyx_n_s_UpliftTreeClassifier_growDecisio, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__59)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 891, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_tuple__60); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_growDecisionTreeFrom, __pyx_t_5) < 0) __PYX_ERR(0, 891, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_tuple__60 = PyTuple_Pack(6, ((PyObject *)__pyx_int_10), ((PyObject *)__pyx_int_100), ((PyObject *)__pyx_int_1), ((PyObject *)__pyx_int_10), ((PyObject *)__pyx_int_100), ((PyObject *)Py_None)); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(0, 891, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__60); - __Pyx_GIVEREF(__pyx_tuple__60); -
0892: min_samples_leaf=100, depth=1,-
0893: min_samples_treatment=10, n_reg=100,-
+0894: parentNodeSummary=None):-
values[9] = ((PyObject *)((PyObject *)Py_None)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - CYTHON_FALLTHROUGH; - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("growDecisionTreeFrom", 0, 4, 10, 1); __PYX_ERR(0, 891, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment_idx)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("growDecisionTreeFrom", 0, 4, 10, 2); __PYX_ERR(0, 891, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("growDecisionTreeFrom", 0, 4, 10, 3); __PYX_ERR(0, 891, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_depth); - if (value) { values[4] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_samples_leaf); - if (value) { values[5] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 6: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_depth); - if (value) { values[6] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 7: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_samples_treatment); - if (value) { values[7] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 8: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_reg); - if (value) { values[8] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 9: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parentNodeSummary); - if (value) { values[9] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "growDecisionTreeFrom") < 0)) __PYX_ERR(0, 891, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - CYTHON_FALLTHROUGH; - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_treatment_idx = values[2]; - __pyx_v_y = values[3]; - __pyx_v_max_depth = values[4]; - __pyx_v_min_samples_leaf = values[5]; - __pyx_v_depth = values[6]; - __pyx_v_min_samples_treatment = values[7]; - __pyx_v_n_reg = values[8]; - __pyx_v_parentNodeSummary = values[9]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("growDecisionTreeFrom", 0, 4, 10, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 891, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.growDecisionTreeFrom", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_34growDecisionTreeFrom(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_treatment_idx, __pyx_v_y, __pyx_v_max_depth, __pyx_v_min_samples_leaf, __pyx_v_depth, __pyx_v_min_samples_treatment, __pyx_v_n_reg, __pyx_v_parentNodeSummary); -
0895: '''-
0896: Train the uplift decision tree.-
0897:
-0898: Args-
0899: -----
0900: X : ndarray, shape = [num_samples, num_features]-
0901: An ndarray of the covariates used to train the uplift model.-
0902: treatment_idx : array-like, shape = [num_samples]-
0903: An array containing the treatment group idx for each unit.-
0904: y : array-like, shape = [num_samples]-
0905: An array containing the outcome of interest for each unit.-
0906: max_depth: int, optional (default=10)-
0907: The maximum depth of the tree.-
0908: min_samples_leaf: int, optional (default=100)-
0909: The minimum number of samples required to be split at a leaf node.-
0910: depth : int, optional (default = 1)-
0911: The current depth.-
0912: min_samples_treatment: int, optional (default=10)-
0913: The minimum number of samples required of the experiment group to be split at a leaf node.-
0914: n_reg: int, optional (default=10)-
0915: The regularization parameter defined in Rzepakowski et al. 2012,-
0916: the weight (in terms of sample size) of the parent node influence-
0917: on the child node, only effective for 'KL', 'ED', 'Chi', 'CTS' methods.-
0918: parentNodeSummary : dictionary, optional (default = None)-
0919: Node summary statistics of the parent tree node.-
0920:
-0921: Returns-
0922: --------
0923: object of DecisionTree class-
0924: '''-
0925:
-+0926: if len(X) == 0:-
__pyx_t_1 = PyObject_Length(__pyx_v_X); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 926, __pyx_L1_error) - __pyx_t_2 = ((__pyx_t_1 == 0) != 0); - if (__pyx_t_2) { -/* … */ - } -
+0927: return DecisionTree(classes_=self.classes_)-
__Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_DecisionTree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 927, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 927, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 927, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_classes, __pyx_t_5) < 0) __PYX_ERR(0, 927, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 927, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; -
0928:
-0929: # Current node summary: [P(Y=1|T), N(T)]-
+0930: currentNodeSummary = self.tree_node_summary(treatment_idx, y,-
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tree_node_summary); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 930, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 930, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_y); -/* … */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 930, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_currentNodeSummary = __pyx_t_6; - __pyx_t_6 = 0; -
+0931: min_samples_treatment=min_samples_treatment,-
__pyx_t_3 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 931, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_min_samples_treatment, __pyx_v_min_samples_treatment) < 0) __PYX_ERR(0, 931, __pyx_L1_error) -
+0932: n_reg=n_reg,-
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 931, __pyx_L1_error) -
+0933: parentNodeSummary=parentNodeSummary)-
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_parentNodeSummary, __pyx_v_parentNodeSummary) < 0) __PYX_ERR(0, 931, __pyx_L1_error) -
+0934: currentScore = self.evaluationFunction(currentNodeSummary)-
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 934, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_v_currentNodeSummary) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_currentNodeSummary); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 934, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_currentScore = __pyx_t_6; - __pyx_t_6 = 0; -
0935:
-0936: # Prune Stats-
+0937: maxAbsDiff = 0-
__Pyx_INCREF(__pyx_int_0);
- __pyx_v_maxAbsDiff = __pyx_int_0;
-
+0938: maxDiff = -1.-
__Pyx_INCREF(__pyx_float_neg_1_);
- __pyx_v_maxDiff = __pyx_float_neg_1_;
-
+0939: bestTreatment = 0 # treatment index for the control group-
__Pyx_INCREF(__pyx_int_0);
- __pyx_v_bestTreatment = __pyx_int_0;
-
+0940: suboptTreatment = 0 # treatment index for the control group-
__Pyx_INCREF(__pyx_int_0);
- __pyx_v_suboptTreatment = __pyx_int_0;
-
+0941: maxDiffTreatment = 0 # treatment index for the control group-
__Pyx_INCREF(__pyx_int_0);
- __pyx_v_maxDiffTreatment = __pyx_int_0;
-
+0942: maxDiffSign = 0-
__Pyx_INCREF(__pyx_int_0);
- __pyx_v_maxDiffSign = __pyx_int_0;
-
+0943: p_c, n_c = currentNodeSummary[0]-
__pyx_t_6 = __Pyx_GetItemInt(__pyx_v_currentNodeSummary, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 943, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { - PyObject* sequence = __pyx_t_6; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 943, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_4 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 943, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 943, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_5 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 943, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_4 = __pyx_t_7(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_5), 2) < 0) __PYX_ERR(0, 943, __pyx_L1_error) - __pyx_t_7 = NULL; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L5_unpacking_done; - __pyx_L4_unpacking_failed:; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_7 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 943, __pyx_L1_error) - __pyx_L5_unpacking_done:; - } - __pyx_v_p_c = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_v_n_c = __pyx_t_4; - __pyx_t_4 = 0; -
+0944: for i_tr in range(1, self.n_class):-
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n_class); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_1); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6); - __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_4, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) { - __pyx_t_4 = __pyx_t_6; __Pyx_INCREF(__pyx_t_4); __pyx_t_1 = 0; - __pyx_t_8 = NULL; - } else { - __pyx_t_1 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 944, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - for (;;) { - if (likely(!__pyx_t_8)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_6); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 944, __pyx_L1_error) - #else - __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - #endif - } else { - if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_6); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 944, __pyx_L1_error) - #else - __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - #endif - } - } else { - __pyx_t_6 = __pyx_t_8(__pyx_t_4); - if (unlikely(!__pyx_t_6)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 944, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_6); - } - __Pyx_XDECREF_SET(__pyx_v_i_tr, __pyx_t_6); - __pyx_t_6 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
+0945: p_t, _ = currentNodeSummary[i_tr]-
__pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_v_i_tr); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 945, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { - PyObject* sequence = __pyx_t_6; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 945, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_5 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_5); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 945, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 945, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_9 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 945, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_7 = Py_TYPE(__pyx_t_9)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_9); if (unlikely(!__pyx_t_3)) goto __pyx_L8_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_9); if (unlikely(!__pyx_t_5)) goto __pyx_L8_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_9), 2) < 0) __PYX_ERR(0, 945, __pyx_L1_error) - __pyx_t_7 = NULL; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L9_unpacking_done; - __pyx_L8_unpacking_failed:; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_7 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 945, __pyx_L1_error) - __pyx_L9_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_p_t, __pyx_t_3); - __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_5); - __pyx_t_5 = 0; -
0946: # P(Y|T=t) - P(Y|T=0)-
+0947: diff = p_t - p_c-
__pyx_t_6 = PyNumber_Subtract(__pyx_v_p_t, __pyx_v_p_c); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_XDECREF_SET(__pyx_v_diff, __pyx_t_6); - __pyx_t_6 = 0; -
+0948: if abs(diff) >= maxAbsDiff:-
__pyx_t_6 = __Pyx_PyNumber_Absolute(__pyx_v_diff); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = PyObject_RichCompare(__pyx_t_6, __pyx_v_maxAbsDiff, Py_GE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_2) { -/* … */ - } -
+0949: maxDiffTreatment = i_tr-
__Pyx_INCREF(__pyx_v_i_tr); - __Pyx_DECREF_SET(__pyx_v_maxDiffTreatment, __pyx_v_i_tr); -
+0950: maxDiffSign = np.sign(diff)-
__Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 950, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_sign); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 950, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_v_diff) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_diff); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 950, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF_SET(__pyx_v_maxDiffSign, __pyx_t_5); - __pyx_t_5 = 0; -
+0951: maxAbsDiff = abs(diff)-
__pyx_t_5 = __Pyx_PyNumber_Absolute(__pyx_v_diff); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 951, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF_SET(__pyx_v_maxAbsDiff, __pyx_t_5); - __pyx_t_5 = 0; -
+0952: if diff >= maxDiff:-
__pyx_t_5 = PyObject_RichCompare(__pyx_v_diff, __pyx_v_maxDiff, Py_GE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 952, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 952, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_2) { -/* … */ - } -
+0953: maxDiff = diff-
__Pyx_INCREF(__pyx_v_diff); - __Pyx_DECREF_SET(__pyx_v_maxDiff, __pyx_v_diff); -
+0954: suboptTreatment = i_tr-
__Pyx_INCREF(__pyx_v_i_tr); - __Pyx_DECREF_SET(__pyx_v_suboptTreatment, __pyx_v_i_tr); -
+0955: if diff > 0:-
__pyx_t_5 = PyObject_RichCompare(__pyx_v_diff, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 955, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 955, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_2) { -/* … */ - } -
+0956: bestTreatment = i_tr-
__Pyx_INCREF(__pyx_v_i_tr); - __Pyx_DECREF_SET(__pyx_v_bestTreatment, __pyx_v_i_tr); -
+0957: if maxDiff > 0:-
__pyx_t_4 = PyObject_RichCompare(__pyx_v_maxDiff, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 957, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 957, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_2) { -/* … */ - goto __pyx_L13; - } -
+0958: p_t = currentNodeSummary[bestTreatment][0]-
__pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_v_bestTreatment); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 958, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 958, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_p_t, __pyx_t_5); - __pyx_t_5 = 0; -
+0959: n_t = currentNodeSummary[bestTreatment][1]-
__pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_v_bestTreatment); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 959, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_n_t = __pyx_t_4; - __pyx_t_4 = 0; -
0960: else:-
+0961: p_t = currentNodeSummary[suboptTreatment][0]-
/*else*/ { - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_v_suboptTreatment); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 961, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 961, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_p_t, __pyx_t_5); - __pyx_t_5 = 0; -
+0962: n_t = currentNodeSummary[suboptTreatment][1]-
__pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_currentNodeSummary, __pyx_v_suboptTreatment); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 962, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 962, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_n_t = __pyx_t_4; - __pyx_t_4 = 0; - } - __pyx_L13:; -
0963:
-+0964: p_value = (1. - stats.norm.cdf(abs(p_c - p_t) / np.sqrt(p_t * (1 - p_t) / n_t + p_c * (1 - p_c) / n_c))) * 2-
__Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_stats); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_norm); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_cdf); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Subtract(__pyx_v_p_c, __pyx_v_p_t); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyNumber_Absolute(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_v_p_t, 1, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_11 = PyNumber_Multiply(__pyx_v_p_t, __pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyNumber_Divide(__pyx_t_11, __pyx_v_n_t); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_v_p_c, 1, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_12 = PyNumber_Multiply(__pyx_v_p_c, __pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyNumber_Divide(__pyx_t_12, __pyx_v_n_c); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = PyNumber_Add(__pyx_t_9, __pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - } - } - __pyx_t_3 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_11, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_12); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_PyNumber_Divide(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_3, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_10); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyFloat_SubtractCObj(__pyx_float_1_, __pyx_t_4, 1., 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Multiply(__pyx_t_5, __pyx_int_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 964, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_p_value = __pyx_t_4; - __pyx_t_4 = 0; -
+0965: upliftScore = [maxDiff, p_value]-
__pyx_t_4 = PyList_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 965, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_maxDiff); - __Pyx_GIVEREF(__pyx_v_maxDiff); - PyList_SET_ITEM(__pyx_t_4, 0, __pyx_v_maxDiff); - __Pyx_INCREF(__pyx_v_p_value); - __Pyx_GIVEREF(__pyx_v_p_value); - PyList_SET_ITEM(__pyx_t_4, 1, __pyx_v_p_value); - __pyx_v_upliftScore = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; -
0966:
-+0967: bestGain = 0.0-
__Pyx_INCREF(__pyx_float_0_0);
- __pyx_v_bestGain = __pyx_float_0_0;
-
+0968: bestGainImp = 0.0-
__Pyx_INCREF(__pyx_float_0_0);
- __pyx_v_bestGainImp = __pyx_float_0_0;
-
+0969: bestAttribute = None-
__Pyx_INCREF(Py_None);
- __pyx_v_bestAttribute = ((PyObject*)Py_None);
-
0970:
-0971: # last column is the result/target column, 2nd to the last is the treatment group-
+0972: columnCount = X.shape[1]-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 972, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_4, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 972, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_columnCount = __pyx_t_5; - __pyx_t_5 = 0; -
+0973: if (self.max_features and self.max_features > 0 and self.max_features <= columnCount):-
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_max_features); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 973, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 973, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_13) { - } else { - __pyx_t_2 = __pyx_t_13; - goto __pyx_L15_bool_binop_done; - } - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_max_features); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 973, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 973, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 973, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_13) { - } else { - __pyx_t_2 = __pyx_t_13; - goto __pyx_L15_bool_binop_done; - } - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_max_features); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 973, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_v_columnCount, Py_LE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 973, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 973, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_2 = __pyx_t_13; - __pyx_L15_bool_binop_done:; - if (__pyx_t_2) { -/* … */ - goto __pyx_L14; - } -
+0974: max_features = self.max_features-
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_max_features); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 974, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_v_max_features = __pyx_t_5; - __pyx_t_5 = 0; -
0975: else:-
+0976: max_features = columnCount-
/*else*/ {
- __Pyx_INCREF(__pyx_v_columnCount);
- __pyx_v_max_features = __pyx_v_columnCount;
- }
- __pyx_L14:;
-
0977:
-+0978: for col in list(self.random_state_.choice(a=range(columnCount), size=max_features, replace=False)):-
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_random_state_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 978, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_choice); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 978, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 978, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_v_columnCount); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 978, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_a, __pyx_t_10) < 0) __PYX_ERR(0, 978, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_size, __pyx_v_max_features) < 0) __PYX_ERR(0, 978, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_replace, Py_False) < 0) __PYX_ERR(0, 978, __pyx_L1_error) - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 978, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PySequence_List(__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 978, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = __pyx_t_5; __Pyx_INCREF(__pyx_t_10); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - for (;;) { - if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_10)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 978, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_10, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 978, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_XDECREF_SET(__pyx_v_col, __pyx_t_5); - __pyx_t_5 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; -
+0979: columnValues = X[:, col]-
__pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 979, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_slice__7); - __Pyx_GIVEREF(__pyx_slice__7); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_slice__7); - __Pyx_INCREF(__pyx_v_col); - __Pyx_GIVEREF(__pyx_v_col); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_col); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 979, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF_SET(__pyx_v_columnValues, __pyx_t_4); - __pyx_t_4 = 0; -
0980: # unique values-
+0981: lsUnique = np.unique(columnValues)-
__Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 981, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_unique); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 981, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_v_columnValues) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_columnValues); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 981, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_lsUnique, __pyx_t_4); - __pyx_t_4 = 0; -
0982:
-+0983: if np.issubdtype(lsUnique.dtype, np.number):-
__Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 983, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_issubdtype); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 983, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_lsUnique, __pyx_n_s_dtype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 983, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = NULL; - __pyx_t_14 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - __pyx_t_14 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, ((PyObject *)__pyx_ptype_5numpy_number)}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 983, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, ((PyObject *)__pyx_ptype_5numpy_number)}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 983, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_12 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 983, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_6) { - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_6); __pyx_t_6 = NULL; - } - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_14, __pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_ptype_5numpy_number)); - __Pyx_GIVEREF(((PyObject *)__pyx_ptype_5numpy_number)); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_14, ((PyObject *)__pyx_ptype_5numpy_number)); - __pyx_t_3 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_12, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 983, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 983, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_2) { -/* … */ - } -
+0984: if len(lsUnique) > 10:-
__pyx_t_15 = PyObject_Length(__pyx_v_lsUnique); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 984, __pyx_L1_error) - __pyx_t_2 = ((__pyx_t_15 > 10) != 0); - if (__pyx_t_2) { -/* … */ - goto __pyx_L21; - } -
+0985: lspercentile = np.percentile(columnValues, [3, 5, 10, 20, 30, 50, 70, 80, 90, 95, 97])-
__Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 985, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_percentile); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 985, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyList_New(11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 985, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - PyList_SET_ITEM(__pyx_t_5, 0, __pyx_int_3); - __Pyx_INCREF(__pyx_int_5); - __Pyx_GIVEREF(__pyx_int_5); - PyList_SET_ITEM(__pyx_t_5, 1, __pyx_int_5); - __Pyx_INCREF(__pyx_int_10); - __Pyx_GIVEREF(__pyx_int_10); - PyList_SET_ITEM(__pyx_t_5, 2, __pyx_int_10); - __Pyx_INCREF(__pyx_int_20); - __Pyx_GIVEREF(__pyx_int_20); - PyList_SET_ITEM(__pyx_t_5, 3, __pyx_int_20); - __Pyx_INCREF(__pyx_int_30); - __Pyx_GIVEREF(__pyx_int_30); - PyList_SET_ITEM(__pyx_t_5, 4, __pyx_int_30); - __Pyx_INCREF(__pyx_int_50); - __Pyx_GIVEREF(__pyx_int_50); - PyList_SET_ITEM(__pyx_t_5, 5, __pyx_int_50); - __Pyx_INCREF(__pyx_int_70); - __Pyx_GIVEREF(__pyx_int_70); - PyList_SET_ITEM(__pyx_t_5, 6, __pyx_int_70); - __Pyx_INCREF(__pyx_int_80); - __Pyx_GIVEREF(__pyx_int_80); - PyList_SET_ITEM(__pyx_t_5, 7, __pyx_int_80); - __Pyx_INCREF(__pyx_int_90); - __Pyx_GIVEREF(__pyx_int_90); - PyList_SET_ITEM(__pyx_t_5, 8, __pyx_int_90); - __Pyx_INCREF(__pyx_int_95); - __Pyx_GIVEREF(__pyx_int_95); - PyList_SET_ITEM(__pyx_t_5, 9, __pyx_int_95); - __Pyx_INCREF(__pyx_int_97); - __Pyx_GIVEREF(__pyx_int_97); - PyList_SET_ITEM(__pyx_t_5, 10, __pyx_int_97); - __pyx_t_3 = NULL; - __pyx_t_14 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - __pyx_t_14 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_columnValues, __pyx_t_5}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 985, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_columnValues, __pyx_t_5}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 985, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 985, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_columnValues); - __Pyx_GIVEREF(__pyx_v_columnValues); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_14, __pyx_v_columnValues); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_14, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 985, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF_SET(__pyx_v_lspercentile, __pyx_t_4); - __pyx_t_4 = 0; -
0986: else:-
+0987: lspercentile = np.percentile(lsUnique, [10, 50, 90])-
/*else*/ { - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_np); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 987, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_percentile); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 987, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = PyList_New(3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 987, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(__pyx_int_10); - __Pyx_GIVEREF(__pyx_int_10); - PyList_SET_ITEM(__pyx_t_12, 0, __pyx_int_10); - __Pyx_INCREF(__pyx_int_50); - __Pyx_GIVEREF(__pyx_int_50); - PyList_SET_ITEM(__pyx_t_12, 1, __pyx_int_50); - __Pyx_INCREF(__pyx_int_90); - __Pyx_GIVEREF(__pyx_int_90); - PyList_SET_ITEM(__pyx_t_12, 2, __pyx_int_90); - __pyx_t_5 = NULL; - __pyx_t_14 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - __pyx_t_14 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_lsUnique, __pyx_t_12}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 987, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_lsUnique, __pyx_t_12}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 987, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 987, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_INCREF(__pyx_v_lsUnique); - __Pyx_GIVEREF(__pyx_v_lsUnique); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_14, __pyx_v_lsUnique); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_14, __pyx_t_12); - __pyx_t_12 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 987, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF_SET(__pyx_v_lspercentile, __pyx_t_4); - __pyx_t_4 = 0; - } - __pyx_L21:; -
+0988: lsUnique = np.unique(lspercentile)-
__Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 988, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_unique); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 988, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_v_lspercentile) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_lspercentile); - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 988, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF_SET(__pyx_v_lsUnique, __pyx_t_4); - __pyx_t_4 = 0; -
0989:
-+0990: for value in lsUnique:-
if (likely(PyList_CheckExact(__pyx_v_lsUnique)) || PyTuple_CheckExact(__pyx_v_lsUnique)) { - __pyx_t_4 = __pyx_v_lsUnique; __Pyx_INCREF(__pyx_t_4); __pyx_t_15 = 0; - __pyx_t_8 = NULL; - } else { - __pyx_t_15 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_lsUnique); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 990, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 990, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_8)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_15); __Pyx_INCREF(__pyx_t_3); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 990, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 990, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } else { - if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_15); __Pyx_INCREF(__pyx_t_3); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 990, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 990, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } - } else { - __pyx_t_3 = __pyx_t_8(__pyx_t_4); - if (unlikely(!__pyx_t_3)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 990, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3); - __pyx_t_3 = 0; -/* … */ - __pyx_L22_continue:; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
+0991: X_l, X_r, w_l, w_r, y_l, y_r = self.divideSet(X, treatment_idx, y, col, value)-
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_divideSet); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_12 = NULL; - __pyx_t_14 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - __pyx_t_14 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[6] = {__pyx_t_12, __pyx_v_X, __pyx_v_treatment_idx, __pyx_v_y, __pyx_v_col, __pyx_v_value}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_14, 5+__pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[6] = {__pyx_t_12, __pyx_v_X, __pyx_v_treatment_idx, __pyx_v_y, __pyx_v_col, __pyx_v_value}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_14, 5+__pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_5 = PyTuple_New(5+__pyx_t_14); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_12) { - __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_12); __pyx_t_12 = NULL; - } - __Pyx_INCREF(__pyx_v_X); - __Pyx_GIVEREF(__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_14, __pyx_v_X); - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_14, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_14, __pyx_v_y); - __Pyx_INCREF(__pyx_v_col); - __Pyx_GIVEREF(__pyx_v_col); - PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_14, __pyx_v_col); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_5, 4+__pyx_t_14, __pyx_v_value); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { - PyObject* sequence = __pyx_t_3; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 6)) { - if (size > 6) __Pyx_RaiseTooManyValuesError(6); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 991, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_12 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_11 = PyTuple_GET_ITEM(sequence, 3); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 4); - __pyx_t_16 = PyTuple_GET_ITEM(sequence, 5); - } else { - __pyx_t_6 = PyList_GET_ITEM(sequence, 0); - __pyx_t_5 = PyList_GET_ITEM(sequence, 1); - __pyx_t_12 = PyList_GET_ITEM(sequence, 2); - __pyx_t_11 = PyList_GET_ITEM(sequence, 3); - __pyx_t_9 = PyList_GET_ITEM(sequence, 4); - __pyx_t_16 = PyList_GET_ITEM(sequence, 5); - } - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_16); - #else - { - Py_ssize_t i; - PyObject** temps[6] = {&__pyx_t_6,&__pyx_t_5,&__pyx_t_12,&__pyx_t_11,&__pyx_t_9,&__pyx_t_16}; - for (i=0; i < 6; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } - } - #endif - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - PyObject** temps[6] = {&__pyx_t_6,&__pyx_t_5,&__pyx_t_12,&__pyx_t_11,&__pyx_t_9,&__pyx_t_16}; - __pyx_t_17 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 991, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_17); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = Py_TYPE(__pyx_t_17)->tp_iternext; - for (index=0; index < 6; index++) { - PyObject* item = __pyx_t_7(__pyx_t_17); if (unlikely(!item)) goto __pyx_L24_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_17), 6) < 0) __PYX_ERR(0, 991, __pyx_L1_error) - __pyx_t_7 = NULL; - __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - goto __pyx_L25_unpacking_done; - __pyx_L24_unpacking_failed:; - __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - __pyx_t_7 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 991, __pyx_L1_error) - __pyx_L25_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_X_l, __pyx_t_6); - __pyx_t_6 = 0; - __Pyx_XDECREF_SET(__pyx_v_X_r, __pyx_t_5); - __pyx_t_5 = 0; - __Pyx_XDECREF_SET(__pyx_v_w_l, __pyx_t_12); - __pyx_t_12 = 0; - __Pyx_XDECREF_SET(__pyx_v_w_r, __pyx_t_11); - __pyx_t_11 = 0; - __Pyx_XDECREF_SET(__pyx_v_y_l, __pyx_t_9); - __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_y_r, __pyx_t_16); - __pyx_t_16 = 0; -
0992: # check the split validity on min_samples_leaf 372-
+0993: if (len(X_l) < min_samples_leaf or len(X_r) < min_samples_leaf):-
__pyx_t_18 = PyObject_Length(__pyx_v_X_l); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 993, __pyx_L1_error) - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 993, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_16 = PyObject_RichCompare(__pyx_t_3, __pyx_v_min_samples_leaf, Py_LT); __Pyx_XGOTREF(__pyx_t_16); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 993, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_16); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 993, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (!__pyx_t_13) { - } else { - __pyx_t_2 = __pyx_t_13; - goto __pyx_L27_bool_binop_done; - } - __pyx_t_18 = PyObject_Length(__pyx_v_X_r); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 993, __pyx_L1_error) - __pyx_t_16 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 993, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_16, __pyx_v_min_samples_leaf, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 993, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 993, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_2 = __pyx_t_13; - __pyx_L27_bool_binop_done:; - if (__pyx_t_2) { -/* … */ - } -
+0994: continue-
goto __pyx_L22_continue; -
0995: # summarize notes-
0996: # Gain -- Entropy or Gini-
+0997: p = float(len(X_l)) / len(X)-
__pyx_t_18 = PyObject_Length(__pyx_v_X_l); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 997, __pyx_L1_error) - __pyx_t_19 = PyObject_Length(__pyx_v_X); if (unlikely(__pyx_t_19 == ((Py_ssize_t)-1))) __PYX_ERR(0, 997, __pyx_L1_error) - __pyx_v_p = (((double)__pyx_t_18) / __pyx_t_19); -
+0998: leftNodeSummary = self.tree_node_summary(w_l, y_l,-
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tree_node_summary); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 998, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 998, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_INCREF(__pyx_v_w_l); - __Pyx_GIVEREF(__pyx_v_w_l); - PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_v_w_l); - __Pyx_INCREF(__pyx_v_y_l); - __Pyx_GIVEREF(__pyx_v_y_l); - PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_v_y_l); -/* … */ - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_16, __pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 998, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_leftNodeSummary, __pyx_t_11); - __pyx_t_11 = 0; -
+0999: min_samples_treatment=min_samples_treatment,-
__pyx_t_9 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 999, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_min_samples_treatment, __pyx_v_min_samples_treatment) < 0) __PYX_ERR(0, 999, __pyx_L1_error) -
+1000: n_reg=n_reg,-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 999, __pyx_L1_error) -
+1001: parentNodeSummary=currentNodeSummary)-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_parentNodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 999, __pyx_L1_error) -
1002:
-+1003: rightNodeSummary = self.tree_node_summary(w_r, y_r,-
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tree_node_summary); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1003, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1003, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_INCREF(__pyx_v_w_r); - __Pyx_GIVEREF(__pyx_v_w_r); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_w_r); - __Pyx_INCREF(__pyx_v_y_r); - __Pyx_GIVEREF(__pyx_v_y_r); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_y_r); -/* … */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_9, __pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1003, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_XDECREF_SET(__pyx_v_rightNodeSummary, __pyx_t_3); - __pyx_t_3 = 0; -
+1004: min_samples_treatment=min_samples_treatment,-
__pyx_t_16 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1004, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - if (PyDict_SetItem(__pyx_t_16, __pyx_n_s_min_samples_treatment, __pyx_v_min_samples_treatment) < 0) __PYX_ERR(0, 1004, __pyx_L1_error) -
+1005: n_reg=n_reg,-
if (PyDict_SetItem(__pyx_t_16, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 1004, __pyx_L1_error) -
+1006: parentNodeSummary=currentNodeSummary)-
if (PyDict_SetItem(__pyx_t_16, __pyx_n_s_parentNodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 1004, __pyx_L1_error) -
1007:
-1008: # check the split validity on min_samples_treatment-
+1009: assert len(leftNodeSummary) == len(rightNodeSummary)-
#ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - __pyx_t_19 = PyObject_Length(__pyx_v_leftNodeSummary); if (unlikely(__pyx_t_19 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1009, __pyx_L1_error) - __pyx_t_18 = PyObject_Length(__pyx_v_rightNodeSummary); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1009, __pyx_L1_error) - if (unlikely(!((__pyx_t_19 == __pyx_t_18) != 0))) { - PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 1009, __pyx_L1_error) - } - } - #endif -
1010:
-+1011: node_mst = min([stat[1] for stat in leftNodeSummary + rightNodeSummary])-
__pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_16 = PyNumber_Add(__pyx_v_leftNodeSummary, __pyx_v_rightNodeSummary); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - if (likely(PyList_CheckExact(__pyx_t_16)) || PyTuple_CheckExact(__pyx_t_16)) { - __pyx_t_9 = __pyx_t_16; __Pyx_INCREF(__pyx_t_9); __pyx_t_18 = 0; - __pyx_t_20 = NULL; - } else { - __pyx_t_18 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_16); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_20 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1011, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - for (;;) { - if (likely(!__pyx_t_20)) { - if (likely(PyList_CheckExact(__pyx_t_9))) { - if (__pyx_t_18 >= PyList_GET_SIZE(__pyx_t_9)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_16 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_18); __Pyx_INCREF(__pyx_t_16); __pyx_t_18++; if (unlikely(0 < 0)) __PYX_ERR(0, 1011, __pyx_L1_error) - #else - __pyx_t_16 = PySequence_ITEM(__pyx_t_9, __pyx_t_18); __pyx_t_18++; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - #endif - } else { - if (__pyx_t_18 >= PyTuple_GET_SIZE(__pyx_t_9)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_16 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_18); __Pyx_INCREF(__pyx_t_16); __pyx_t_18++; if (unlikely(0 < 0)) __PYX_ERR(0, 1011, __pyx_L1_error) - #else - __pyx_t_16 = PySequence_ITEM(__pyx_t_9, __pyx_t_18); __pyx_t_18++; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - #endif - } - } else { - __pyx_t_16 = __pyx_t_20(__pyx_t_9); - if (unlikely(!__pyx_t_16)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1011, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_16); - } - __Pyx_XDECREF_SET(__pyx_v_stat, __pyx_t_16); - __pyx_t_16 = 0; - __pyx_t_16 = __Pyx_GetItemInt(__pyx_v_stat, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_16))) __PYX_ERR(0, 1011, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_min, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_node_mst, __pyx_t_9); - __pyx_t_9 = 0; -
+1012: if node_mst < min_samples_treatment:-
__pyx_t_9 = PyObject_RichCompare(__pyx_v_node_mst, __pyx_v_min_samples_treatment, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1012, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1012, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (__pyx_t_2) { -/* … */ - } -
+1013: continue-
goto __pyx_L22_continue; -
1014:
-1015: # evaluate the split-
+1016: if self.evaluationFunction == self.evaluate_CTS:-
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1016, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluate_CTS); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1016, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_16 = PyObject_RichCompare(__pyx_t_9, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_16); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1016, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_16); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1016, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (__pyx_t_2) { -/* … */ - goto __pyx_L32; - } -
+1017: leftScore1 = self.evaluationFunction(leftNodeSummary)-
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1017, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_16 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_v_leftNodeSummary) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_leftNodeSummary); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1017, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_leftScore1, __pyx_t_16); - __pyx_t_16 = 0; -
+1018: rightScore2 = self.evaluationFunction(rightNodeSummary)-
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1018, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_16 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_v_rightNodeSummary) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_rightNodeSummary); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1018, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_rightScore2, __pyx_t_16); - __pyx_t_16 = 0; -
+1019: gain = (currentScore - p * leftScore1 - (1 - p) * rightScore2)-
__pyx_t_16 = PyFloat_FromDouble(__pyx_v_p); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1019, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_3 = PyNumber_Multiply(__pyx_t_16, __pyx_v_leftScore1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1019, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = PyNumber_Subtract(__pyx_v_currentScore, __pyx_t_3); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1019, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyFloat_FromDouble((1.0 - __pyx_v_p)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1019, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = PyNumber_Multiply(__pyx_t_3, __pyx_v_rightScore2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1019, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Subtract(__pyx_t_16, __pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1019, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_gain, __pyx_t_3); - __pyx_t_3 = 0; -
+1020: gain_for_imp = (len(X) * currentScore - len(X_l) * leftScore1 - len(X_r) * rightScore2)-
__pyx_t_18 = PyObject_Length(__pyx_v_X); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1020, __pyx_L1_error) - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = PyNumber_Multiply(__pyx_t_3, __pyx_v_currentScore); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_18 = PyObject_Length(__pyx_v_X_l); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1020, __pyx_L1_error) - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_16 = PyNumber_Multiply(__pyx_t_3, __pyx_v_leftScore1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Subtract(__pyx_t_9, __pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_18 = PyObject_Length(__pyx_v_X_r); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1020, __pyx_L1_error) - __pyx_t_16 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_9 = PyNumber_Multiply(__pyx_t_16, __pyx_v_rightScore2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = PyNumber_Subtract(__pyx_t_3, __pyx_t_9); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_gain_for_imp, __pyx_t_16); - __pyx_t_16 = 0; -
+1021: elif self.evaluationFunction == self.evaluate_DDP:-
__pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1021, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluate_DDP); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1021, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_16, __pyx_t_9, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1021, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1021, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_2) { -/* … */ - goto __pyx_L32; - } -
+1022: leftScore1 = self.evaluationFunction(leftNodeSummary)-
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1022, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_16 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_16)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_16); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - } - } - __pyx_t_3 = (__pyx_t_16) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_16, __pyx_v_leftNodeSummary) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_leftNodeSummary); - __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1022, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_leftScore1, __pyx_t_3); - __pyx_t_3 = 0; -
+1023: rightScore2 = self.evaluationFunction(rightNodeSummary)-
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1023, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_16 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_16)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_16); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - } - } - __pyx_t_3 = (__pyx_t_16) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_16, __pyx_v_rightNodeSummary) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_rightNodeSummary); - __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1023, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_rightScore2, __pyx_t_3); - __pyx_t_3 = 0; -
+1024: gain = np.abs(leftScore1 - rightScore2)-
__Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_np); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1024, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_abs); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1024, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Subtract(__pyx_v_leftScore1, __pyx_v_rightScore2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1024, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_16); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_16, function); - } - } - __pyx_t_3 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_16, __pyx_t_11, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_9); - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1024, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_XDECREF_SET(__pyx_v_gain, __pyx_t_3); - __pyx_t_3 = 0; -
+1025: gain_for_imp = np.abs(len(X_l) * leftScore1 - len(X_r) * rightScore2)-
__Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_np); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_abs); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_18 = PyObject_Length(__pyx_v_X_l); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1025, __pyx_L1_error) - __pyx_t_16 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_11 = PyNumber_Multiply(__pyx_t_16, __pyx_v_leftScore1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_18 = PyObject_Length(__pyx_v_X_r); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1025, __pyx_L1_error) - __pyx_t_16 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_12 = PyNumber_Multiply(__pyx_t_16, __pyx_v_rightScore2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = PyNumber_Subtract(__pyx_t_11, __pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_12)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - } - } - __pyx_t_3 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_12, __pyx_t_16) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_16); - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_gain_for_imp, __pyx_t_3); - __pyx_t_3 = 0; -
1026: else:-
+1027: leftScore1 = self.evaluationFunction(leftNodeSummary)-
/*else*/ { - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1027, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_16 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_16)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_16); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - } - } - __pyx_t_3 = (__pyx_t_16) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_16, __pyx_v_leftNodeSummary) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_leftNodeSummary); - __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1027, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_leftScore1, __pyx_t_3); - __pyx_t_3 = 0; -
+1028: rightScore2 = self.evaluationFunction(rightNodeSummary)-
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1028, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_16 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_16)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_16); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - } - } - __pyx_t_3 = (__pyx_t_16) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_16, __pyx_v_rightNodeSummary) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_rightNodeSummary); - __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1028, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF_SET(__pyx_v_rightScore2, __pyx_t_3); - __pyx_t_3 = 0; -
+1029: gain = (p * leftScore1 + (1 - p) * rightScore2 - currentScore)-
__pyx_t_3 = PyFloat_FromDouble(__pyx_v_p); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1029, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = PyNumber_Multiply(__pyx_t_3, __pyx_v_leftScore1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1029, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyFloat_FromDouble((1.0 - __pyx_v_p)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1029, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_16 = PyNumber_Multiply(__pyx_t_3, __pyx_v_rightScore2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1029, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Add(__pyx_t_9, __pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1029, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = PyNumber_Subtract(__pyx_t_3, __pyx_v_currentScore); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1029, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_gain, __pyx_t_16); - __pyx_t_16 = 0; -
+1030: gain_for_imp = (len(X_l) * leftScore1 + len(X_r) * rightScore2 - len(X) * currentScore)-
__pyx_t_18 = PyObject_Length(__pyx_v_X_l); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1030, __pyx_L1_error) - __pyx_t_16 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_3 = PyNumber_Multiply(__pyx_t_16, __pyx_v_leftScore1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_18 = PyObject_Length(__pyx_v_X_r); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1030, __pyx_L1_error) - __pyx_t_16 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_9 = PyNumber_Multiply(__pyx_t_16, __pyx_v_rightScore2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = PyNumber_Add(__pyx_t_3, __pyx_t_9); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_18 = PyObject_Length(__pyx_v_X); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1030, __pyx_L1_error) - __pyx_t_9 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_3 = PyNumber_Multiply(__pyx_t_9, __pyx_v_currentScore); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Subtract(__pyx_t_16, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_gain_for_imp, __pyx_t_9); - __pyx_t_9 = 0; -
+1031: if self.normalization:-
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_normalization); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1031, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1031, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (__pyx_t_2) { -/* … */ - goto __pyx_L33; - } -
+1032: n_c = currentNodeSummary[0][1]-
__pyx_t_9 = __Pyx_GetItemInt(__pyx_v_currentNodeSummary, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1032, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_9, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1032, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF_SET(__pyx_v_n_c, __pyx_t_3); - __pyx_t_3 = 0; -
+1033: n_c_left = leftNodeSummary[0][1]-
__pyx_t_3 = __Pyx_GetItemInt(__pyx_v_leftNodeSummary, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1033, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_3, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1033, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_n_c_left, __pyx_t_9); - __pyx_t_9 = 0; -
+1034: n_t = [tr[1] for tr in currentNodeSummary[1:]]-
__pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1034, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_v_currentNodeSummary, 1, 0, NULL, NULL, &__pyx_slice__3, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1034, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_16 = __pyx_t_3; __Pyx_INCREF(__pyx_t_16); __pyx_t_18 = 0; - __pyx_t_20 = NULL; - } else { - __pyx_t_18 = -1; __pyx_t_16 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1034, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_20 = Py_TYPE(__pyx_t_16)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1034, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (likely(!__pyx_t_20)) { - if (likely(PyList_CheckExact(__pyx_t_16))) { - if (__pyx_t_18 >= PyList_GET_SIZE(__pyx_t_16)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_16, __pyx_t_18); __Pyx_INCREF(__pyx_t_3); __pyx_t_18++; if (unlikely(0 < 0)) __PYX_ERR(0, 1034, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_16, __pyx_t_18); __pyx_t_18++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1034, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } else { - if (__pyx_t_18 >= PyTuple_GET_SIZE(__pyx_t_16)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_16, __pyx_t_18); __Pyx_INCREF(__pyx_t_3); __pyx_t_18++; if (unlikely(0 < 0)) __PYX_ERR(0, 1034, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_16, __pyx_t_18); __pyx_t_18++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1034, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } - } else { - __pyx_t_3 = __pyx_t_20(__pyx_t_16); - if (unlikely(!__pyx_t_3)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1034, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF_SET(__pyx_v_tr, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_tr, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1034, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_9, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 1034, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF_SET(__pyx_v_n_t, __pyx_t_9); - __pyx_t_9 = 0; -
+1035: n_t_left = [tr[1] for tr in leftNodeSummary[1:]]-
__pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_16 = __Pyx_PyObject_GetSlice(__pyx_v_leftNodeSummary, 1, 0, NULL, NULL, &__pyx_slice__3, 1, 0, 0); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - if (likely(PyList_CheckExact(__pyx_t_16)) || PyTuple_CheckExact(__pyx_t_16)) { - __pyx_t_3 = __pyx_t_16; __Pyx_INCREF(__pyx_t_3); __pyx_t_18 = 0; - __pyx_t_20 = NULL; - } else { - __pyx_t_18 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 1035, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - for (;;) { - if (likely(!__pyx_t_20)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_18 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_16 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_18); __Pyx_INCREF(__pyx_t_16); __pyx_t_18++; if (unlikely(0 < 0)) __PYX_ERR(0, 1035, __pyx_L1_error) - #else - __pyx_t_16 = PySequence_ITEM(__pyx_t_3, __pyx_t_18); __pyx_t_18++; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - #endif - } else { - if (__pyx_t_18 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_16 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_18); __Pyx_INCREF(__pyx_t_16); __pyx_t_18++; if (unlikely(0 < 0)) __PYX_ERR(0, 1035, __pyx_L1_error) - #else - __pyx_t_16 = PySequence_ITEM(__pyx_t_3, __pyx_t_18); __pyx_t_18++; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - #endif - } - } else { - __pyx_t_16 = __pyx_t_20(__pyx_t_3); - if (unlikely(!__pyx_t_16)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1035, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_16); - } - __Pyx_XDECREF_SET(__pyx_v_tr, __pyx_t_16); - __pyx_t_16 = 0; - __pyx_t_16 = __Pyx_GetItemInt(__pyx_v_tr, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_9, (PyObject*)__pyx_t_16))) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_n_t_left, ((PyObject*)__pyx_t_9)); - __pyx_t_9 = 0; -
1036:
-+1037: norm_factor = self.normI(n_c, n_c_left, n_t, n_t_left, alpha=0.9)-
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_normI); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1037, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1037, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_n_c); - __Pyx_GIVEREF(__pyx_v_n_c); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_n_c); - __Pyx_INCREF(__pyx_v_n_c_left); - __Pyx_GIVEREF(__pyx_v_n_c_left); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_n_c_left); - __Pyx_INCREF(__pyx_v_n_t); - __Pyx_GIVEREF(__pyx_v_n_t); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_n_t); - __Pyx_INCREF(__pyx_v_n_t_left); - __Pyx_GIVEREF(__pyx_v_n_t_left); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_n_t_left); - __pyx_t_16 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1037, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - if (PyDict_SetItem(__pyx_t_16, __pyx_n_s_alpha, __pyx_float_0_9) < 0) __PYX_ERR(0, 1037, __pyx_L1_error) - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_3, __pyx_t_16); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1037, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_XDECREF_SET(__pyx_v_norm_factor, __pyx_t_12); - __pyx_t_12 = 0; -
1038: else:-
+1039: norm_factor = 1-
/*else*/ { - __Pyx_INCREF(__pyx_int_1); - __Pyx_XDECREF_SET(__pyx_v_norm_factor, __pyx_int_1); - } - __pyx_L33:; -
+1040: gain = gain / norm_factor-
__pyx_t_12 = __Pyx_PyNumber_Divide(__pyx_v_gain, __pyx_v_norm_factor); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF_SET(__pyx_v_gain, __pyx_t_12); - __pyx_t_12 = 0; - } - __pyx_L32:; -
+1041: if (gain > bestGain and len(X_l) > min_samples_leaf and len(X_r) > min_samples_leaf):-
__pyx_t_12 = PyObject_RichCompare(__pyx_v_gain, __pyx_v_bestGain, Py_GT); __Pyx_XGOTREF(__pyx_t_12); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1041, __pyx_L1_error) - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1041, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (__pyx_t_13) { - } else { - __pyx_t_2 = __pyx_t_13; - goto __pyx_L39_bool_binop_done; - } - __pyx_t_18 = PyObject_Length(__pyx_v_X_l); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1041, __pyx_L1_error) - __pyx_t_12 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1041, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_16 = PyObject_RichCompare(__pyx_t_12, __pyx_v_min_samples_leaf, Py_GT); __Pyx_XGOTREF(__pyx_t_16); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1041, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_16); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1041, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (__pyx_t_13) { - } else { - __pyx_t_2 = __pyx_t_13; - goto __pyx_L39_bool_binop_done; - } - __pyx_t_18 = PyObject_Length(__pyx_v_X_r); if (unlikely(__pyx_t_18 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1041, __pyx_L1_error) - __pyx_t_16 = PyInt_FromSsize_t(__pyx_t_18); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1041, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_12 = PyObject_RichCompare(__pyx_t_16, __pyx_v_min_samples_leaf, Py_GT); __Pyx_XGOTREF(__pyx_t_12); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1041, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1041, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_2 = __pyx_t_13; - __pyx_L39_bool_binop_done:; - if (__pyx_t_2) { -/* … */ - } -
+1042: bestGain = gain-
__Pyx_INCREF(__pyx_v_gain); - __Pyx_DECREF_SET(__pyx_v_bestGain, __pyx_v_gain); -
+1043: bestGainImp = gain_for_imp-
__Pyx_INCREF(__pyx_v_gain_for_imp); - __Pyx_DECREF_SET(__pyx_v_bestGainImp, __pyx_v_gain_for_imp); -
+1044: bestAttribute = (col, value)-
__pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1044, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(__pyx_v_col); - __Pyx_GIVEREF(__pyx_v_col); - PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_col); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_v_value); - __Pyx_DECREF_SET(__pyx_v_bestAttribute, ((PyObject*)__pyx_t_12)); - __pyx_t_12 = 0; -
+1045: best_set_left = [X_l, w_l, y_l]-
__pyx_t_12 = PyList_New(3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1045, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(__pyx_v_X_l); - __Pyx_GIVEREF(__pyx_v_X_l); - PyList_SET_ITEM(__pyx_t_12, 0, __pyx_v_X_l); - __Pyx_INCREF(__pyx_v_w_l); - __Pyx_GIVEREF(__pyx_v_w_l); - PyList_SET_ITEM(__pyx_t_12, 1, __pyx_v_w_l); - __Pyx_INCREF(__pyx_v_y_l); - __Pyx_GIVEREF(__pyx_v_y_l); - PyList_SET_ITEM(__pyx_t_12, 2, __pyx_v_y_l); - __Pyx_XDECREF_SET(__pyx_v_best_set_left, ((PyObject*)__pyx_t_12)); - __pyx_t_12 = 0; -
+1046: best_set_right = [X_r, w_r, y_r]-
__pyx_t_12 = PyList_New(3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1046, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(__pyx_v_X_r); - __Pyx_GIVEREF(__pyx_v_X_r); - PyList_SET_ITEM(__pyx_t_12, 0, __pyx_v_X_r); - __Pyx_INCREF(__pyx_v_w_r); - __Pyx_GIVEREF(__pyx_v_w_r); - PyList_SET_ITEM(__pyx_t_12, 1, __pyx_v_w_r); - __Pyx_INCREF(__pyx_v_y_r); - __Pyx_GIVEREF(__pyx_v_y_r); - PyList_SET_ITEM(__pyx_t_12, 2, __pyx_v_y_r); - __Pyx_XDECREF_SET(__pyx_v_best_set_right, ((PyObject*)__pyx_t_12)); - __pyx_t_12 = 0; -
1047:
-+1048: dcY = {'impurity': '%.3f' % currentScore, 'samples': '%d' % len(X)}-
__pyx_t_10 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1048, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_4 = __Pyx_PyString_FormatSafe(__pyx_kp_s_3f, __pyx_v_currentScore); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1048, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_impurity, __pyx_t_4) < 0) __PYX_ERR(0, 1048, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_1 = PyObject_Length(__pyx_v_X); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1048, __pyx_L1_error) - __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1048, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_12 = __Pyx_PyString_Format(__pyx_kp_s_d, __pyx_t_4); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1048, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_samples, __pyx_t_12) < 0) __PYX_ERR(0, 1048, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_v_dcY = ((PyObject*)__pyx_t_10); - __pyx_t_10 = 0; -
1049: # Add treatment size-
+1050: dcY['group_size'] = ''-
if (unlikely(PyDict_SetItem(__pyx_v_dcY, __pyx_n_s_group_size, __pyx_kp_s__4) < 0)) __PYX_ERR(0, 1050, __pyx_L1_error) -
+1051: for i, summary in enumerate(currentNodeSummary):-
__Pyx_INCREF(__pyx_int_0); - __pyx_t_10 = __pyx_int_0; - if (likely(PyList_CheckExact(__pyx_v_currentNodeSummary)) || PyTuple_CheckExact(__pyx_v_currentNodeSummary)) { - __pyx_t_12 = __pyx_v_currentNodeSummary; __Pyx_INCREF(__pyx_t_12); __pyx_t_1 = 0; - __pyx_t_8 = NULL; - } else { - __pyx_t_1 = -1; __pyx_t_12 = PyObject_GetIter(__pyx_v_currentNodeSummary); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1051, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_8 = Py_TYPE(__pyx_t_12)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1051, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_8)) { - if (likely(PyList_CheckExact(__pyx_t_12))) { - if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_12)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_12, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 1051, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_12, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1051, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_12)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_12, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 1051, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_12, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1051, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_8(__pyx_t_12); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1051, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF_SET(__pyx_v_summary, __pyx_t_4); - __pyx_t_4 = 0; - __Pyx_INCREF(__pyx_t_10); - __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_10); - __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_10, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1051, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_10); - __pyx_t_10 = __pyx_t_4; - __pyx_t_4 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; -
+1052: dcY['group_size'] += ' ' + self.classes_[i] + ': ' + str(summary[1])-
__Pyx_INCREF(__pyx_n_s_group_size); - __pyx_t_21 = __pyx_n_s_group_size; - __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_dcY, __pyx_t_21); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1052, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1052, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_16, __pyx_v_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1052, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = PyNumber_Add(__pyx_kp_s__5, __pyx_t_3); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1052, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Add(__pyx_t_16, __pyx_kp_s__6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1052, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = __Pyx_GetItemInt(__pyx_v_summary, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1052, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_9 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_16); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1052, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = PyNumber_Add(__pyx_t_3, __pyx_t_9); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1052, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_t_4, __pyx_t_16); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1052, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (unlikely(PyDict_SetItem(__pyx_v_dcY, __pyx_t_21, __pyx_t_9) < 0)) __PYX_ERR(0, 1052, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; -
+1053: dcY['upliftScore'] = [round(upliftScore[0], 4), round(upliftScore[1], 4)]-
__pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1053, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(PyList_GET_ITEM(__pyx_v_upliftScore, 0)); - __Pyx_GIVEREF(PyList_GET_ITEM(__pyx_v_upliftScore, 0)); - PyTuple_SET_ITEM(__pyx_t_10, 0, PyList_GET_ITEM(__pyx_v_upliftScore, 0)); - __Pyx_INCREF(__pyx_int_4); - __Pyx_GIVEREF(__pyx_int_4); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_int_4); - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_10, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1053, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1053, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(PyList_GET_ITEM(__pyx_v_upliftScore, 1)); - __Pyx_GIVEREF(PyList_GET_ITEM(__pyx_v_upliftScore, 1)); - PyTuple_SET_ITEM(__pyx_t_10, 0, PyList_GET_ITEM(__pyx_v_upliftScore, 1)); - __Pyx_INCREF(__pyx_int_4); - __Pyx_GIVEREF(__pyx_int_4); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_int_4); - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1053, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyList_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1053, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_12); - PyList_SET_ITEM(__pyx_t_10, 0, __pyx_t_12); - __Pyx_GIVEREF(__pyx_t_9); - PyList_SET_ITEM(__pyx_t_10, 1, __pyx_t_9); - __pyx_t_12 = 0; - __pyx_t_9 = 0; - if (unlikely(PyDict_SetItem(__pyx_v_dcY, __pyx_n_s_upliftScore, __pyx_t_10) < 0)) __PYX_ERR(0, 1053, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; -
+1054: dcY['matchScore'] = round(upliftScore[0], 4)-
__pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1054, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(PyList_GET_ITEM(__pyx_v_upliftScore, 0)); - __Pyx_GIVEREF(PyList_GET_ITEM(__pyx_v_upliftScore, 0)); - PyTuple_SET_ITEM(__pyx_t_10, 0, PyList_GET_ITEM(__pyx_v_upliftScore, 0)); - __Pyx_INCREF(__pyx_int_4); - __Pyx_GIVEREF(__pyx_int_4); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_int_4); - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_round, __pyx_t_10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1054, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (unlikely(PyDict_SetItem(__pyx_v_dcY, __pyx_n_s_matchScore, __pyx_t_9) < 0)) __PYX_ERR(0, 1054, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; -
1055:
-+1056: if bestGain > 0 and depth < max_depth:-
__pyx_t_9 = PyObject_RichCompare(__pyx_v_bestGain, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1056, __pyx_L1_error) - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1056, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (__pyx_t_13) { - } else { - __pyx_t_2 = __pyx_t_13; - goto __pyx_L45_bool_binop_done; - } - __pyx_t_9 = PyObject_RichCompare(__pyx_v_depth, __pyx_v_max_depth, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1056, __pyx_L1_error) - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1056, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_2 = __pyx_t_13; - __pyx_L45_bool_binop_done:; - if (__pyx_t_2) { -/* … */ - } -
+1057: self.feature_imp_dict[bestAttribute[0]] += bestGainImp-
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_feature_imp_dict); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1057, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (unlikely(__pyx_v_bestAttribute == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 1057, __pyx_L1_error) - } - __Pyx_INCREF(PyTuple_GET_ITEM(__pyx_v_bestAttribute, 0)); - __pyx_t_10 = PyTuple_GET_ITEM(__pyx_v_bestAttribute, 0); - __pyx_t_12 = __Pyx_PyObject_GetItem(__pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1057, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_16 = PyNumber_InPlaceAdd(__pyx_t_12, __pyx_v_bestGainImp); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1057, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(PyObject_SetItem(__pyx_t_9, __pyx_t_10, __pyx_t_16) < 0)) __PYX_ERR(0, 1057, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; -
+1058: trueBranch = self.growDecisionTreeFrom(-
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_growDecisionTreeFrom); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1058, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); -/* … */ - __pyx_t_10 = PySequence_Tuple(__pyx_v_best_set_left); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1058, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); -/* … */ - __pyx_t_12 = PyTuple_New(3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1058, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(__pyx_v_max_depth); - __Pyx_GIVEREF(__pyx_v_max_depth); - PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_max_depth); - __Pyx_INCREF(__pyx_v_min_samples_leaf); - __Pyx_GIVEREF(__pyx_v_min_samples_leaf); - PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_v_min_samples_leaf); - __Pyx_GIVEREF(__pyx_t_16); - PyTuple_SET_ITEM(__pyx_t_12, 2, __pyx_t_16); - __pyx_t_16 = 0; - __pyx_t_16 = PyNumber_Add(__pyx_t_10, __pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1058, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; -/* … */ - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_16, __pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1058, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_v_trueBranch = __pyx_t_10; - __pyx_t_10 = 0; -
+1059: *best_set_left, max_depth, min_samples_leaf,-
if (unlikely(!__pyx_v_best_set_left)) { __Pyx_RaiseUnboundLocalError("best_set_left"); __PYX_ERR(0, 1059, __pyx_L1_error) } -
+1060: depth + 1, min_samples_treatment=min_samples_treatment,-
__pyx_t_16 = __Pyx_PyInt_AddObjC(__pyx_v_depth, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1060, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); -/* … */ - __pyx_t_12 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1060, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_min_samples_treatment, __pyx_v_min_samples_treatment) < 0) __PYX_ERR(0, 1060, __pyx_L1_error) -
+1061: n_reg=n_reg, parentNodeSummary=currentNodeSummary-
if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 1060, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_parentNodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 1060, __pyx_L1_error) -
1062: )-
+1063: falseBranch = self.growDecisionTreeFrom(-
__pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_growDecisionTreeFrom); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1063, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); -/* … */ - __pyx_t_12 = PySequence_Tuple(__pyx_v_best_set_right); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1063, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); -/* … */ - __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1063, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_INCREF(__pyx_v_max_depth); - __Pyx_GIVEREF(__pyx_v_max_depth); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_max_depth); - __Pyx_INCREF(__pyx_v_min_samples_leaf); - __Pyx_GIVEREF(__pyx_v_min_samples_leaf); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_min_samples_leaf); - __Pyx_GIVEREF(__pyx_t_16); - PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_16); - __pyx_t_16 = 0; - __pyx_t_16 = PyNumber_Add(__pyx_t_12, __pyx_t_9); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1063, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; -/* … */ - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_16, __pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1063, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_falseBranch = __pyx_t_12; - __pyx_t_12 = 0; -
+1064: *best_set_right, max_depth, min_samples_leaf,-
if (unlikely(!__pyx_v_best_set_right)) { __Pyx_RaiseUnboundLocalError("best_set_right"); __PYX_ERR(0, 1064, __pyx_L1_error) } -
+1065: depth + 1, min_samples_treatment=min_samples_treatment,-
__pyx_t_16 = __Pyx_PyInt_AddObjC(__pyx_v_depth, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1065, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); -/* … */ - __pyx_t_9 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1065, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_min_samples_treatment, __pyx_v_min_samples_treatment) < 0) __PYX_ERR(0, 1065, __pyx_L1_error) -
+1066: n_reg=n_reg, parentNodeSummary=currentNodeSummary-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 1065, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_parentNodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 1065, __pyx_L1_error) -
1067: )-
1068:
-+1069: return DecisionTree(-
__Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_DecisionTree); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1069, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); -/* … */ - __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_empty_tuple, __pyx_t_9); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1069, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_r = __pyx_t_16; - __pyx_t_16 = 0; - goto __pyx_L0; -
+1070: classes_=self.classes_,-
__pyx_t_9 = __Pyx_PyDict_NewPresized(12); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1070, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1070, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_classes, __pyx_t_16) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; -
+1071: col=bestAttribute[0], value=bestAttribute[1],-
if (unlikely(__pyx_v_bestAttribute == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 1071, __pyx_L1_error) - } - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_col, PyTuple_GET_ITEM(__pyx_v_bestAttribute, 0)) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) - if (unlikely(__pyx_v_bestAttribute == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 1071, __pyx_L1_error) - } - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_value, PyTuple_GET_ITEM(__pyx_v_bestAttribute, 1)) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) -
+1072: trueBranch=trueBranch, falseBranch=falseBranch, summary=dcY,-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_trueBranch, __pyx_v_trueBranch) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_falseBranch, __pyx_v_falseBranch) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_summary, __pyx_v_dcY) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) -
+1073: maxDiffTreatment=maxDiffTreatment, maxDiffSign=maxDiffSign,-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_maxDiffTreatment, __pyx_v_maxDiffTreatment) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_maxDiffSign, __pyx_v_maxDiffSign) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) -
+1074: nodeSummary=currentNodeSummary,-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_nodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) -
+1075: backupResults=self.uplift_classification_results(treatment_idx, y),-
__pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_uplift_classification_results); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1075, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_4 = NULL; - __pyx_t_14 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - __pyx_t_14 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_16 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1075, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_16); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_16 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1075, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_16); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1075, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL; - } - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_14, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_14, __pyx_v_y); - __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_3, NULL); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1075, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_backupResults, __pyx_t_16) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; -
+1076: bestTreatment=bestTreatment, upliftScore=upliftScore-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_bestTreatment, __pyx_v_bestTreatment) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_upliftScore, __pyx_v_upliftScore) < 0) __PYX_ERR(0, 1070, __pyx_L1_error) -
1077: )-
1078: else:-
+1079: if self.evaluationFunction == self.evaluate_CTS:-
/*else*/ { - __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1079, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_evaluate_CTS); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1079, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_12 = PyObject_RichCompare(__pyx_t_16, __pyx_t_9, Py_EQ); __Pyx_XGOTREF(__pyx_t_12); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1079, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1079, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (__pyx_t_2) { -/* … */ - } -
+1080: return DecisionTree(-
__Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_DecisionTree); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1080, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); -/* … */ - __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_empty_tuple, __pyx_t_9); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1080, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_r = __pyx_t_16; - __pyx_t_16 = 0; - goto __pyx_L0; -
+1081: classes_=self.classes_,-
__pyx_t_9 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1081, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1081, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_classes, __pyx_t_16) < 0) __PYX_ERR(0, 1081, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; -
+1082: results=self.uplift_classification_results(treatment_idx, y),-
__pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_uplift_classification_results); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1082, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_3 = NULL; - __pyx_t_14 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - __pyx_t_14 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_16 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1082, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_16); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_16 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1082, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_16); - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1082, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_14, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_14, __pyx_v_y); - __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_4, NULL); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1082, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_results, __pyx_t_16) < 0) __PYX_ERR(0, 1081, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; -
+1083: summary=dcY, nodeSummary=currentNodeSummary,-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_summary, __pyx_v_dcY) < 0) __PYX_ERR(0, 1081, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_nodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 1081, __pyx_L1_error) -
+1084: bestTreatment=bestTreatment, upliftScore=upliftScore-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_bestTreatment, __pyx_v_bestTreatment) < 0) __PYX_ERR(0, 1081, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_upliftScore, __pyx_v_upliftScore) < 0) __PYX_ERR(0, 1081, __pyx_L1_error) -
1085: )-
1086: else:-
+1087: return DecisionTree(-
/*else*/ { - __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_DecisionTree); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1087, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); -/* … */ - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_empty_tuple, __pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1087, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_r = __pyx_t_12; - __pyx_t_12 = 0; - goto __pyx_L0; - } - } -
+1088: classes_=self.classes_,-
__pyx_t_9 = __Pyx_PyDict_NewPresized(8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1088, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1088, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_classes, __pyx_t_12) < 0) __PYX_ERR(0, 1088, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; -
+1089: results=self.uplift_classification_results(treatment_idx, y),-
__pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_uplift_classification_results); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1089, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_4 = NULL; - __pyx_t_14 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - __pyx_t_14 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1089, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_12); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_treatment_idx, __pyx_v_y}; - __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1089, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_12); - } else - #endif - { - __pyx_t_3 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1089, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL; - } - __Pyx_INCREF(__pyx_v_treatment_idx); - __Pyx_GIVEREF(__pyx_v_treatment_idx); - PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_14, __pyx_v_treatment_idx); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_14, __pyx_v_y); - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_3, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1089, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_results, __pyx_t_12) < 0) __PYX_ERR(0, 1088, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; -
+1090: summary=dcY, maxDiffTreatment=maxDiffTreatment,-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_summary, __pyx_v_dcY) < 0) __PYX_ERR(0, 1088, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_maxDiffTreatment, __pyx_v_maxDiffTreatment) < 0) __PYX_ERR(0, 1088, __pyx_L1_error) -
+1091: maxDiffSign=maxDiffSign, nodeSummary=currentNodeSummary,-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_maxDiffSign, __pyx_v_maxDiffSign) < 0) __PYX_ERR(0, 1088, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_nodeSummary, __pyx_v_currentNodeSummary) < 0) __PYX_ERR(0, 1088, __pyx_L1_error) -
+1092: bestTreatment=bestTreatment, upliftScore=upliftScore-
if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_bestTreatment, __pyx_v_bestTreatment) < 0) __PYX_ERR(0, 1088, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_upliftScore, __pyx_v_upliftScore) < 0) __PYX_ERR(0, 1088, __pyx_L1_error) -
1093: )-
1094:
-+1095: @staticmethod-
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1095, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_classify, __pyx_t_2) < 0) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+1096: def classify(observations, tree, dataMissing=False):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_37classify(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_36classify[] = "\n Classifies (prediction) the observations according to the tree.\n\n Args\n ----\n observations : list of list\n The internal data format for the training data (combining X, Y, treatment).\n\n dataMissing: boolean, optional (default = False)\n An indicator for if data are missing or not.\n\n Returns\n -------\n tree.results, tree.upliftScore :\n The results in the leaf node.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_37classify = {"classify", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_37classify, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_36classify}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_37classify(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_observations = 0; - PyObject *__pyx_v_tree = 0; - PyObject *__pyx_v_dataMissing = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("classify (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_observations,&__pyx_n_s_tree,&__pyx_n_s_dataMissing,0}; - PyObject* values[3] = {0,0,0}; - values[2] = ((PyObject *)((PyObject *)Py_False)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_observations)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tree)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("classify", 0, 2, 3, 1); __PYX_ERR(0, 1096, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dataMissing); - if (value) { values[2] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "classify") < 0)) __PYX_ERR(0, 1096, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_observations = values[0]; - __pyx_v_tree = values[1]; - __pyx_v_dataMissing = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("classify", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1096, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.classify", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_36classify(__pyx_self, __pyx_v_observations, __pyx_v_tree, __pyx_v_dataMissing); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_36classify(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_observations, PyObject *__pyx_v_tree, PyObject *__pyx_v_dataMissing) { - struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("classify", 0); - __pyx_cur_scope = (struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify *)__pyx_tp_new_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify(__pyx_ptype_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1096, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.classify", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__61 = PyTuple_Pack(7, __pyx_n_s_observations, __pyx_n_s_tree, __pyx_n_s_dataMissing, __pyx_n_s_classifyWithoutMissingData, __pyx_n_s_classifyWithoutMissingData, __pyx_n_s_classifyWithMissingData, __pyx_n_s_classifyWithMissingData); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__61); - __Pyx_GIVEREF(__pyx_tuple__61); - __pyx_codeobj__62 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__61, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_classify, 1096, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__62)) __PYX_ERR(0, 1096, __pyx_L1_error) -/* … */ - __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_37classify, __Pyx_CYFUNCTION_STATICMETHOD, __pyx_n_s_UpliftTreeClassifier_classify, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__62)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_tuple__63); - __pyx_tuple__63 = PyTuple_Pack(1, ((PyObject *)Py_False)); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__63); - __Pyx_GIVEREF(__pyx_tuple__63); -/* … */ -struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify { - PyObject_HEAD - PyObject *__pyx_v_classifyWithMissingData; - PyObject *__pyx_v_classifyWithoutMissingData; -}; - -
1097: '''-
1098: Classifies (prediction) the observations according to the tree.-
1099:
-1100: Args-
1101: -----
1102: observations : list of list-
1103: The internal data format for the training data (combining X, Y, treatment).-
1104:
-1105: dataMissing: boolean, optional (default = False)-
1106: An indicator for if data are missing or not.-
1107:
-1108: Returns-
1109: --------
1110: tree.results, tree.upliftScore :-
1111: The results in the leaf node.-
1112: '''-
1113:
-+1114: def classifyWithoutMissingData(observations, tree):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_1classifyWithoutMissingData(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_classifyWithoutMissingData[] = "\n Classifies (prediction) the observations according to the tree, assuming without missing data.\n\n Args\n ----\n observations : list of list\n The internal data format for the training data (combining X, Y, treatment).\n\n Returns\n -------\n tree.results, tree.upliftScore :\n The results in the leaf node.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_1classifyWithoutMissingData = {"classifyWithoutMissingData", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_1classifyWithoutMissingData, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_classifyWithoutMissingData}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_1classifyWithoutMissingData(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_observations = 0; - PyObject *__pyx_v_tree = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("classifyWithoutMissingData (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_observations,&__pyx_n_s_tree,0}; - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_observations)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tree)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("classifyWithoutMissingData", 1, 2, 2, 1); __PYX_ERR(0, 1114, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "classifyWithoutMissingData") < 0)) __PYX_ERR(0, 1114, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_observations = values[0]; - __pyx_v_tree = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("classifyWithoutMissingData", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1114, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.classify.classifyWithoutMissingData", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_classifyWithoutMissingData(__pyx_self, __pyx_v_observations, __pyx_v_tree); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_classifyWithoutMissingData(PyObject *__pyx_self, PyObject *__pyx_v_observations, PyObject *__pyx_v_tree) { - struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify *__pyx_cur_scope; - struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify *__pyx_outer_scope; - PyObject *__pyx_v_v = NULL; - PyObject *__pyx_v_branch = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("classifyWithoutMissingData", 0); - __pyx_outer_scope = (struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify *) __Pyx_CyFunction_GetClosure(__pyx_self); - __pyx_cur_scope = __pyx_outer_scope; -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.classify.classifyWithoutMissingData", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_v); - __Pyx_XDECREF(__pyx_v_branch); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__8 = PyTuple_Pack(4, __pyx_n_s_observations, __pyx_n_s_tree, __pyx_n_s_v, __pyx_n_s_branch); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 1114, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__8); - __Pyx_GIVEREF(__pyx_tuple__8); -/* … */ - __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_1classifyWithoutMissingData, 0, __pyx_n_s_UpliftTreeClassifier_classify_lo, ((PyObject*)__pyx_cur_scope), __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__9)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1114, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_v_classifyWithoutMissingData = __pyx_t_1; - __pyx_t_1 = 0; - __pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_classifyWithoutMissingData, 1114, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) __PYX_ERR(0, 1114, __pyx_L1_error) -
1115: '''-
1116: Classifies (prediction) the observations according to the tree, assuming without missing data.-
1117:
-1118: Args-
1119: -----
1120: observations : list of list-
1121: The internal data format for the training data (combining X, Y, treatment).-
1122:
-1123: Returns-
1124: --------
1125: tree.results, tree.upliftScore :-
1126: The results in the leaf node.-
1127: '''-
+1128: if tree.results is not None: # leaf-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_results); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1128, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = (__pyx_t_1 != Py_None); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { -/* … */ - } -
+1129: return tree.results, tree.upliftScore-
__Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_results); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1129, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_upliftScore); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1129, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1129, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); - __pyx_t_1 = 0; - __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; -
1130: else:-
+1131: v = observations[tree.col]-
/*else*/ { - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_col); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1131, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_observations, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1131, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_v = __pyx_t_4; - __pyx_t_4 = 0; -
+1132: branch = None-
__Pyx_INCREF(Py_None);
- __pyx_v_branch = Py_None;
-
+1133: if isinstance(v, int) or isinstance(v, float):-
__pyx_t_2 = PyInt_Check(__pyx_v_v); - __pyx_t_6 = (__pyx_t_2 != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_3 = __pyx_t_6; - goto __pyx_L5_bool_binop_done; - } - __pyx_t_6 = PyFloat_Check(__pyx_v_v); - __pyx_t_2 = (__pyx_t_6 != 0); - __pyx_t_3 = __pyx_t_2; - __pyx_L5_bool_binop_done:; - if (__pyx_t_3) { -/* … */ - goto __pyx_L4; - } -
+1134: if v >= tree.value:-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1134, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_v, __pyx_t_4, Py_GE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1134, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1134, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_3) { -/* … */ - goto __pyx_L7; - } -
+1135: branch = tree.trueBranch-
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1135, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF_SET(__pyx_v_branch, __pyx_t_5); - __pyx_t_5 = 0; -
1136: else:-
+1137: branch = tree.falseBranch-
/*else*/ { - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF_SET(__pyx_v_branch, __pyx_t_5); - __pyx_t_5 = 0; - } - __pyx_L7:; -
1138: else:-
+1139: if v == tree.value:-
/*else*/ { - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_value); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyObject_RichCompare(__pyx_v_v, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_3) { -/* … */ - goto __pyx_L8; - } -
+1140: branch = tree.trueBranch-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1140, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF_SET(__pyx_v_branch, __pyx_t_4); - __pyx_t_4 = 0; -
1141: else:-
+1142: branch = tree.falseBranch-
/*else*/ { - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1142, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF_SET(__pyx_v_branch, __pyx_t_4); - __pyx_t_4 = 0; - } - __pyx_L8:; - } - __pyx_L4:; - } -
+1143: return classifyWithoutMissingData(observations, branch)-
__Pyx_XDECREF(__pyx_r); - if (unlikely(!__pyx_cur_scope->__pyx_v_classifyWithoutMissingData)) { __Pyx_RaiseClosureNameError("classifyWithoutMissingData"); __PYX_ERR(0, 1143, __pyx_L1_error) } - __pyx_t_4 = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_classifyWithoutMissingData(__pyx_cur_scope->__pyx_v_classifyWithoutMissingData, __pyx_v_observations, __pyx_v_branch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1143, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; -
1144:
-+1145: def classifyWithMissingData(observations, tree):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_3classifyWithMissingData(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_2classifyWithMissingData[] = "\n Classifies (prediction) the observations according to the tree, assuming with missing data.\n\n Args\n ----\n observations : list of list\n The internal data format for the training data (combining X, Y, treatment).\n\n Returns\n -------\n tree.results, tree.upliftScore :\n The results in the leaf node.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_3classifyWithMissingData = {"classifyWithMissingData", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_3classifyWithMissingData, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_2classifyWithMissingData}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_3classifyWithMissingData(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_observations = 0; - PyObject *__pyx_v_tree = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("classifyWithMissingData (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_observations,&__pyx_n_s_tree,0}; - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_observations)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tree)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("classifyWithMissingData", 1, 2, 2, 1); __PYX_ERR(0, 1145, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "classifyWithMissingData") < 0)) __PYX_ERR(0, 1145, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_observations = values[0]; - __pyx_v_tree = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("classifyWithMissingData", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1145, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.classify.classifyWithMissingData", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_2classifyWithMissingData(__pyx_self, __pyx_v_observations, __pyx_v_tree); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_2classifyWithMissingData(PyObject *__pyx_self, PyObject *__pyx_v_observations, PyObject *__pyx_v_tree) { - struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify *__pyx_cur_scope; - struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify *__pyx_outer_scope; - PyObject *__pyx_v_v = NULL; - PyObject *__pyx_v_tr = NULL; - PyObject *__pyx_v_fr = NULL; - PyObject *__pyx_v_tcount = NULL; - PyObject *__pyx_v_fcount = NULL; - PyObject *__pyx_v_tw = NULL; - PyObject *__pyx_v_fw = NULL; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_k = NULL; - PyObject *__pyx_v_branch = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("classifyWithMissingData", 0); - __pyx_outer_scope = (struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct__classify *) __Pyx_CyFunction_GetClosure(__pyx_self); - __pyx_cur_scope = __pyx_outer_scope; -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftTreeClassifier.classify.classifyWithMissingData", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_v); - __Pyx_XDECREF(__pyx_v_tr); - __Pyx_XDECREF(__pyx_v_fr); - __Pyx_XDECREF(__pyx_v_tcount); - __Pyx_XDECREF(__pyx_v_fcount); - __Pyx_XDECREF(__pyx_v_tw); - __Pyx_XDECREF(__pyx_v_fw); - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_k); - __Pyx_XDECREF(__pyx_v_branch); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__10 = PyTuple_Pack(12, __pyx_n_s_observations, __pyx_n_s_tree, __pyx_n_s_v, __pyx_n_s_tr, __pyx_n_s_fr, __pyx_n_s_tcount, __pyx_n_s_fcount, __pyx_n_s_tw, __pyx_n_s_fw, __pyx_n_s_result, __pyx_n_s_k, __pyx_n_s_branch); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 1145, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__10); - __Pyx_GIVEREF(__pyx_tuple__10); -/* … */ - __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_3classifyWithMissingData, 0, __pyx_n_s_UpliftTreeClassifier_classify_lo_2, ((PyObject*)__pyx_cur_scope), __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1145, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_v_classifyWithMissingData = __pyx_t_1; - __pyx_t_1 = 0; - __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(2, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_classifyWithMissingData, 1145, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 1145, __pyx_L1_error) -
1146: '''-
1147: Classifies (prediction) the observations according to the tree, assuming with missing data.-
1148:
-1149: Args-
1150: -----
1151: observations : list of list-
1152: The internal data format for the training data (combining X, Y, treatment).-
1153:
-1154: Returns-
1155: --------
1156: tree.results, tree.upliftScore :-
1157: The results in the leaf node.-
1158: '''-
+1159: if tree.results is not None: # leaf-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_results); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = (__pyx_t_1 != Py_None); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { -/* … */ - } -
+1160: return tree.results-
__Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_results); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1160, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; -
1161: else:-
+1162: v = observations[tree.col]-
/*else*/ { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_col); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1162, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_observations, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1162, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_v = __pyx_t_4; - __pyx_t_4 = 0; -
+1163: if v is None:-
__pyx_t_3 = (__pyx_v_v == Py_None); - __pyx_t_2 = (__pyx_t_3 != 0); - if (__pyx_t_2) { -/* … */ - } -
+1164: tr = classifyWithMissingData(observations, tree.trueBranch)-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1164, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (unlikely(!__pyx_cur_scope->__pyx_v_classifyWithMissingData)) { __Pyx_RaiseClosureNameError("classifyWithMissingData"); __PYX_ERR(0, 1164, __pyx_L1_error) } - __pyx_t_1 = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_2classifyWithMissingData(__pyx_cur_scope->__pyx_v_classifyWithMissingData, __pyx_v_observations, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1164, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_tr = __pyx_t_1; - __pyx_t_1 = 0; -
+1165: fr = classifyWithMissingData(observations, tree.falseBranch)-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1165, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (unlikely(!__pyx_cur_scope->__pyx_v_classifyWithMissingData)) { __Pyx_RaiseClosureNameError("classifyWithMissingData"); __PYX_ERR(0, 1165, __pyx_L1_error) } - __pyx_t_4 = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_2classifyWithMissingData(__pyx_cur_scope->__pyx_v_classifyWithMissingData, __pyx_v_observations, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1165, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_fr = __pyx_t_4; - __pyx_t_4 = 0; -
+1166: tcount = sum(tr.values())-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tr, __pyx_n_s_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1166, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1166, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_sum, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1166, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_tcount = __pyx_t_1; - __pyx_t_1 = 0; -
+1167: fcount = sum(fr.values())-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_fr, __pyx_n_s_values); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1167, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1167, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_sum, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1167, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_fcount = __pyx_t_4; - __pyx_t_4 = 0; -
+1168: tw = float(tcount) / (tcount + fcount)-
__pyx_t_4 = __Pyx_PyNumber_Float(__pyx_v_tcount); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1168, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyNumber_Add(__pyx_v_tcount, __pyx_v_fcount); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1168, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1168, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_tw = __pyx_t_5; - __pyx_t_5 = 0; -
+1169: fw = float(fcount) / (tcount + fcount)-
__pyx_t_5 = __Pyx_PyNumber_Float(__pyx_v_fcount); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1169, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyNumber_Add(__pyx_v_tcount, __pyx_v_fcount); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1169, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1169, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_fw = __pyx_t_4; - __pyx_t_4 = 0; -
1170:
-1171: # Problem description: http://blog.ludovf.net/python-collections-defaultdict/-
+1172: result = defaultdict(int)-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1172, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_5, ((PyObject *)(&PyInt_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)(&PyInt_Type))); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1172, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_result = __pyx_t_4; - __pyx_t_4 = 0; -
+1173: for k, v in tr.items():-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tr, __pyx_n_s_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_1 = __pyx_t_4; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1173, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (likely(!__pyx_t_7)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1173, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1173, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_7(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1173, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { - PyObject* sequence = __pyx_t_4; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1173, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_5 = PyList_GET_ITEM(sequence, 0); - __pyx_t_8 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); - #else - __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_9 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; - index = 0; __pyx_t_5 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_5)) goto __pyx_L7_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L7_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) __PYX_ERR(0, 1173, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L8_unpacking_done; - __pyx_L7_unpacking_failed:; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1173, __pyx_L1_error) - __pyx_L8_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_5); - __pyx_t_5 = 0; - __Pyx_DECREF_SET(__pyx_v_v, __pyx_t_8); - __pyx_t_8 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+1174: result[k] += v * tw-
__Pyx_INCREF(__pyx_v_k); - __pyx_t_4 = __pyx_v_k; - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_result, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1174, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = PyNumber_Multiply(__pyx_v_v, __pyx_v_tw); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1174, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1174, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_t_4, __pyx_t_9) < 0)) __PYX_ERR(0, 1174, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
+1175: for k, v in fr.items():-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_fr, __pyx_n_s_items); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1175, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_7)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1175, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1175, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_7(__pyx_t_4); - if (unlikely(!__pyx_t_1)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1175, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1175, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_9 = PyList_GET_ITEM(sequence, 0); - __pyx_t_5 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_5); - #else - __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_8)->tp_iternext; - index = 0; __pyx_t_9 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_9)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_9); - index = 1; __pyx_t_5 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_5)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_8), 2) < 0) __PYX_ERR(0, 1175, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L12_unpacking_done; - __pyx_L11_unpacking_failed:; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1175, __pyx_L1_error) - __pyx_L12_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_9); - __pyx_t_9 = 0; - __Pyx_DECREF_SET(__pyx_v_v, __pyx_t_5); - __pyx_t_5 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
+1176: result[k] += v * fw-
__Pyx_INCREF(__pyx_v_k); - __pyx_t_1 = __pyx_v_k; - __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_result, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1176, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_9 = PyNumber_Multiply(__pyx_v_v, __pyx_v_fw); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1176, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_t_5, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1176, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_t_1, __pyx_t_8) < 0)) __PYX_ERR(0, 1176, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+1177: return dict(result)-
__Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), __pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1177, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; -
1178: else:-
+1179: branch = None-
/*else*/ {
- __Pyx_INCREF(Py_None);
- __pyx_v_branch = Py_None;
-
+1180: if isinstance(v, int) or isinstance(v, float):-
__pyx_t_3 = PyInt_Check(__pyx_v_v); - __pyx_t_11 = (__pyx_t_3 != 0); - if (!__pyx_t_11) { - } else { - __pyx_t_2 = __pyx_t_11; - goto __pyx_L14_bool_binop_done; - } - __pyx_t_11 = PyFloat_Check(__pyx_v_v); - __pyx_t_3 = (__pyx_t_11 != 0); - __pyx_t_2 = __pyx_t_3; - __pyx_L14_bool_binop_done:; - if (__pyx_t_2) { -/* … */ - goto __pyx_L13; - } -
+1181: if v >= tree.value:-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1181, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyObject_RichCompare(__pyx_v_v, __pyx_t_4, Py_GE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1181, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1181, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { -/* … */ - goto __pyx_L16; - } -
+1182: branch = tree.trueBranch-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF_SET(__pyx_v_branch, __pyx_t_1); - __pyx_t_1 = 0; -
1183: else:-
+1184: branch = tree.falseBranch-
/*else*/ { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1184, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF_SET(__pyx_v_branch, __pyx_t_1); - __pyx_t_1 = 0; - } - __pyx_L16:; -
1185: else:-
+1186: if v == tree.value:-
/*else*/ { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_RichCompare(__pyx_v_v, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1186, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1186, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_2) { -/* … */ - goto __pyx_L17; - } -
+1187: branch = tree.trueBranch-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_trueBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1187, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF_SET(__pyx_v_branch, __pyx_t_4); - __pyx_t_4 = 0; -
1188: else:-
+1189: branch = tree.falseBranch-
/*else*/ { - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_falseBranch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF_SET(__pyx_v_branch, __pyx_t_4); - __pyx_t_4 = 0; - } - __pyx_L17:; - } - __pyx_L13:; - } -
+1190: return classifyWithMissingData(observations, branch)-
__Pyx_XDECREF(__pyx_r); - if (unlikely(!__pyx_cur_scope->__pyx_v_classifyWithMissingData)) { __Pyx_RaiseClosureNameError("classifyWithMissingData"); __PYX_ERR(0, 1190, __pyx_L1_error) } - __pyx_t_4 = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_2classifyWithMissingData(__pyx_cur_scope->__pyx_v_classifyWithMissingData, __pyx_v_observations, __pyx_v_branch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1190, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - } -
1191:
-1192: # function body-
+1193: if dataMissing:-
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_dataMissing); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1193, __pyx_L1_error) - if (__pyx_t_2) { -/* … */ - } -
+1194: return classifyWithMissingData(observations, tree)-
__Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_2classifyWithMissingData(__pyx_cur_scope->__pyx_v_classifyWithMissingData, __pyx_v_observations, __pyx_v_tree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1194, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; -
1195: else:-
+1196: return classifyWithoutMissingData(observations, tree)-
/*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_pf_8causalml_9inference_4tree_6uplift_20UpliftTreeClassifier_8classify_classifyWithoutMissingData(__pyx_cur_scope->__pyx_v_classifyWithoutMissingData, __pyx_v_observations, __pyx_v_tree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - } -
1197:
- 1198:
-1199: # Uplift Random Forests-
+1200: class UpliftRandomForestClassifier:-
__pyx_t_1 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_empty_tuple, __pyx_n_s_UpliftRandomForestClassifier, __pyx_n_s_UpliftRandomForestClassifier, (PyObject *) NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_kp_s_Uplift_Random_Forest_for_Classi); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); -/* … */ - __pyx_t_2 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_n_s_UpliftRandomForestClassifier, __pyx_empty_tuple, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_UpliftRandomForestClassifier, __pyx_t_2) < 0) __PYX_ERR(0, 1200, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
1201: """ Uplift Random Forest for Classification Task.-
1202:
-1203: Parameters-
1204: -----------
1205: n_estimators : integer, optional (default=10)-
1206: The number of trees in the uplift random forest.-
1207:
-1208: evaluationFunction : string-
1209: Choose from one of the models: 'KL', 'ED', 'Chi', 'CTS', 'DDP'.-
1210:
-1211: max_features: int, optional (default=10)-
1212: The number of features to consider when looking for the best split.-
1213:
-1214: random_state: int, RandomState instance or None (default=None)-
1215: A random seed or `np.random.RandomState` to control randomness in building the trees and forest.-
1216:
-1217: max_depth: int, optional (default=5)-
1218: The maximum depth of the tree.-
1219:
-1220: min_samples_leaf: int, optional (default=100)-
1221: The minimum number of samples required to be split at a leaf node.-
1222:
-1223: min_samples_treatment: int, optional (default=10)-
1224: The minimum number of samples required of the experiment group to be split at a leaf node.-
1225:
-1226: n_reg: int, optional (default=10)-
1227: The regularization parameter defined in Rzepakowski et al. 2012, the-
1228: weight (in terms of sample size) of the parent node influence on the-
1229: child node, only effective for 'KL', 'ED', 'Chi', 'CTS' methods.-
1230:
-1231: control_name: string-
1232: The name of the control group (other experiment groups will be regarded as treatment groups)-
1233:
-1234: normalization: boolean, optional (default=True)-
1235: The normalization factor defined in Rzepakowski et al. 2012,-
1236: correcting for tests with large number of splits and imbalanced-
1237: treatment and control splits-
1238:
-1239: n_jobs: int, optional (default=-1)-
1240: The parallelization parameter to define how many parallel jobs need to be created.-
1241: This is passed on to joblib library for parallelizing uplift-tree creation and prediction.-
1242:
-1243: joblib_prefer: str, optional (default="threads")-
1244: The preferred backend for joblib (passed as `prefer` to joblib.Parallel). See the joblib-
1245: documentation for valid values.-
1246:
-1247: Outputs-
1248: -----------
1249: df_res: pandas dataframe-
1250: A user-level results dataframe containing the estimated individual treatment effect.-
1251: """-
+1252: def __init__(self,-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier___init__[] = "\n Initialize the UpliftRandomForestClassifier class.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_1__init__ = {"__init__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_1__init__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier___init__}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_control_name = 0; - PyObject *__pyx_v_n_estimators = 0; - PyObject *__pyx_v_max_features = 0; - PyObject *__pyx_v_random_state = 0; - PyObject *__pyx_v_max_depth = 0; - PyObject *__pyx_v_min_samples_leaf = 0; - PyObject *__pyx_v_min_samples_treatment = 0; - PyObject *__pyx_v_n_reg = 0; - PyObject *__pyx_v_evaluationFunction = 0; - PyObject *__pyx_v_normalization = 0; - PyObject *__pyx_v_n_jobs = 0; - PyObject *__pyx_v_joblib_prefer = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_control_name,&__pyx_n_s_n_estimators,&__pyx_n_s_max_features,&__pyx_n_s_random_state,&__pyx_n_s_max_depth,&__pyx_n_s_min_samples_leaf,&__pyx_n_s_min_samples_treatment,&__pyx_n_s_n_reg,&__pyx_n_s_evaluationFunction,&__pyx_n_s_normalization,&__pyx_n_s_n_jobs,&__pyx_n_s_joblib_prefer,0}; - PyObject* values[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; - values[2] = ((PyObject *)((PyObject *)__pyx_int_10)); - values[3] = ((PyObject *)((PyObject *)__pyx_int_10)); -/* … */ - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_control_name, PyObject *__pyx_v_n_estimators, PyObject *__pyx_v_max_features, PyObject *__pyx_v_random_state, PyObject *__pyx_v_max_depth, PyObject *__pyx_v_min_samples_leaf, PyObject *__pyx_v_min_samples_treatment, PyObject *__pyx_v_n_reg, PyObject *__pyx_v_evaluationFunction, PyObject *__pyx_v_normalization, PyObject *__pyx_v_n_jobs, PyObject *__pyx_v_joblib_prefer) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__", 0); -/* … */ - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftRandomForestClassifier.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__64 = PyTuple_Pack(13, __pyx_n_s_self, __pyx_n_s_control_name, __pyx_n_s_n_estimators, __pyx_n_s_max_features, __pyx_n_s_random_state, __pyx_n_s_max_depth, __pyx_n_s_min_samples_leaf, __pyx_n_s_min_samples_treatment, __pyx_n_s_n_reg, __pyx_n_s_evaluationFunction, __pyx_n_s_normalization, __pyx_n_s_n_jobs, __pyx_n_s_joblib_prefer); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(0, 1252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__64); - __Pyx_GIVEREF(__pyx_tuple__64); - __pyx_codeobj__65 = (PyObject*)__Pyx_PyCode_New(13, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__64, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_init, 1252, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__65)) __PYX_ERR(0, 1252, __pyx_L1_error) -/* … */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_joblib_prefer, __pyx_n_u_str) < 0) __PYX_ERR(0, 1252, __pyx_L1_error) - __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_1__init__, 0, __pyx_n_s_UpliftRandomForestClassifier___i, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__65)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_tuple__66); - __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_5, __pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_init, __pyx_t_5) < 0) __PYX_ERR(0, 1252, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_tuple__66 = PyTuple_Pack(11, ((PyObject *)__pyx_int_10), ((PyObject *)__pyx_int_10), ((PyObject *)Py_None), ((PyObject *)__pyx_int_5), ((PyObject *)__pyx_int_100), ((PyObject *)__pyx_int_10), ((PyObject *)__pyx_int_10), ((PyObject*)__pyx_n_s_KL), ((PyObject *)Py_True), ((PyObject *)__pyx_int_neg_1), ((PyObject*)__pyx_n_s_threads)); if (unlikely(!__pyx_tuple__66)) __PYX_ERR(0, 1252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__66); - __Pyx_GIVEREF(__pyx_tuple__66); -
1253: control_name,-
1254: n_estimators=10,-
1255: max_features=10,-
+1256: random_state=None,-
values[4] = ((PyObject *)((PyObject *)Py_None)); - values[5] = ((PyObject *)((PyObject *)__pyx_int_5)); - values[6] = ((PyObject *)((PyObject *)__pyx_int_100)); - values[7] = ((PyObject *)((PyObject *)__pyx_int_10)); - values[8] = ((PyObject *)((PyObject *)__pyx_int_10)); - values[9] = ((PyObject *)((PyObject*)__pyx_n_s_KL)); -
1257: max_depth=5,-
1258: min_samples_leaf=100,-
1259: min_samples_treatment=10,-
1260: n_reg=10,-
1261: evaluationFunction='KL',-
+1262: normalization=True,-
values[10] = ((PyObject *)((PyObject *)Py_True)); - values[11] = ((PyObject *)((PyObject *)__pyx_int_neg_1)); - values[12] = ((PyObject*)((PyObject*)__pyx_n_s_threads)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); - CYTHON_FALLTHROUGH; - case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); - CYTHON_FALLTHROUGH; - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - CYTHON_FALLTHROUGH; - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - CYTHON_FALLTHROUGH; - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_control_name)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 13, 1); __PYX_ERR(0, 1252, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_estimators); - if (value) { values[2] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_features); - if (value) { values[3] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_random_state); - if (value) { values[4] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_depth); - if (value) { values[5] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 6: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_samples_leaf); - if (value) { values[6] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 7: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_samples_treatment); - if (value) { values[7] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 8: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_reg); - if (value) { values[8] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 9: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_evaluationFunction); - if (value) { values[9] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 10: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_normalization); - if (value) { values[10] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 11: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_jobs); - if (value) { values[11] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 12: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_joblib_prefer); - if (value) { values[12] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1252, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); - CYTHON_FALLTHROUGH; - case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); - CYTHON_FALLTHROUGH; - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - CYTHON_FALLTHROUGH; - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - CYTHON_FALLTHROUGH; - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_control_name = values[1]; - __pyx_v_n_estimators = values[2]; - __pyx_v_max_features = values[3]; - __pyx_v_random_state = values[4]; - __pyx_v_max_depth = values[5]; - __pyx_v_min_samples_leaf = values[6]; - __pyx_v_min_samples_treatment = values[7]; - __pyx_v_n_reg = values[8]; - __pyx_v_evaluationFunction = values[9]; - __pyx_v_normalization = values[10]; - __pyx_v_n_jobs = values[11]; - __pyx_v_joblib_prefer = ((PyObject*)values[12]); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 13, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1252, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftRandomForestClassifier.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_joblib_prefer), (&PyString_Type), 1, "joblib_prefer", 1))) __PYX_ERR(0, 1264, __pyx_L1_error) - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier___init__(__pyx_self, __pyx_v_self, __pyx_v_control_name, __pyx_v_n_estimators, __pyx_v_max_features, __pyx_v_random_state, __pyx_v_max_depth, __pyx_v_min_samples_leaf, __pyx_v_min_samples_treatment, __pyx_v_n_reg, __pyx_v_evaluationFunction, __pyx_v_normalization, __pyx_v_n_jobs, __pyx_v_joblib_prefer); -
1263: n_jobs=-1,-
1264: joblib_prefer: str = "threads"):-
1265:
-1266: """-
1267: Initialize the UpliftRandomForestClassifier class.-
1268: """-
+1269: self.n_estimators = n_estimators-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_n_estimators, __pyx_v_n_estimators) < 0) __PYX_ERR(0, 1269, __pyx_L1_error) -
+1270: self.max_features = max_features-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_max_features, __pyx_v_max_features) < 0) __PYX_ERR(0, 1270, __pyx_L1_error) -
+1271: self.random_state = random_state-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_random_state, __pyx_v_random_state) < 0) __PYX_ERR(0, 1271, __pyx_L1_error) -
+1272: self.max_depth = max_depth-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_max_depth, __pyx_v_max_depth) < 0) __PYX_ERR(0, 1272, __pyx_L1_error) -
+1273: self.min_samples_leaf = min_samples_leaf-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_leaf, __pyx_v_min_samples_leaf) < 0) __PYX_ERR(0, 1273, __pyx_L1_error) -
+1274: self.min_samples_treatment = min_samples_treatment-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_min_samples_treatment, __pyx_v_min_samples_treatment) < 0) __PYX_ERR(0, 1274, __pyx_L1_error) -
+1275: self.n_reg = n_reg-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_n_reg, __pyx_v_n_reg) < 0) __PYX_ERR(0, 1275, __pyx_L1_error) -
+1276: self.evaluationFunction = evaluationFunction-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_evaluationFunction, __pyx_v_evaluationFunction) < 0) __PYX_ERR(0, 1276, __pyx_L1_error) -
+1277: self.control_name = control_name-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_control_name, __pyx_v_control_name) < 0) __PYX_ERR(0, 1277, __pyx_L1_error) -
+1278: self.normalization = normalization-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_normalization, __pyx_v_normalization) < 0) __PYX_ERR(0, 1278, __pyx_L1_error) -
+1279: self.n_jobs = n_jobs-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_n_jobs, __pyx_v_n_jobs) < 0) __PYX_ERR(0, 1279, __pyx_L1_error) -
+1280: self.joblib_prefer = joblib_prefer-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_joblib_prefer, __pyx_v_joblib_prefer) < 0) __PYX_ERR(0, 1280, __pyx_L1_error) -
1281:
-+1282: assert control_name is not None and isinstance(control_name, str), \-
#ifndef CYTHON_WITHOUT_ASSERTIONS
- if (unlikely(!Py_OptimizeFlag)) {
- __pyx_t_2 = (__pyx_v_control_name != Py_None);
- __pyx_t_3 = (__pyx_t_2 != 0);
- if (__pyx_t_3) {
- } else {
- __pyx_t_1 = __pyx_t_3;
- goto __pyx_L3_bool_binop_done;
- }
- __pyx_t_3 = PyString_Check(__pyx_v_control_name);
- __pyx_t_2 = (__pyx_t_3 != 0);
- __pyx_t_1 = __pyx_t_2;
- __pyx_L3_bool_binop_done:;
- if (unlikely(!__pyx_t_1)) {
-
+1283: f"control_group should be string but {control_name} is passed"-
__pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1283, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = 0; - __pyx_t_6 = 127; - __Pyx_INCREF(__pyx_kp_u_control_group_should_be_string_b); - __pyx_t_5 += 35; - __Pyx_GIVEREF(__pyx_kp_u_control_group_should_be_string_b); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_control_group_should_be_string_b); - __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_v_control_name, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1283, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_6; - __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_kp_u_is_passed); - __pyx_t_5 += 10; - __Pyx_GIVEREF(__pyx_kp_u_is_passed); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_is_passed); - __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1283, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - PyErr_SetObject(PyExc_AssertionError, __pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __PYX_ERR(0, 1282, __pyx_L1_error) - } - } - #endif -
+1284: self.control_name = control_name-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_control_name, __pyx_v_control_name) < 0) __PYX_ERR(0, 1284, __pyx_L1_error) -
+1285: self.classes_ = [control_name]-
__pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1285, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_control_name); - __Pyx_GIVEREF(__pyx_v_control_name); - PyList_SET_ITEM(__pyx_t_7, 0, __pyx_v_control_name); - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_classes, __pyx_t_7) < 0) __PYX_ERR(0, 1285, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
+1286: self.n_class = 1-
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_n_class, __pyx_int_1) < 0) __PYX_ERR(0, 1286, __pyx_L1_error) -
1287:
-+1288: if self.n_jobs == -1:-
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n_jobs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_t_7, __pyx_int_neg_1, -1L, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1288, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_1) { -/* … */ - } -
+1289: self.n_jobs = mp.cpu_count()-
__Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_mp); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_cpu_count); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_n_jobs, __pyx_t_4) < 0) __PYX_ERR(0, 1289, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
1290:
-+1291: def fit(self, X, treatment, y):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_2fit[] = "\n Fit the UpliftRandomForestClassifier.\n\n Args\n ----\n X : ndarray, shape = [num_samples, num_features]\n An ndarray of the covariates used to train the uplift model.\n\n treatment : array-like, shape = [num_samples]\n An array containing the treatment group for each unit.\n\n y : array-like, shape = [num_samples]\n An array containing the outcome of interest for each unit.\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit = {"fit", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_2fit}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fit (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_treatment,&__pyx_n_s_y,0}; - PyObject* values[4] = {0,0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 1); __PYX_ERR(0, 1291, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 2); __PYX_ERR(0, 1291, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 3); __PYX_ERR(0, 1291, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fit") < 0)) __PYX_ERR(0, 1291, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_treatment = values[2]; - __pyx_v_y = values[3]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1291, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftRandomForestClassifier.fit", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_2fit(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_treatment, __pyx_v_y); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit_2generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* … */ -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_2fit(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment, PyObject *__pyx_v_y) { - struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_1_fit *__pyx_cur_scope; - PyObject *__pyx_v_random_state = NULL; - PyObject *__pyx_v_treatment_groups = NULL; - PyObject *__pyx_v_tr = NULL; - PyObject *__pyx_v_all_importances = NULL; - CYTHON_UNUSED PyObject *__pyx_v__ = NULL; - PyObject *__pyx_v_x = NULL; - PyObject *__pyx_gb_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit_2generator = 0; - PyObject *__pyx_v_tree = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fit", 0); - __pyx_cur_scope = (struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_1_fit *)__pyx_tp_new_8causalml_9inference_4tree_6uplift___pyx_scope_struct_1_fit(__pyx_ptype_8causalml_9inference_4tree_6uplift___pyx_scope_struct_1_fit, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_1_fit *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1291, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_X = __pyx_v_X; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_X); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_X); - __pyx_cur_scope->__pyx_v_treatment = __pyx_v_treatment; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_treatment); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_treatment); - __pyx_cur_scope->__pyx_v_y = __pyx_v_y; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_y); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_y); -/* … */ - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftRandomForestClassifier.fit", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_random_state); - __Pyx_XDECREF(__pyx_v_treatment_groups); - __Pyx_XDECREF(__pyx_v_tr); - __Pyx_XDECREF(__pyx_v_all_importances); - __Pyx_XDECREF(__pyx_v__); - __Pyx_XDECREF(__pyx_v_x); - __Pyx_XDECREF(__pyx_gb_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit_2generator); - __Pyx_XDECREF(__pyx_v_tree); - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__67 = PyTuple_Pack(13, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_treatment, __pyx_n_s_y, __pyx_n_s_random_state, __pyx_n_s_treatment_groups, __pyx_n_s_tr, __pyx_n_s_all_importances, __pyx_n_s__34, __pyx_n_s_x, __pyx_n_s_genexpr, __pyx_n_s_genexpr, __pyx_n_s_tree); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(0, 1291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__67); - __Pyx_GIVEREF(__pyx_tuple__67); -/* … */ - __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit, 0, __pyx_n_s_UpliftRandomForestClassifier_fit_2, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__68)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_fit, __pyx_t_5) < 0) __PYX_ERR(0, 1291, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_codeobj__68 = (PyObject*)__Pyx_PyCode_New(4, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__67, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_fit, 1291, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__68)) __PYX_ERR(0, 1291, __pyx_L1_error) -/* … */ -struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_1_fit { - PyObject_HEAD - PyObject *__pyx_v_X; - PyObject *__pyx_v_self; - PyObject *__pyx_v_treatment; - PyObject *__pyx_v_y; -}; - -
1292: """-
1293: Fit the UpliftRandomForestClassifier.-
1294:
-1295: Args-
1296: -----
1297: X : ndarray, shape = [num_samples, num_features]-
1298: An ndarray of the covariates used to train the uplift model.-
1299:
-1300: treatment : array-like, shape = [num_samples]-
1301: An array containing the treatment group for each unit.-
1302:
-1303: y : array-like, shape = [num_samples]-
1304: An array containing the outcome of interest for each unit.-
1305: """-
+1306: random_state = check_random_state(self.random_state)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_check_random_state); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_random_state); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_random_state = __pyx_t_1; - __pyx_t_1 = 0; -
1307:
-1308: # Create forest-
+1309: self.uplift_forest = [-
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); -/* … */ - if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_uplift_forest, __pyx_t_1) < 0) __PYX_ERR(0, 1309, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+1310: UpliftTreeClassifier(-
__Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_UpliftTreeClassifier); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1310, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); -/* … */ - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1310, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 1309, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
+1311: max_features=self.max_features, max_depth=self.max_depth,-
__pyx_t_4 = __Pyx_PyDict_NewPresized(9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_max_features); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_max_features, __pyx_t_7) < 0) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_max_depth); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_max_depth, __pyx_t_7) < 0) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
+1312: min_samples_leaf=self.min_samples_leaf,-
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_min_samples_leaf); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1312, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_min_samples_leaf, __pyx_t_7) < 0) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
+1313: min_samples_treatment=self.min_samples_treatment,-
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_min_samples_treatment); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1313, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_min_samples_treatment, __pyx_t_7) < 0) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
+1314: n_reg=self.n_reg,-
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_n_reg); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1314, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_n_reg, __pyx_t_7) < 0) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
+1315: evaluationFunction=self.evaluationFunction,-
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_evaluationFunction); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1315, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_evaluationFunction, __pyx_t_7) < 0) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
+1316: control_name=self.control_name,-
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1316, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_control_name, __pyx_t_7) < 0) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
+1317: normalization=self.normalization,-
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_normalization); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1317, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_normalization, __pyx_t_7) < 0) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
+1318: random_state=random_state.randint(MAX_INT))-
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_random_state, __pyx_n_s_randint); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1318, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_MAX_INT); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1318, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - __pyx_t_7 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_10, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1318, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_random_state, __pyx_t_7) < 0) __PYX_ERR(0, 1311, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
+1319: for _ in range(self.n_estimators)-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_n_estimators); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - } else { - __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1319, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1319, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } else { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1319, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } - } else { - __pyx_t_3 = __pyx_t_6(__pyx_t_2); - if (unlikely(!__pyx_t_3)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1319, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_3); - __pyx_t_3 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
1320: ]-
1321:
-1322: # Get treatment group keys. self.classes_[0] is reserved for the control group.-
+1323: treatment_groups = sorted([x for x in list(set(treatment)) if x != self.control_name])-
__pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = PySet_New(__pyx_cur_scope->__pyx_v_treatment); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = PySequence_List(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __pyx_t_4; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1323, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_x, __pyx_t_4, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1323, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1323, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_11) { - if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_v_x))) __PYX_ERR(0, 1323, __pyx_L1_error) - } - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_1 = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_12 = PyList_Sort(__pyx_t_1); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 1323, __pyx_L1_error) - __pyx_v_treatment_groups = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; -
+1324: self.classes_ = [self.control_name]-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1324, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1324, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __pyx_t_1 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_classes, __pyx_t_2) < 0) __PYX_ERR(0, 1324, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+1325: for tr in treatment_groups:-
if (unlikely(__pyx_v_treatment_groups == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); - __PYX_ERR(0, 1325, __pyx_L1_error) - } - __pyx_t_2 = __pyx_v_treatment_groups; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0; - for (;;) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1325, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1325, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - __Pyx_XDECREF_SET(__pyx_v_tr, __pyx_t_1); - __pyx_t_1 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+1326: self.classes_.append(tr)-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1326, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_12 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_v_tr); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 1326, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+1327: self.n_class = len(self.classes_)-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1327, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1327, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1327, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_n_class, __pyx_t_2) < 0) __PYX_ERR(0, 1327, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
1328:
-+1329: self.uplift_forest = (-
if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_uplift_forest, __pyx_t_2) < 0) __PYX_ERR(0, 1329, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+1330: Parallel(n_jobs=self.n_jobs, prefer=self.joblib_prefer)-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_Parallel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1330, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1330, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_n_jobs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1330, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_n_jobs, __pyx_t_3) < 0) __PYX_ERR(0, 1330, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_joblib_prefer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1330, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_prefer, __pyx_t_3) < 0) __PYX_ERR(0, 1330, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1330, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
+1331: (delayed(self.bootstrap)(X, treatment, y, tree) for tree in self.uplift_forest)-
static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit_genexpr(PyObject *__pyx_self) { - struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_2_genexpr *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("genexpr", 0); - __pyx_cur_scope = (struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_2_genexpr *)__pyx_tp_new_8causalml_9inference_4tree_6uplift___pyx_scope_struct_2_genexpr(__pyx_ptype_8causalml_9inference_4tree_6uplift___pyx_scope_struct_2_genexpr, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_2_genexpr *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1331, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_1_fit *) __pyx_self; - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit_2generator, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_UpliftRandomForestClassifier_fit, __pyx_n_s_causalml_inference_tree_uplift); if (unlikely(!gen)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } - - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftRandomForestClassifier.fit.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_gb_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit_2generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("genexpr", 0); - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1331, __pyx_L1_error) - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 1331, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self, __pyx_n_s_uplift_forest); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1331, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1331, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1331, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_4(__pyx_t_2); - if (unlikely(!__pyx_t_1)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1331, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_tree); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_tree, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_delayed); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 1331, __pyx_L1_error) } - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self, __pyx_n_s_bootstrap); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_X)) { __Pyx_RaiseClosureNameError("X"); __PYX_ERR(0, 1331, __pyx_L1_error) } - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_treatment)) { __Pyx_RaiseClosureNameError("treatment"); __PYX_ERR(0, 1331, __pyx_L1_error) } - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_y)) { __Pyx_RaiseClosureNameError("y"); __PYX_ERR(0, 1331, __pyx_L1_error) } - __pyx_t_6 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_X, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_treatment, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_y, __pyx_cur_scope->__pyx_v_tree}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_X, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_treatment, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_y, __pyx_cur_scope->__pyx_v_tree}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_7 = PyTuple_New(4+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_6) { - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; - } - __Pyx_INCREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_X); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_X); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_X); - __Pyx_INCREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_treatment); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_treatment); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_treatment); - __Pyx_INCREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_y); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_9, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_y); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_tree); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_tree); - PyTuple_SET_ITEM(__pyx_t_7, 3+__pyx_t_9, __pyx_cur_scope->__pyx_v_tree); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - __Pyx_XGIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_2); - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1331, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - - /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - #if !CYTHON_USE_EXC_INFO_STACK - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - #endif - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_t_7 = __pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_3fit_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -/* … */ -struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_2_genexpr { - PyObject_HEAD - struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_1_fit *__pyx_outer_scope; - PyObject *__pyx_v_tree; - PyObject *__pyx_t_0; - Py_ssize_t __pyx_t_1; - PyObject *(*__pyx_t_2)(PyObject *); -}; - -
1332: )-
1333:
-+1334: all_importances = [tree.feature_importances_ for tree in self.uplift_forest]-
__pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_uplift_forest); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_7 = __pyx_t_3; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - } else { - __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1334, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_7))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1334, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } else { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1334, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } - } else { - __pyx_t_3 = __pyx_t_6(__pyx_t_7); - if (unlikely(!__pyx_t_3)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1334, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF_SET(__pyx_v_tree, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_feature_importances); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1334, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 1334, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_all_importances = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; -
+1335: self.feature_importances_ = np.mean(all_importances, axis=0)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1335, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_mean); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1335, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1335, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_all_importances); - __Pyx_GIVEREF(__pyx_v_all_importances); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_all_importances); - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1335, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_axis, __pyx_int_0) < 0) __PYX_ERR(0, 1335, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1335, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_feature_importances, __pyx_t_1) < 0) __PYX_ERR(0, 1335, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
+1336: self.feature_importances_ /= self.feature_importances_.sum() # normalize to add to 1-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_feature_importances); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1336, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_feature_importances); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1336, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_sum); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1336, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1336, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyNumber_InPlaceDivide(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1336, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_feature_importances, __pyx_t_7) < 0) __PYX_ERR(0, 1336, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -
1337:
-+1338: @staticmethod-
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_staticmethod, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1338, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_bootstrap, __pyx_t_2) < 0) __PYX_ERR(0, 1339, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+1339: def bootstrap(X, treatment, y, tree):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_5bootstrap(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_5bootstrap = {"bootstrap", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_5bootstrap, METH_VARARGS|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_5bootstrap(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_treatment = 0; - PyObject *__pyx_v_y = 0; - PyObject *__pyx_v_tree = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("bootstrap (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_X,&__pyx_n_s_treatment,&__pyx_n_s_y,&__pyx_n_s_tree,0}; - PyObject* values[4] = {0,0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_treatment)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("bootstrap", 1, 4, 4, 1); __PYX_ERR(0, 1339, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("bootstrap", 1, 4, 4, 2); __PYX_ERR(0, 1339, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tree)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("bootstrap", 1, 4, 4, 3); __PYX_ERR(0, 1339, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bootstrap") < 0)) __PYX_ERR(0, 1339, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - } - __pyx_v_X = values[0]; - __pyx_v_treatment = values[1]; - __pyx_v_y = values[2]; - __pyx_v_tree = values[3]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("bootstrap", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1339, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftRandomForestClassifier.bootstrap", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_4bootstrap(__pyx_self, __pyx_v_X, __pyx_v_treatment, __pyx_v_y, __pyx_v_tree); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_4bootstrap(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_X, PyObject *__pyx_v_treatment, PyObject *__pyx_v_y, PyObject *__pyx_v_tree) { - PyObject *__pyx_v_random_state = NULL; - PyObject *__pyx_v_bt_index = NULL; - PyObject *__pyx_v_x_train_bt = NULL; - PyObject *__pyx_v_y_train_bt = NULL; - PyObject *__pyx_v_treatment_train_bt = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("bootstrap", 0); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftRandomForestClassifier.bootstrap", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_random_state); - __Pyx_XDECREF(__pyx_v_bt_index); - __Pyx_XDECREF(__pyx_v_x_train_bt); - __Pyx_XDECREF(__pyx_v_y_train_bt); - __Pyx_XDECREF(__pyx_v_treatment_train_bt); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__69 = PyTuple_Pack(9, __pyx_n_s_X, __pyx_n_s_treatment, __pyx_n_s_y, __pyx_n_s_tree, __pyx_n_s_random_state, __pyx_n_s_bt_index, __pyx_n_s_x_train_bt, __pyx_n_s_y_train_bt, __pyx_n_s_treatment_train_bt); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(0, 1339, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__69); - __Pyx_GIVEREF(__pyx_tuple__69); -/* … */ - __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_5bootstrap, __Pyx_CYFUNCTION_STATICMETHOD, __pyx_n_s_UpliftRandomForestClassifier_boo, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__70)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1339, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_codeobj__70 = (PyObject*)__Pyx_PyCode_New(4, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__69, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_bootstrap, 1339, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__70)) __PYX_ERR(0, 1339, __pyx_L1_error) -
+1340: random_state = check_random_state(tree.random_state)-
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_check_random_state); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1340, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_random_state); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1340, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1340, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_random_state = __pyx_t_1; - __pyx_t_1 = 0; -
+1341: bt_index = random_state.choice(len(X), len(X))-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_random_state, __pyx_n_s_choice); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1341, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyObject_Length(__pyx_v_X); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1341, __pyx_L1_error) - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1341, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_Length(__pyx_v_X); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1341, __pyx_L1_error) - __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1341, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1341, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1341, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1341, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (__pyx_t_6) { - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; - } - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_4); - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1341, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_bt_index = __pyx_t_1; - __pyx_t_1 = 0; -
+1342: x_train_bt = X[bt_index]-
__pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_v_bt_index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1342, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_x_train_bt = __pyx_t_1; - __pyx_t_1 = 0; -
+1343: y_train_bt = y[bt_index]-
__pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_y, __pyx_v_bt_index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1343, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_y_train_bt = __pyx_t_1; - __pyx_t_1 = 0; -
+1344: treatment_train_bt = treatment[bt_index]-
__pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_treatment, __pyx_v_bt_index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1344, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_treatment_train_bt = __pyx_t_1; - __pyx_t_1 = 0; -
+1345: tree.fit(X=x_train_bt, treatment=treatment_train_bt, y=y_train_bt)-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_fit); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_X, __pyx_v_x_train_bt) < 0) __PYX_ERR(0, 1345, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_treatment, __pyx_v_treatment_train_bt) < 0) __PYX_ERR(0, 1345, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_y, __pyx_v_y_train_bt) < 0) __PYX_ERR(0, 1345, __pyx_L1_error) - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -
+1346: return tree-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_tree); - __pyx_r = __pyx_v_tree; - goto __pyx_L0; -
1347:
-+1348: @ignore_warnings(category=FutureWarning)-
__Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ignore_warnings); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_category, __pyx_builtin_FutureWarning) < 0) __PYX_ERR(0, 1348, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -
+1349: def predict(self, X, full_output=False):-
/* Python wrapper */ -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_6predict[] = "\n Returns the recommended treatment group and predicted optimal\n probability conditional on using the recommended treatment group.\n\n Args\n ----\n X : ndarray, shape = [num_samples, num_features]\n An ndarray of the covariates used to train the uplift model.\n\n full_output : bool, optional (default=False)\n Whether the UpliftTree algorithm returns upliftScores, pred_nodes\n alongside the recommended treatment group and p_hat in the treatment group.\n\n Returns\n -------\n y_pred_list : ndarray, shape = (num_samples, num_treatments])\n An ndarray containing the predicted treatment effect of each treatment group for each sample\n\n df_res : DataFrame, shape = [num_samples, (num_treatments * 2 + 3)]\n If `full_output` is `True`, a DataFrame containing the predicted outcome of each treatment and\n control group, the treatment effect of each treatment group, the treatment group with the\n highest treatment effect, and the maximum treatment effect for each sample.\n\n "; -static PyMethodDef __pyx_mdef_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict = {"predict", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_6predict}; -static PyObject *__pyx_pw_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_X = 0; - PyObject *__pyx_v_full_output = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("predict (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_X,&__pyx_n_s_full_output,0}; - PyObject* values[3] = {0,0,0}; - values[2] = ((PyObject *)((PyObject *)Py_False)); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_X)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("predict", 0, 2, 3, 1); __PYX_ERR(0, 1349, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_full_output); - if (value) { values[2] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "predict") < 0)) __PYX_ERR(0, 1349, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_self = values[0]; - __pyx_v_X = values[1]; - __pyx_v_full_output = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("predict", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1349, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftRandomForestClassifier.predict", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_6predict(__pyx_self, __pyx_v_self, __pyx_v_X, __pyx_v_full_output); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict_2generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* … */ -static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_6predict(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_full_output) { - struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_3_predict *__pyx_cur_scope; - PyObject *__pyx_v_y_pred_ensemble = NULL; - PyObject *__pyx_v_df_res = NULL; - PyObject *__pyx_v_delta_cols = NULL; - PyObject *__pyx_v_i_tr = NULL; - PyObject *__pyx_v_treatment_group = NULL; - PyObject *__pyx_gb_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict_2generator1 = 0; - PyObject *__pyx_v_tree = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("predict", 0); - __pyx_cur_scope = (struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_3_predict *)__pyx_tp_new_8causalml_9inference_4tree_6uplift___pyx_scope_struct_3_predict(__pyx_ptype_8causalml_9inference_4tree_6uplift___pyx_scope_struct_3_predict, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_3_predict *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1349, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_X = __pyx_v_X; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_X); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_X); -/* … */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftRandomForestClassifier.predict", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_y_pred_ensemble); - __Pyx_XDECREF(__pyx_v_df_res); - __Pyx_XDECREF(__pyx_v_delta_cols); - __Pyx_XDECREF(__pyx_v_i_tr); - __Pyx_XDECREF(__pyx_v_treatment_group); - __Pyx_XDECREF(__pyx_gb_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict_2generator1); - __Pyx_XDECREF(__pyx_v_tree); - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_tuple__71 = PyTuple_Pack(11, __pyx_n_s_self, __pyx_n_s_X, __pyx_n_s_full_output, __pyx_n_s_y_pred_ensemble, __pyx_n_s_df_res, __pyx_n_s_delta_cols, __pyx_n_s_i_tr, __pyx_n_s_treatment_group, __pyx_n_s_genexpr, __pyx_n_s_genexpr, __pyx_n_s_tree); if (unlikely(!__pyx_tuple__71)) __PYX_ERR(0, 1349, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__71); - __Pyx_GIVEREF(__pyx_tuple__71); - __pyx_codeobj__72 = (PyObject*)__Pyx_PyCode_New(3, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__71, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_causalml_inference_tree_uplift_p, __pyx_n_s_predict, 1349, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__72)) __PYX_ERR(0, 1349, __pyx_L1_error) -/* … */ - __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict, 0, __pyx_n_s_UpliftRandomForestClassifier_pre_2, NULL, __pyx_n_s_causalml_inference_tree_uplift, __pyx_d, ((PyObject *)__pyx_codeobj__72)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1349, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_tuple__73); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_predict, __pyx_t_2) < 0) __PYX_ERR(0, 1349, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -/* … */ -struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_3_predict { - PyObject_HEAD - PyObject *__pyx_v_X; - PyObject *__pyx_v_self; -}; - -
1350: '''-
1351: Returns the recommended treatment group and predicted optimal-
1352: probability conditional on using the recommended treatment group.-
1353:
-1354: Args-
1355: -----
1356: X : ndarray, shape = [num_samples, num_features]-
1357: An ndarray of the covariates used to train the uplift model.-
1358:
-1359: full_output : bool, optional (default=False)-
1360: Whether the UpliftTree algorithm returns upliftScores, pred_nodes-
1361: alongside the recommended treatment group and p_hat in the treatment group.-
1362:
-1363: Returns-
1364: --------
1365: y_pred_list : ndarray, shape = (num_samples, num_treatments])-
1366: An ndarray containing the predicted treatment effect of each treatment group for each sample-
1367:
-1368: df_res : DataFrame, shape = [num_samples, (num_treatments * 2 + 3)]-
1369: If `full_output` is `True`, a DataFrame containing the predicted outcome of each treatment and-
1370: control group, the treatment effect of each treatment group, the treatment group with the-
1371: highest treatment effect, and the maximum treatment effect for each sample.-
1372:
-1373: '''-
1374: # Make predictions with all trees and take the average-
1375:
-+1376: if self.n_jobs != 1:-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_n_jobs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1376, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_NeObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1376, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1376, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_3) { -/* … */ - goto __pyx_L3; - } -
+1377: y_pred_ensemble = sum(-
__pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_sum, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1377, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -
+1378: Parallel(n_jobs=self.n_jobs, prefer=self.joblib_prefer)-
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_Parallel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_n_jobs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_n_jobs, __pyx_t_5) < 0) __PYX_ERR(0, 1378, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_joblib_prefer); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_prefer, __pyx_t_5) < 0) __PYX_ERR(0, 1378, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
+1379: (delayed(tree.predict)(X=X) for tree in self.uplift_forest)-
static PyObject *__pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict_genexpr(PyObject *__pyx_self) { - struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_4_genexpr *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("genexpr", 0); - __pyx_cur_scope = (struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_4_genexpr *)__pyx_tp_new_8causalml_9inference_4tree_6uplift___pyx_scope_struct_4_genexpr(__pyx_ptype_8causalml_9inference_4tree_6uplift___pyx_scope_struct_4_genexpr, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_4_genexpr *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1379, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_8causalml_9inference_4tree_6uplift___pyx_scope_struct_3_predict *) __pyx_self; - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict_2generator1, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_UpliftRandomForestClassifier_pre, __pyx_n_s_causalml_inference_tree_uplift); if (unlikely(!gen)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } - - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("causalml.inference.tree.uplift.UpliftRandomForestClassifier.predict.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_gb_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict_2generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("genexpr", 0); - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1379, __pyx_L1_error) - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 1379, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self, __pyx_n_s_uplift_forest); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1379, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1379, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1379, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_4(__pyx_t_2); - if (unlikely(!__pyx_t_1)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1379, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_tree); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_tree, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_delayed); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_tree, __pyx_n_s_predict); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_X)) { __Pyx_RaiseClosureNameError("X"); __PYX_ERR(0, 1379, __pyx_L1_error) } - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_X, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_X) < 0) __PYX_ERR(0, 1379, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; - __Pyx_XGIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_2); - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1379, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - - /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - #if !CYTHON_USE_EXC_INFO_STACK - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - #endif - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* … */ - __pyx_t_4 = __pyx_pf_8causalml_9inference_4tree_6uplift_28UpliftRandomForestClassifier_7predict_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; -
+1380: ) / len(self.uplift_forest)-
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_uplift_forest); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1380, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_y_pred_ensemble = __pyx_t_4; - __pyx_t_4 = 0; -
1381: else:-
+1382: y_pred_ensemble = sum([tree.predict(X=X) for tree in self.uplift_forest]) / len(self.uplift_forest)-
/*else*/ { - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_uplift_forest); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_5 = __pyx_t_2; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1382, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_7)) { - if (likely(PyList_CheckExact(__pyx_t_5))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1382, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1382, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_7(__pyx_t_5); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1382, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_tree, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_predict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_X, __pyx_cur_scope->__pyx_v_X) < 0) __PYX_ERR(0, 1382, __pyx_L1_error) - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_8))) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_sum, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_uplift_forest); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyNumber_Divide(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_y_pred_ensemble = __pyx_t_8; - __pyx_t_8 = 0; - } - __pyx_L3:; -
1383:
-1384: # Summarize results into dataframe-
+1385: df_res = pd.DataFrame(y_pred_ensemble, columns=self.classes_)-
__Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_pd); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_DataFrame); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v_y_pred_ensemble); - __Pyx_GIVEREF(__pyx_v_y_pred_ensemble); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_y_pred_ensemble); - __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_columns, __pyx_t_1) < 0) __PYX_ERR(0, 1385, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_df_res = __pyx_t_1; - __pyx_t_1 = 0; -
+1386: df_res['recommended_treatment'] = df_res.apply(np.argmax, axis=1)-
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_df_res, __pyx_n_s_apply); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_argmax); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_axis, __pyx_int_1) < 0) __PYX_ERR(0, 1386, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_df_res, __pyx_n_s_recommended_treatment, __pyx_t_4) < 0)) __PYX_ERR(0, 1386, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
1387:
-1388: # Calculate delta-
+1389: delta_cols = [f'delta_{treatment_group}' for treatment_group in self.classes_[1:]]-
__pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = __Pyx_PyObject_GetSlice(__pyx_t_8, 1, 0, NULL, NULL, &__pyx_slice__3, 1, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) { - __pyx_t_8 = __pyx_t_5; __Pyx_INCREF(__pyx_t_8); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1389, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - for (;;) { - if (likely(!__pyx_t_7)) { - if (likely(PyList_CheckExact(__pyx_t_8))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1389, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_8, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } else { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1389, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_8, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } - } else { - __pyx_t_5 = __pyx_t_7(__pyx_t_8); - if (unlikely(!__pyx_t_5)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1389, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - __Pyx_XDECREF_SET(__pyx_v_treatment_group, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_v_treatment_group, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_PyUnicode_Concat(__pyx_n_u_delta, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_1))) __PYX_ERR(0, 1389, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_delta_cols = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; -
+1390: for i_tr in range(1, self.n_class):-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_n_class); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1390, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1390, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_int_1); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1390, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_8 = __pyx_t_4; __Pyx_INCREF(__pyx_t_8); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1390, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1390, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (likely(!__pyx_t_7)) { - if (likely(PyList_CheckExact(__pyx_t_8))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1390, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_8, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1390, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1390, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_8, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1390, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_7(__pyx_t_8); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1390, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF_SET(__pyx_v_i_tr, __pyx_t_4); - __pyx_t_4 = 0; -/* … */ - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; -
+1391: treatment_group = self.classes_[i_tr]-
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_classes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1391, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_v_i_tr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1391, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_treatment_group, __pyx_t_1); - __pyx_t_1 = 0; -
+1392: df_res[f'delta_{treatment_group}'] = df_res[treatment_group] - df_res[self.control_name]-
__pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_df_res, __pyx_v_treatment_group); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_control_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_df_res, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Subtract(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_v_treatment_group, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_PyUnicode_Concat(__pyx_n_u_delta, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_df_res, __pyx_t_1, __pyx_t_4) < 0)) __PYX_ERR(0, 1392, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -
1393:
-+1394: df_res['max_delta'] = df_res[delta_cols].max(axis=1)-
__pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_df_res, __pyx_v_delta_cols); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_max); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_axis, __pyx_int_1) < 0) __PYX_ERR(0, 1394, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_df_res, __pyx_n_s_max_delta, __pyx_t_1) < 0)) __PYX_ERR(0, 1394, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; -
1395:
-+1396: if full_output:-
__pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_full_output); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1396, __pyx_L1_error) - if (__pyx_t_3) { -/* … */ - } -
+1397: return df_res-
__Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_df_res); - __pyx_r = __pyx_v_df_res; - goto __pyx_L0; -
1398: else:-
+1399: return df_res[delta_cols].values-
/*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_df_res, __pyx_v_delta_cols); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_values); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; - goto __pyx_L0; - } -