| Title: | Positive and Unlabeled Learning from Unbalanced Cases and Sparse Structures |
|---|---|
| Description: | Provides PLUS-derived extensions for positive and unlabeled (PU) learning from unbalanced cases and sparse structures, based on Zhou et al. (2022) <doi:10.1371/journal.pcbi.1009956>. Iteratively relabels unlabeled observations via penalised logistic regression and pseudo-label updates, then refits a final sparse model. Includes weighted bootstrap sampling, convergence diagnostics, prediction, coefficient extraction, and assessment utilities. |
| Authors: | Angel Robles [aut, cre] (ORCID: <https://orcid.org/0000-0002-4674-4270>) |
| Maintainer: | Angel Robles <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.2 |
| Built: | 2026-09-27 14:18:16 UTC |
| Source: | https://github.com/alrobles/xplus |
Assess predictive performance
assess(object, newx = NULL, newy, weights = NULL, ...) ## S3 method for class 'xplus' assess(object, newx = NULL, newy, weights = NULL, ...)assess(object, newx = NULL, newy, weights = NULL, ...) ## S3 method for class 'xplus' assess(object, newx = NULL, newy, weights = NULL, ...)
object |
A model object. |
newx |
Optional feature matrix. |
newy |
Binary 0/1 labels or a two-column finite nonnegative matrix of negative and positive class masses; soft vectors are not accepted. |
weights |
Optional finite nonnegative numeric row weights without recycling; NULL means unit weights. |
... |
Additional arguments passed to |
A named list with deviance, class, auc, mse, and mae.
For class metric, the threshold used is the model's cutoff (from
object$cutoff), consistent with predict(type = "class"); MSE and MAE sum both class-column losses (twice the scalar loss). Undefined metrics return NA with a warning.
Zhou et al. (2022). doi:10.1371/journal.pcbi.1009956
set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) assess(fit, newx = x, newy = y)set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) assess(fit, newx = x, newy = y)
Compute area under the ROC curve
auc(y, prob, w = NULL)auc(y, prob, w = NULL)
y |
Binary 0/1 vector, including logical, character, or factor encodings. |
prob |
Finite numeric scores, one per label; values outside |
w |
Optional finite nonnegative numeric sample weights; NULL means unit weights. |
Numeric rank AUC with half credit for ties; NA with a warning if either effective class mass is zero.
Zhou et al. (2022). doi:10.1371/journal.pcbi.1009956
y <- c(0, 0, 1, 1) p <- c(0.1, 0.3, 0.7, 0.9) auc(y, p)y <- c(0, 0, 1, 1) p <- c(0.1, 0.3, 0.7, 0.9) auc(y, p)
Compute AUC from matrix labels
auc_matrix(y, prob, weights = NULL)auc_matrix(y, prob, weights = NULL)
y |
Two-column finite nonnegative class masses (negative, positive); soft labels, counts, and zero-mass rows are supported. |
prob |
Finite numeric scores, one per row; values outside |
weights |
Optional finite nonnegative numeric row weights without recycling; NULL means unit weights. |
Weighted rank AUC with half credit for ties; NA with a warning if either effective class mass is zero.
Zhou et al. (2022). doi:10.1371/journal.pcbi.1009956
y <- cbind(c(1, 1, 0, 0), c(0, 0, 1, 1)) p <- c(0.2, 0.3, 0.7, 0.8) auc_matrix(y, p)y <- cbind(c(1, 1, 0, 0), c(0, 0, 1, 1)) p <- c(0.2, 0.3, 0.7, 0.8) auc_matrix(y, p)
A small binary example dataset used in package examples.
binexamplebinexample
A data frame.
Extract coefficients from an xplus model
## S3 method for class 'xplus' coef(object, s = "lambda.min", ...)## S3 method for class 'xplus' coef(object, s = "lambda.min", ...)
object |
An |
s |
Penalty value name or numeric lambda. |
... |
Additional arguments. |
A sparse coefficient matrix.
summary.xplus(), print.xplus()
set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) coef(fit)set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) coef(fit)
Example cutoff values used in demonstrations.
cutoff_examplecutoff_example
A numeric vector.
Example model fit used in package documentation.
fit_xplus_examplefit_xplus_example
An object of class xplus.
Compute AUC for predictions from a model
get_auc(object, newx = NULL, newy = NULL, weights = NULL, ...) ## S3 method for class 'xplus' get_auc(object, newx = NULL, newy = NULL, weights = NULL, ...)get_auc(object, newx = NULL, newy = NULL, weights = NULL, ...) ## S3 method for class 'xplus' get_auc(object, newx = NULL, newy = NULL, weights = NULL, ...)
object |
A model object. |
newx |
Feature matrix. |
newy |
True labels. |
weights |
Optional sample weights. |
... |
Arguments passed to |
Numeric AUC value.
set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) get_auc(fit, newx = x, newy = y)set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) get_auc(fit, newx = x, newy = y)
Build a tidy prediction table
get_predictions(object, newx, newy, use_cutoff = TRUE)get_predictions(object, newx, newy, use_cutoff = TRUE)
object |
An |
newx |
Feature matrix. |
newy |
True labels. |
use_cutoff |
Logical; if |
A tibble with truth labels, probabilities and predicted classes; Class1 is the positive label 1, classified by probability strictly greater than the cutoff.
Zhou et al. (2022). doi:10.1371/journal.pcbi.1009956
set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) get_predictions(fit, x, y)set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) get_predictions(fit, x, y)
Example dataset from the original PLUS package.
lacslacs
A data frame.
Sample subset of the LACS data.
lacsSamplelacsSample
A data frame.
Predict from an xplus model
## S3 method for class 'xplus' predict(object, newx = NULL, s = "lambda.min", type = "response", ...)## S3 method for class 'xplus' predict(object, newx = NULL, s = "lambda.min", type = "response", ...)
object |
An |
newx |
Optional finite numeric feature matrix; defaults to training data. Named training features must match and are reordered automatically. |
s |
Exact penalty name ( |
type |
Prediction type: |
... |
Additional arguments are not supported and cause an error. |
Probabilities (type = "response") or log-odds (type = "link"); cached probabilities of 0 and 1 give infinite log-odds.
Classes use a factor with fixed levels "0", "1" for one lambda, or a dimension-preserving 0/1 matrix for multiple lambdas.
Zhou et al. (2022). doi:10.1371/journal.pcbi.1009956
set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) predict(fit, newx = x, type = "response") predict(fit, newx = x, type = "link")set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) predict(fit, newx = x, type = "response") predict(fit, newx = x, type = "link")
Sparse coefficients extracted from an xplus model.
predicted_coefficients_examplepredicted_coefficients_example
A sparse matrix.
Predicted probabilities from an xplus model.
predicted_y_examplepredicted_y_example
A numeric matrix.
Zhou et al. (2022). doi:10.1371/journal.pcbi.1009956
Print method for summary.xplus objects
## S3 method for class 'summary.xplus' print(x, ...)## S3 method for class 'summary.xplus' print(x, ...)
x |
A |
... |
Additional arguments. |
The input object x is returned invisibly (called for side
effects).
Print an xplus model
## S3 method for class 'xplus' print(x, digits = max(3, getOption("digits") - 3), ...)## S3 method for class 'xplus' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
An |
digits |
Number of significant digits. |
... |
Additional arguments. |
Invisibly returns x.
Zhou et al. (2022). doi:10.1371/journal.pcbi.1009956
set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) print(fit)set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) print(fit)
Summarize an xplus model
## S3 method for class 'xplus' summary(object, ...)## S3 method for class 'xplus' summary(object, ...)
object |
An |
... |
Additional arguments. |
A list of class summary.xplus with model details.
Zhou et al. (2022). doi:10.1371/journal.pcbi.1009956
set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) summary(fit)set.seed(1) x <- matrix(rnorm(100 * 5), ncol = 5) y <- c(rep(1, 20), rep(0, 80)) fit <- xplus(x, y, max_iter = 5) summary(fit)
Fit a PLUS-derived model for positive-unlabeled learning.
xplus( x, y, alpha = 1, sample_use_time = 30, learning_rate = 1, qq = 0.1, verbose = FALSE, nfolds = 4, max_iter = 10000, convergence_threshold = 0.9, seed = NULL, sigmoid_scale = 10, min_iter = 5, stability_window = 5, min_coverage = 0.9, sampling = c("bootstrap", "unique"), cv_measure = c("deviance", "auc"), degenerate_threshold = 1e-06 )xplus( x, y, alpha = 1, sample_use_time = 30, learning_rate = 1, qq = 0.1, verbose = FALSE, nfolds = 4, max_iter = 10000, convergence_threshold = 0.9, seed = NULL, sigmoid_scale = 10, min_iter = 5, stability_window = 5, min_coverage = 0.9, sampling = c("bootstrap", "unique"), cv_measure = c("deviance", "auc"), degenerate_threshold = 1e-06 )
x |
Finite numeric feature matrix with at least two columns. |
y |
Binary vector where |
alpha |
Elastic-net mixing parameter in |
sample_use_time |
Unlabeled-sampling budget inherited from the reference implementation: maximum number of completed sampling rounds containing each unlabeled case, not the number of bootstrap copies within a round. |
learning_rate |
Pseudo-label smoothing rate in |
qq |
Quantile used to define the positive-reference cutoff. |
verbose |
Logical; print iterative progress messages. |
nfolds |
Requested CV folds, an integer at least three; reduced for small classes. |
max_iter |
Maximum number of pseudo-labeling iterations. |
convergence_threshold |
Required stability score in |
seed |
Integer or |
sigmoid_scale, degenerate_threshold
|
Positive sigmoid scale and nonnegative residual-clamping tolerance. |
min_iter, stability_window
|
Minimum iterations and consecutive stable iterations required before declaring convergence.
|
min_coverage |
Minimum fraction of unlabeled cases sampled before convergence, in |
sampling, cv_measure
|
Sampling convention ( |
Core PLUS behavior alternates between fitting penalized logistic models on known positives plus sampled unlabeled cases, anchoring predictions to a positive quantile cutoff, and iteratively relabeling unlabeled samples.
An object of class "xplus" containing predictions, original and final labels, pseudo-labels, fallback metadata, sampling counts, and history.
Zhou et al. (2022). doi:10.1371/journal.pcbi.1009956
predict.xplus(), summary.xplus(), assess.xplus()
set.seed(1) x <- matrix(rnorm(200 * 10), ncol = 10) y <- c(rep(1, 40), rep(0, 160)) fit <- xplus(x, y, max_iter = 20)set.seed(1) x <- matrix(rnorm(200 * 10), ncol = 10) y <- c(rep(1, 40), rep(0, 160)) fit <- xplus(x, y, max_iter = 20)
Saved xplus object for examples and tests.
xplus_object_examplexplus_object_example
An object of class xplus.