% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cv_estimators.R
\name{werm_logistic_cv}
\alias{werm_logistic_cv}
\title{Fit a WERM changepoint model with logistic loss and CV selection}
\usage{
werm_logistic_cv(
  X,
  y,
  max_num_chgpts,
  delta = 1L,
  search_method = "efficient",
  cv = 5L,
  fit_intercept = TRUE,
  max_iter = 100L,
  tol = 1e-05,
  use_base_loss_for_cv = FALSE,
  penalty = "l2",
  alpha = 1
)
}
\arguments{
\item{X}{Numeric matrix of shape \verb{(n, p)}. Observations must be in order.}

\item{y}{Integer or factor vector of binary labels.}

\item{max_num_chgpts}{Integer. Upper bound of the CV search grid.}

\item{delta}{Integer. Minimum gap between candidate changepoints.
Default \code{1}.}

\item{search_method}{Character. \code{"efficient"} (default) or \code{"brute_force"}.}

\item{cv}{Integer. Number of interleaved folds. Default \code{5}.}

\item{fit_intercept}{Logical. Default \code{TRUE}.}

\item{max_iter}{Integer. Maximum L-BFGS-B iterations. Default \code{100}.}

\item{tol}{Numeric. Gradient-norm tolerance. Default \code{1e-5}.}

\item{use_base_loss_for_cv}{Logical. If \code{TRUE}, uses logistic loss for CV
segment scoring instead of the default absolute error. Default \code{FALSE}.}

\item{penalty}{Character. Default \code{"l2"}.}

\item{alpha}{Numeric. Default \code{1.0}.}
}
\value{
An object of class \code{c("werm_logistic_cv", "werm_fit")}.
Contains all CV elements plus \code{classes} (character vector of length 2).
}
\description{
Fit a WERM changepoint model with logistic loss and CV selection
}
\examples{
# Limit BLAS/OpenMP threads so example CPU time stays proportional to
# elapsed time on multicore CRAN machines.
Sys.setenv(
  OMP_NUM_THREADS = "1",
  OPENBLAS_NUM_THREADS = "1",
  MKL_NUM_THREADS = "1",
  BLAS_NUM_THREADS = "1"
)

if (nzchar(Sys.getenv("RETICULATE_PYTHON")) &&
    weightederm_examples_available("WERMLogisticCV")) {
  set.seed(12)
  n <- 30L; p <- 2L
  X <- matrix(rnorm(n * p), n, p)
  eta <- c(
    X[1:10, ] \%*\% c(3, -3),
    X[11:20, ] \%*\% c(-3, 3),
    X[21:30, ] \%*\% c(3, -3)
  )
  y <- rbinom(n, 1L, 1 / (1 + exp(-eta)))
  fit <- werm_logistic_cv(X, y, max_num_chgpts = 2L, cv = 3L, delta = 3L,
                          fit_intercept = FALSE, max_iter = 100L)
  fit$best_num_chgpts
  fit$changepoints
}

}
