-
Notifications
You must be signed in to change notification settings - Fork 110
Open
Description
I get this error from certain optbinning fittings:
TypeError Traceback (most recent call last)
[<ipython-input-2-f32626932f5e>](https://localhost:8080/#) in <cell line: 0>()
10 # for col in X.columns:
11 # bp.fit_transform(X[col], y)
---> 12 bp.fit_transform(X['mean area'], y)
13
14 # bp = OptimalBinning()
[/usr/local/lib/python3.11/dist-packages/optbinning/binning/binning.py](https://localhost:8080/#) in fit_transform(self, x, y, sample_weight, metric, metric_special, metric_missing, show_digits, check_input)
606 Transformed array.
607 """
--> 608 return self.fit(x, y, sample_weight, check_input).transform(
609 x, metric, metric_special, metric_missing, show_digits,
610 check_input)
[/usr/local/lib/python3.11/dist-packages/optbinning/binning/binning.py](https://localhost:8080/#) in fit(self, x, y, sample_weight, check_input)
556 Fitted optimal binning.
557 """
--> 558 return self._fit(x, y, sample_weight, check_input)
559
560 def fit_transform(self, x, y, sample_weight=None, metric="woe",
[/usr/local/lib/python3.11/dist-packages/optbinning/binning/binning.py](https://localhost:8080/#) in _fit(self, x, y, sample_weight, check_input)
828
829 # Optimization
--> 830 self._fit_optimizer(splits, n_nonevent, n_event)
831
832 # Post-processing
[/usr/local/lib/python3.11/dist-packages/optbinning/binning/binning.py](https://localhost:8080/#) in _fit_optimizer(self, splits, n_nonevent, n_event)
1018 logger.info("Optimizer: build model...")
1019
-> 1020 optimizer.build_model(self.divergence, n_nonevent, n_event,
1021 trend_change)
1022
[/usr/local/lib/python3.11/dist-packages/optbinning/binning/cp.py](https://localhost:8080/#) in build_model(self, divergence, n_nonevent, n_event, trend_change)
78 regularization * (pmax - pmin))
79 else:
---> 80 model.Maximize(sum([(V[i][i] * x[i, i]) +
81 sum([(V[i][j] - V[i][j+1]) * x[i, j]
82 for j in range(i)]) for i in range(n)]))
[/usr/local/lib/python3.11/dist-packages/optbinning/binning/cp.py](https://localhost:8080/#) in <listcomp>(.0)
78 regularization * (pmax - pmin))
79 else:
---> 80 model.Maximize(sum([(V[i][i] * x[i, i]) +
81 sum([(V[i][j] - V[i][j+1]) * x[i, j]
82 for j in range(i)]) for i in range(n)]))
TypeError: __radd__(): incompatible function arguments. The following argument types are supported:
1. (self: object, other: int) -> ortools.sat.python.cp_model_helper.LinearExpr
2. (self: object, arg0: float) -> ortools.sat.python.cp_model_helper.LinearExpr
Invoked with: SumArray(IntAffine(expr=x[5, 0](0..1), coeff=562277, offset=0), IntAffine(expr=x[5, 1](0..1), coeff=236900, offset=0), IntAffine(expr=x[5, 2](0..1), coeff=199303, offset=0), IntAffine(expr=x[5, 3](0..1), coeff=69286, offset=0), IntAffine(expr=x[5, 4](0..1), coeff=23302, offset=0)), IntConstant(0)
That sounds like a change from ortools
, and I can confirm that things seem to work if I downgrade from ortools 9.12.4544 to 9.11.4210. But even with 9.12 I sometimes get no error, and I don't immediately see why. The above was generated from the following code, but replacing mean area
by mean radius
and it runs fine. (This is on Colab, which currently has python 3.11.11, optbinning version 0.20.0.)
from optbinning import OptimalBinning
from sklearn.datasets import load_breast_cancer
X, y = load_breast_cancer(return_X_y=True, as_frame=True)
bp = OptimalBinning()
bp.fit_transform(X['mean area'], y)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Projects
Status
No status