diff --git a/AGENTS.md b/AGENTS.md index 7657bb2..649a676 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -3,7 +3,7 @@ R package for **partial dependence plots (PDPs)** and **individual conditional expectation (ICE) curves** from fitted ML models. Exports: `partial()` (the workhorse), `plot()` methods (tinyplot/base graphics, default engine), -`plotPartial()` (lattice), `exemplar()`, and the deprecated `topPredictors()`. +`plotPartial()` (lattice), and `exemplar()`. ## Branches & releases @@ -12,8 +12,10 @@ workhorse), `plot()` methods (tinyplot/base graphics, default engine), - **`main`**: stable releases only, tagged `vX.Y.Z`. r-universe (pinned to main in bgreenwell/bgreenwell.r-universe.dev) and the pkgdown site both build from main — never push experimental work there. -- Release: merge devel → main, drop the `.9000` suffix and dev NEWS heading, - tag, push; then bump devel to the next `.9000`. +- Release: merge devel → main (`--no-ff`), drop the `.9000` suffix and dev + NEWS heading, tag, push, `gh release create`; then **merge main back into + devel** (else the release merge commit leaves devel "behind" main) and bump + devel to the next `.9000`. - Shared fixes that main needs immediately (CI, README): commit to **main first, then merge main → devel**. Never cherry-pick devel → main — it duplicates commits and makes main appear "ahead" of devel. diff --git a/DESCRIPTION b/DESCRIPTION index bd2f589..ed3d44d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: pdp Type: Package Title: Partial Dependence Plots -Version: 0.9.1 +Version: 0.9.1.9000 Authors@R: person(c("Brandon", "M."), family = "Greenwell", email = "greenwell.brandon@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-8120-0084")) diff --git a/NAMESPACE b/NAMESPACE index dc21770..4b21a92 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,12 +11,9 @@ S3method(plot,partial) S3method(plotPartial,cice) S3method(plotPartial,ice) S3method(plotPartial,partial) -S3method(topPredictors,default) -S3method(topPredictors,train) export(exemplar) export(partial) export(plotPartial) -export(topPredictors) export(trellis.last.object) importFrom(lattice,dotplot) importFrom(lattice,equal.count) diff --git a/NEWS.md b/NEWS.md index 2675a74..0c51236 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# pdp (development version) + +## Breaking changes + +* Removed `topPredictors()`, which had been deprecated since pdp 0.8.0; use + the [vip](https://bgreenwell.github.io/vip/) package to identify important + predictors instead. + + # pdp 0.9.1 ## Deprecations diff --git a/R/topPredictors.R b/R/topPredictors.R deleted file mode 100644 index a78e03e..0000000 --- a/R/topPredictors.R +++ /dev/null @@ -1,88 +0,0 @@ -#' Extract Most "Important" Predictors (Experimental) -#' -#' Extract the most "important" predictors for regression and classification -#' models. -#' -#' @param object A fitted model object of appropriate class (e.g., `"gbm"`, -#' `"lm"`, `"randomForest"`, etc.). -#' -#' @param n Integer specifying the number of predictors to return. Default is -#' `1` meaning return the single most important predictor. -#' -#' @param ... Additional optional arguments to be passed onto -#' [caret::varImp()]. -#' -#' @details -#' This function uses the generic function [caret::varImp()] to -#' calculate variable importance scores for each predictor. After that, they are -#' sorted at the names of the `n` highest scoring predictors are returned. -#' -#' @rdname topPredictors -#' @export -#' @examples -#' \dontrun{ -#' # -#' # Regression example (requires randomForest package to run) -#' # -#' -#' # Load required packages -#' library(randomForest) -#' -#' # Fit a random forest to the mtcars dataset -#' data(mtcars, package = "datasets") -#' set.seed(101) -#' mtcars.rf <- randomForest(mpg ~ ., data = mtcars, mtry = 5, importance = TRUE) -#' -#' # Top four predictors -#' top4 <- topPredictors(mtcars.rf, n = 4) -#' -#' # Construct partial dependence functions for top four predictors -#' pd <- NULL -#' for (i in top4) { -#' tmp <- partial(mtcars.rf, pred.var = i) -#' names(tmp) <- c("x", "y") -#' pd <- rbind(pd, cbind(tmp, predictor = i)) -#' } -#' -#' # Display partial dependence functions -#' tinyplot::tinyplot(y ~ x, facet = ~ predictor, data = pd, type = "l", -#' facet.args = list(free = TRUE), ylab = "mpg") -#' -#' } -topPredictors <- function(object, n = 1L, ...) { - .Deprecated( - msg = paste("pdp::topPredictors() is now deprecated and will be removed in", - "the next version. For a more general replacement, check out", - "the vip package: https://github.com/koalaverse/vip.") - ) - if (!requireNamespace("caret", quietly = TRUE)) { - stop("Package \"caret\" is needed for this function to work. Please ", - "install it.", call. = FALSE) - } - UseMethod("topPredictors") -} - - -#' @rdname topPredictors -#' @export -topPredictors.default <- function(object, n = 1L, ...) { - imp <- caret::varImp(object, ...) - if (n > nrow(imp)) { - n <- nrow(imp) - } - imp <- imp[order(imp[, "Overall"], decreasing = TRUE), , drop = FALSE] - rownames(imp)[seq_len(n)] -} - - -#' @rdname topPredictors -#' @export -topPredictors.train <- function(object, n = 1L, ...) { - # FIXME: What about filterVarImp? - imp <- caret::varImp(object, ...)$importance - if (n > nrow(imp)) { - n <- nrow(imp) - } - imp <- imp[order(imp$Overall, decreasing = TRUE), , drop = FALSE] - rownames(imp)[seq_len(n)] -} diff --git a/_pkgdown.yml b/_pkgdown.yml index f8c88cf..07333cc 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -38,6 +38,3 @@ reference: contents: - boston - pima -- title: Deprecated - contents: - - topPredictors diff --git a/man/topPredictors.Rd b/man/topPredictors.Rd deleted file mode 100644 index 02086c5..0000000 --- a/man/topPredictors.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/topPredictors.R -\name{topPredictors} -\alias{topPredictors} -\alias{topPredictors.default} -\alias{topPredictors.train} -\title{Extract Most "Important" Predictors (Experimental)} -\usage{ -topPredictors(object, n = 1L, ...) - -\method{topPredictors}{default}(object, n = 1L, ...) - -\method{topPredictors}{train}(object, n = 1L, ...) -} -\arguments{ -\item{object}{A fitted model object of appropriate class (e.g., \code{"gbm"}, -\code{"lm"}, \code{"randomForest"}, etc.).} - -\item{n}{Integer specifying the number of predictors to return. Default is -\code{1} meaning return the single most important predictor.} - -\item{...}{Additional optional arguments to be passed onto -\code{\link[caret:varImp]{caret::varImp()}}.} -} -\description{ -Extract the most "important" predictors for regression and classification -models. -} -\details{ -This function uses the generic function \code{\link[caret:varImp]{caret::varImp()}} to -calculate variable importance scores for each predictor. After that, they are -sorted at the names of the \code{n} highest scoring predictors are returned. -} -\examples{ -\dontrun{ -# -# Regression example (requires randomForest package to run) -# - -# Load required packages -library(randomForest) - -# Fit a random forest to the mtcars dataset -data(mtcars, package = "datasets") -set.seed(101) -mtcars.rf <- randomForest(mpg ~ ., data = mtcars, mtry = 5, importance = TRUE) - -# Top four predictors -top4 <- topPredictors(mtcars.rf, n = 4) - -# Construct partial dependence functions for top four predictors -pd <- NULL -for (i in top4) { - tmp <- partial(mtcars.rf, pred.var = i) - names(tmp) <- c("x", "y") - pd <- rbind(pd, cbind(tmp, predictor = i)) -} - -# Display partial dependence functions -tinyplot::tinyplot(y ~ x, facet = ~ predictor, data = pd, type = "l", - facet.args = list(free = TRUE), ylab = "mpg") - -} -}