Skip to content

Commit 8da8a15

Browse files
authored
FIX add argument to _check_sample_weight (#73)
Fix the following bug: ``` >>> from treeple.ensemble import ObliqueRandomForestClassifier >>> from sklearn.datasets import make_classification >>> X,y = make_classification(n_samples=1000, n_features=4,n_informative=2,n_redundant=0,random_state=0,shuffle=False) >>> clf = ObliqueRandomForestClassifier(max_depth=2, random_state=0) >>> clf.fit(X,y) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/pssf23/miniconda3/envs/temp/lib/python3.10/site-packages/sklearn/base.py", line 1363, in wrapper return fit_method(estimator, *args, **kwargs) File "/Users/pssf23/miniconda3/envs/temp/lib/python3.10/site-packages/treeple/_lib/sklearn/ensemble/_forest.py", line 597, in fit self._construct_trees( File "/Users/pssf23/miniconda3/envs/temp/lib/python3.10/site-packages/treeple/_lib/sklearn/ensemble/_forest.py", line 663, in _construct_trees trees = Parallel( File "/Users/pssf23/miniconda3/envs/temp/lib/python3.10/site-packages/sklearn/utils/parallel.py", line 82, in __call__ return super().__call__(iterable_with_config_and_warning_filters) File "/Users/pssf23/miniconda3/envs/temp/lib/python3.10/site-packages/joblib/parallel.py", line 1986, in __call__ return output if self.return_generator else list(output) File "/Users/pssf23/miniconda3/envs/temp/lib/python3.10/site-packages/joblib/parallel.py", line 1914, in _get_sequential_output res = func(*args, **kwargs) File "/Users/pssf23/miniconda3/envs/temp/lib/python3.10/site-packages/sklearn/utils/parallel.py", line 147, in __call__ return self.function(*args, **kwargs) File "/Users/pssf23/miniconda3/envs/temp/lib/python3.10/site-packages/treeple/_lib/sklearn/ensemble/_forest.py", line 211, in _parallel_build_trees tree._fit( File "/Users/pssf23/miniconda3/envs/temp/lib/python3.10/site-packages/treeple/_lib/sklearn/tree/_classes.py", line 395, in _fit sample_weight = _check_sample_weight(sample_weight, X, DOUBLE) TypeError: _check_sample_weight() takes 2 positional arguments but 3 were given ```
1 parent 0e43e91 commit 8da8a15

5 files changed

Lines changed: 28 additions & 21 deletions

File tree

build_tools/circle/build_doc.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ conda activate $CONDA_ENV_NAME
176176

177177
show_installed_libraries
178178

179-
pip install -e . --no-build-isolation
179+
# reduce memory pressure
180+
pip install scikit-learn
180181

181182
echo "ccache build summary:"
182183
ccache -s

sklearn/cluster/_hdbscan/_tree.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ cdef tuple _get_clusters(
783783
else:
784784
is_cluster[c] = False
785785

786-
clusters = set([c for c in is_cluster if is_cluster[c]])
786+
clusters = {c for c in is_cluster if is_cluster[c]}
787787
cluster_map = {c: n for n, c in enumerate(sorted(list(clusters)))}
788788
reverse_cluster_map = {n: c for c, n in cluster_map.items()}
789789

sklearn/ensemble/_forest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ def partial_fit(self, X, y, sample_weight=None, classes=None):
12751275
multi_output=True,
12761276
accept_sparse="csc",
12771277
dtype=DTYPE,
1278-
force_all_finite=False,
1278+
ensure_all_finite=False,
12791279
reset=first_call,
12801280
)
12811281

sklearn/tree/_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def _fit(
401401
max_leaf_nodes = -1 if self.max_leaf_nodes is None else self.max_leaf_nodes
402402

403403
if sample_weight is not None:
404-
sample_weight = _check_sample_weight(sample_weight, X, DOUBLE)
404+
sample_weight = _check_sample_weight(sample_weight, X, dtype=DOUBLE)
405405

406406
if y is not None and expanded_class_weight is not None:
407407
if sample_weight is not None:

sklearn/utils/_cython_blas.pyx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ cdef void _gemv(BLAS_Order order, BLAS_Trans ta, int m, int n, floating alpha,
126126
floating beta, floating *y, int incy) noexcept nogil:
127127
"""y := alpha * op(A).x + beta * y"""
128128
cdef char ta_ = ta
129-
if order == RowMajor:
130-
ta_ = NoTrans if ta == Trans else Trans
129+
if order == BLAS_Order.RowMajor:
130+
ta_ = BLAS_Trans.NoTrans if ta == BLAS_Trans.Trans else BLAS_Trans.Trans
131131
if floating is float:
132132
sgemv(&ta_, &n, &m, &alpha, <float *> A, &lda, <float *> x,
133133
&incx, &beta, y, &incy)
@@ -148,8 +148,10 @@ cpdef _gemv_memview(BLAS_Trans ta, floating alpha, const floating[:, :] A,
148148
cdef:
149149
int m = A.shape[0]
150150
int n = A.shape[1]
151-
BLAS_Order order = ColMajor if A.strides[0] == A.itemsize else RowMajor
152-
int lda = m if order == ColMajor else n
151+
BLAS_Order order = (
152+
BLAS_Order.ColMajor if A.strides[0] == A.itemsize else BLAS_Order.RowMajor
153+
)
154+
int lda = m if order == BLAS_Order.ColMajor else n
153155

154156
_gemv(order, ta, m, n, alpha, &A[0, 0], lda, &x[0], 1, beta, &y[0], 1)
155157

@@ -158,7 +160,7 @@ cdef void _ger(BLAS_Order order, int m, int n, floating alpha,
158160
const floating *x, int incx, const floating *y,
159161
int incy, floating *A, int lda) noexcept nogil:
160162
"""A := alpha * x.y.T + A"""
161-
if order == RowMajor:
163+
if order == BLAS_Order.RowMajor:
162164
if floating is float:
163165
sger(&n, &m, &alpha, <float *> y, &incy, <float *> x, &incx, A, &lda)
164166
else:
@@ -175,8 +177,10 @@ cpdef _ger_memview(floating alpha, const floating[::1] x,
175177
cdef:
176178
int m = A.shape[0]
177179
int n = A.shape[1]
178-
BLAS_Order order = ColMajor if A.strides[0] == A.itemsize else RowMajor
179-
int lda = m if order == ColMajor else n
180+
BLAS_Order order = (
181+
BLAS_Order.ColMajor if A.strides[0] == A.itemsize else BLAS_Order.RowMajor
182+
)
183+
int lda = m if order == BLAS_Order.ColMajor else n
180184

181185
_ger(order, m, n, alpha, &x[0], 1, &y[0], 1, &A[0, 0], lda)
182186

@@ -194,7 +198,7 @@ cdef void _gemm(BLAS_Order order, BLAS_Trans ta, BLAS_Trans tb, int m, int n,
194198
cdef:
195199
char ta_ = ta
196200
char tb_ = tb
197-
if order == RowMajor:
201+
if order == BLAS_Order.RowMajor:
198202
if floating is float:
199203
sgemm(&tb_, &ta_, &n, &m, &k, &alpha, <float*>B,
200204
&ldb, <float*>A, &lda, &beta, C, &ldc)
@@ -214,19 +218,21 @@ cpdef _gemm_memview(BLAS_Trans ta, BLAS_Trans tb, floating alpha,
214218
const floating[:, :] A, const floating[:, :] B, floating beta,
215219
floating[:, :] C):
216220
cdef:
217-
int m = A.shape[0] if ta == NoTrans else A.shape[1]
218-
int n = B.shape[1] if tb == NoTrans else B.shape[0]
219-
int k = A.shape[1] if ta == NoTrans else A.shape[0]
221+
int m = A.shape[0] if ta == BLAS_Trans.NoTrans else A.shape[1]
222+
int n = B.shape[1] if tb == BLAS_Trans.NoTrans else B.shape[0]
223+
int k = A.shape[1] if ta == BLAS_Trans.NoTrans else A.shape[0]
220224
int lda, ldb, ldc
221-
BLAS_Order order = ColMajor if A.strides[0] == A.itemsize else RowMajor
225+
BLAS_Order order = (
226+
BLAS_Order.ColMajor if A.strides[0] == A.itemsize else BLAS_Order.RowMajor
227+
)
222228

223-
if order == RowMajor:
224-
lda = k if ta == NoTrans else m
225-
ldb = n if tb == NoTrans else k
229+
if order == BLAS_Order.RowMajor:
230+
lda = k if ta == BLAS_Trans.NoTrans else m
231+
ldb = n if tb == BLAS_Trans.NoTrans else k
226232
ldc = n
227233
else:
228-
lda = m if ta == NoTrans else k
229-
ldb = k if tb == NoTrans else n
234+
lda = m if ta == BLAS_Trans.NoTrans else k
235+
ldb = k if tb == BLAS_Trans.NoTrans else n
230236
ldc = m
231237

232238
_gemm(order, ta, tb, m, n, k, alpha, &A[0, 0],

0 commit comments

Comments
 (0)