(
X: Sequence[Sequence[float]],
y: Sequence[float],
feature_names: Sequence[str] | None = None,
sample_weight: Sequence[float] | None = None,
event_end_indices: Sequence[int] | None = None,
n_splits: int = 5,
pct_embargo: float = 0.01,
scoring: str = "neg_log_loss",
)
| 403 | break |
| 404 | scale *= 0.5 |
| 405 | if cand_obj > objective: |
| 406 | break |
| 407 | coefficient_small = max(abs(scale * s) for s in step) < tol * ( |
| 408 | 1 + max(abs(b) for b in beta) |
| 409 | ) |
| 410 | # A tiny coefficient step can still move logits by order one when |
| 411 | # features are huge. Also retain the coefficient criterion for ridge |
| 412 | # movement in a likelihood nullspace. |
| 413 | change = [Fraction(c) - b for c, b in zip(candidate, bq)] |
| 414 | # Scale each observation by its own logit. A negligible-weight outlier |
| 415 | # with an enormous logit must not hide progress on the other rows. |
| 416 | logits_small = all( |
| 417 | abs(sum((v * d for v, d in zip(row, change)), Fraction())) |
| 418 | < Fraction(tol) * (1 + abs(sum((v * b for v, b in zip(row, bq)), Fraction()))) |
| 419 | for row, w in zip(rows, sw) |
| 420 | if w |
| 421 | ) |
| 422 | converged = coefficient_small and logits_small |
| 423 | beta, objective = candidate, cand_obj |
| 424 | if converged: |
| 425 | break |
| 426 | return _LinearModel(coeffs=beta[1:], intercept=beta[0]) |
| 427 | |
| 428 | |
| 429 | def _material_loss_cancellation( |
| 430 | design: list[list[float]], |
| 431 | y: Sequence[float], |
| 432 | weights: list[float], |
| 433 | beta: list[float], |
| 434 | objective: float, |
| 435 | ) -> bool: |
| 436 | # Called only for weights large relative to the penalty. Tiny harmless tail |
| 437 | # roundoff must not change the ordinary fitting path. |
| 438 | for row, yy, w in zip(design, y, weights): |
| 439 | if yy != 1.0 or w == 0: |
| 440 | continue |
| 441 | z = _dot(row, beta) |
| 442 | if z > 0 and isfinite(z): |
| 443 | tail = log1p(exp(-z)) |
| 444 | lost = abs(((z + tail) - z) - tail) |
| 445 | if w * lost > _EPS * abs(objective): |
| 446 | return True |
| 447 | return False |
| 448 | |
| 449 | |
| 450 | def _fit_linear_probability_model( |
| 451 | x: Sequence[Sequence[float]], |
| 452 | y: Sequence[float], |
| 453 | sample_weight: Sequence[float] | None, |
| 454 | ridge: float = 1e-3, |
| 455 | max_iter: int = 50, |
| 456 | tol: float = 1e-8, |
| 457 | ) -> _LinearModel: |
nothing calls this directly
no test coverage detected