Title: | Add the 'dann' Model and the 'sub_dann' Model to the Tidymodels Ecosystem |
---|---|
Description: | Provides model specifications, tuning parameters for models in 'dann' package. Models based on Hastie (1996) <https://web.stanford.edu/~hastie/Papers/dann_IEEE.pdf>. |
Authors: | Greg McMahan [aut, cre] |
Maintainer: | Greg McMahan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.1.99999 |
Built: | 2025-01-17 03:53:01 UTC |
Source: | https://github.com/gmcmacran/tidydann |
Softening
matrix_diagonal(range = c(0, 2), trans = NULL)
matrix_diagonal(range = c(0, 2), trans = NULL)
range |
A two-element vector holding the defaults for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the transformed units. |
trans |
A trans object from the scales package, such as scales::log10_trans() or scales::reciprocal_trans().If not provided, the default is used which matches the units used in range. If no transformation, NULL. |
Softening parameter. Usually has the least affect on performance.
An S3 class of type quant_param from the dials package.
library(tidydann) matrix_diagonal()
library(tidydann) matrix_diagonal()
Discriminant Adaptive Nearest Neighbor Classification
nearest_neighbor_adaptive( mode = "classification", neighbors = NULL, neighborhood = NULL, matrix_diagonal = NULL, weighted = NULL, sphere = NULL, num_comp = NULL )
nearest_neighbor_adaptive( mode = "classification", neighbors = NULL, neighborhood = NULL, matrix_diagonal = NULL, weighted = NULL, sphere = NULL, num_comp = NULL )
mode |
A single character string for the type of model. The only possible value for this model is "classification". |
neighbors |
The number of data points used for final classification. |
neighborhood |
The number of data points used to calculate between and within class covariance. |
matrix_diagonal |
Diagonal elements of a diagonal matrix. 1 is the identity matrix. |
weighted |
weighted argument to ncoord. See |
sphere |
One of "mcd", "mve", "classical", or "none" See |
num_comp |
Dimension of subspace used by dann. See |
Discriminant Adaptive Nearest Neighbor (dann) is a variation of k nearest neighbors where the shape of the neighborhood is data driven. The neighborhood is elongated along class boundaries and shrunk in the orthogonal direction.
This function has engines dann and sub_dann.
An S3 class of type nearest_neighbor_adaptive.
library(parsnip) library(tidydann) data("two_class_dat", package = "modeldata") model <- nearest_neighbor_adaptive(neighbors = 2) |> set_engine("dann") |> fit(formula = Class ~ A + B, data = two_class_dat) model |> predict(new_data = two_class_dat)
library(parsnip) library(tidydann) data("two_class_dat", package = "modeldata") model <- nearest_neighbor_adaptive(neighbors = 2) |> set_engine("dann") |> fit(formula = Class ~ A + B, data = two_class_dat) model |> predict(new_data = two_class_dat)
Number of data points used to calculate the shape of the neighborhood.
neighborhood(range = c(2L, dials::unknown()), trans = NULL)
neighborhood(range = c(2L, dials::unknown()), trans = NULL)
range |
A two-element vector holding the defaults for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the transformed units. |
trans |
A trans object from the scales package, such as scales::log10_trans() or scales::reciprocal_trans().If not provided, the default is used which matches the units used in range. If no transformation, NULL. |
Use get_n or finalize from dials to finalize.
If cross validation is done, use get_n_frac with argument frac set to 1/V. See README for detailed example.
An S3 class of type quant_param from the dials package.
library(dials) library(tidydann) data("taxi", package = "modeldata") neighborhood() |> finalize(taxi) neighborhood() |> get_n(taxi)
library(dials) library(tidydann) data("taxi", package = "modeldata") neighborhood() |> finalize(taxi) neighborhood() |> get_n(taxi)
Sphere argument to ncoord
sphere(values = c("mcd", "mve", "classical", "none"))
sphere(values = c("mcd", "mve", "classical", "none"))
values |
A one-element vector containing "mcd", "mve", "classical", or "none". |
An S3 class of type qual_param from the dials package.
library(tidydann) sphere()
library(tidydann) sphere()
Returns information on potential hyper-parameters that can be optimized.
## S3 method for class 'nearest_neighbor_adaptive' tunable(x, ...)
## S3 method for class 'nearest_neighbor_adaptive' tunable(x, ...)
x |
A model specification of type nearest_neighbor_adaptive specification. |
... |
Other arguments passed to methods. |
A tibble with a column for the parameter name, information on the default method for generating a corresponding parameter object, the source of the parameter (e.g. "recipe", etc.), and the component within the source.
If parameters of a model specification need to be modified, update() can be used in lieu of recreating the object from scratch.
## S3 method for class 'nearest_neighbor_adaptive' update( object, parameters = NULL, neighbors = NULL, neighborhood = NULL, matrix_diagonal = NULL, weighted = NULL, sphere = NULL, num_comp = NULL, fresh = FALSE, ... )
## S3 method for class 'nearest_neighbor_adaptive' update( object, parameters = NULL, neighbors = NULL, neighborhood = NULL, matrix_diagonal = NULL, weighted = NULL, sphere = NULL, num_comp = NULL, fresh = FALSE, ... )
object |
A model specification. |
parameters |
A 1-row tibble or named list with main parameters to update. Use either parameters or the main arguments directly when updating. If the main arguments are used, these will supersede the values in parameters. Also, using engine arguments in this object will result in an error. |
neighbors |
The number of data points used for final classification. |
neighborhood |
The number of data points used to calculate between and within class covariance. |
matrix_diagonal |
Diagonal elements of a diagonal matrix. 1 is the identity matrix. |
weighted |
weighted argument to ncoord. See |
sphere |
One of "mcd", "mve", "classical", or "none" See |
num_comp |
Dimension of subspace used by dann. See |
fresh |
A logical for whether the arguments should be modified in-place or replaced wholesale. |
... |
Not used for update(). |
Weighted argument to ncoord
weighted(values = c(FALSE, TRUE))
weighted(values = c(FALSE, TRUE))
values |
A one-element vector containing FALSE or TRUE. |
An S3 class of type qual_param from the dials package.
library(tidydann) weighted()
library(tidydann) weighted()