Title: | Yet Another General Regression Neural Network |
---|---|
Description: | Another implementation of general regression neural network in R based on Specht (1991) <DOI:10.1109/72.97934>. It is applicable to the functional approximation or the classification. |
Authors: | WenSui Liu |
Maintainer: | WenSui Liu <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.1 |
Built: | 2025-03-10 05:04:26 UTC |
Source: | https://github.com/cran/yager |
The function folds
generates a list of index for the n-fold cross-validation
folds(idx, n, seed = 1)
folds(idx, n, seed = 1)
idx |
A vector of index list |
n |
The number of n folds |
seed |
The seed value to generate random n-fold index |
A list of n-fold index
folds(seq(10), n = 3, seed = 2020)
folds(seq(10), n = 3, seed = 2020)
The function gen_latin
generates a vector of random numbers by latin hypercube sampling
gen_latin(min = 0, max = 1, n, seed = 1)
gen_latin(min = 0, max = 1, n, seed = 1)
min |
The minimum value of random numbers |
max |
The maxinum value of random numbers |
n |
The number of random numbers to gernate |
seed |
The seed value of random number generation |
A vector of random numbers bounded by the min and max
gen_latin(0, 1, 10, 2020)
gen_latin(0, 1, 10, 2020)
The function gen_sobol
generates a vector of scrambled sobol sequence
gen_sobol(min = 0, max = 1, n, seed = 1)
gen_sobol(min = 0, max = 1, n, seed = 1)
min |
The minimum value of random numbers |
max |
The maxinum value of random numbers |
n |
The number of random numbers to gernate |
seed |
The seed value of random number generation |
A vector of sobol sequence bounded by the min and max
gen_sobol(0, 1, 10, 2020)
gen_sobol(0, 1, 10, 2020)
The function gen_unifm
generates a vector of uniform random numbers
gen_unifm(min = 0, max = 1, n, seed = 1)
gen_unifm(min = 0, max = 1, n, seed = 1)
min |
The minimum value of random numbers |
max |
The maxinum value of random numbers |
n |
The number of random numbers to gernate |
seed |
The seed value of random number generation |
A vector of uniform random numbers bounded by the min and max
gen_unifm(0, 1, 10, 2020)
gen_unifm(0, 1, 10, 2020)
The function grnn.fit
creates a general regression neural network (GRNN)
grnn.fit(x, y, sigma = 1, w = rep(1, length(y)))
grnn.fit(x, y, sigma = 1, w = rep(1, length(y)))
x |
The matrix of predictors |
y |
The vector of response variable |
sigma |
The scalar of smoothing parameter |
w |
The vector of weights with default = 1 for each record |
A general regression neural network object
Donald Specht. (1991). A General Regression Neural Network.
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y)
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y)
The function grnn.imp
derives the importance rank of all predictors used in the GRNN
It essentially is a wrapper around the function grnn.x_imp
.
grnn.imp(net, class = FALSE)
grnn.imp(net, class = FALSE)
net |
The GRNN object generated by grnn.fit() |
class |
TRUE or FALSE, whether it is for the classification or not |
A dataframe with important values of all predictors in the GRNN
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:3]) gnet <- grnn.fit(x = X, y = Y) ## Not run: grnn.imp(net = gnet, class = TRUE) ## End(Not run)
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:3]) gnet <- grnn.fit(x = X, y = Y) ## Not run: grnn.imp(net = gnet, class = TRUE) ## End(Not run)
The function grnn.margin
derives the marginal effect of a predictor used in a GRNN
by assuming mean values for the rest predictors
grnn.margin(net, i, plot = TRUE)
grnn.margin(net, i, plot = TRUE)
net |
The GRNN object generated by grnn.fit() |
i |
The ith predictor in the GRNN |
plot |
TRUE or FALSE to plot the marginal effect |
A plot of the marginal effect or a dataframe of the marginal effect
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.margin(gnet, 1, plot = FALSE)
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.margin(gnet, 1, plot = FALSE)
The function grnn.optmiz_auc
optimize the optimal value of GRNN smoothing parameter by cross-validation.
It is applicable to the classification.
grnn.optmiz_auc(net, lower = 0, upper, nfolds = 4, seed = 1, method = 1)
grnn.optmiz_auc(net, lower = 0, upper, nfolds = 4, seed = 1, method = 1)
net |
A GRNN object generated by grnn.fit() |
lower |
A scalar for the lower bound of the smoothing parameter |
upper |
A scalar for the upper bound of the smoothing parameter |
nfolds |
A scalar for the number of n-fold, 4 by default |
seed |
The seed value for the n-fold cross-validation, 1 by default |
method |
A scalar referring to the optimization method, 1 for Golden section searc and 2 for Brent’s method |
The best outcome
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) ## Not run: grnn.optmiz_auc(net = gnet, lower = 3, upper = 7, nfolds = 2) ## End(Not run)
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) ## Not run: grnn.optmiz_auc(net = gnet, lower = 3, upper = 7, nfolds = 2) ## End(Not run)
The function grnn.parpred
calculates a vector of GRNN predicted values based on an input matrix
grnn.parpred(net, x)
grnn.parpred(net, x)
net |
The GRNN object generated by grnn.fit() |
x |
The matrix of input predictors |
A vector of predicted values
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.parpred(gnet, X[seq(5), ])
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.parpred(gnet, X[seq(5), ])
The function grnn.partial
derives the partial effect of a predictor used in a GRNN
by average-out values of the rest predictors.
grnn.partial(net, i, plot = TRUE)
grnn.partial(net, i, plot = TRUE)
net |
The GRNN object generated by grnn.fit() |
i |
The ith predictor in the GRNN |
plot |
TRUE or FALSE to plot the partial effect |
A plot of the partial effect or a dataframe of the partial effect
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) ## Not run: grnn.partial(gnet, 1, plot = FALSE) ## End(Not run)
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) ## Not run: grnn.partial(gnet, 1, plot = FALSE) ## End(Not run)
The function grnn.pfi
derives the PFI rank of all predictors used in the GRNN
It essentially is a wrapper around the function grnn.x_pfi
.
grnn.pfi(net, class = FALSE, ntry = 1000, seed = 1)
grnn.pfi(net, class = FALSE, ntry = 1000, seed = 1)
net |
The GRNN object generated by grnn.fit() |
class |
TRUE or FALSE, whether it is for the classification or not |
ntry |
The number of random permutations to try, 1e3 times by default |
seed |
The seed value for the random permutation |
A dataframe with PFI values of all predictors in the GRNN
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:3]) gnet <- grnn.fit(x = X, y = Y) ## Not run: grnn.pfi(net = gnet, class = TRUE) ## End(Not run)
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:3]) gnet <- grnn.fit(x = X, y = Y) ## Not run: grnn.pfi(net = gnet, class = TRUE) ## End(Not run)
The function grnn.predict
calculates a vector of GRNN predicted values based on an input matrix
grnn.predict(net, x)
grnn.predict(net, x)
net |
The GRNN object generated by grnn.fit() |
x |
The matrix of input predictors |
A vector of predicted values
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.predict(gnet, X[seq(5), ])
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.predict(gnet, X[seq(5), ])
The function grnn.predone
calculates a predicted value of GRNN based on an input vector
The function grnn.predone
calculates a predicted value of GRNN based on an input vector
grnn.predone(net, x, type = 1) grnn.predone(net, x, type = 1)
grnn.predone(net, x, type = 1) grnn.predone(net, x, type = 1)
net |
The GRNN object generated by grnn.fit() |
x |
The vector of input predictors |
type |
A scalar, 1 for euclidean distance and 2 for manhattan distance |
A scalar of the predicted value
A scalar of the predicted value
Donald Specht. (1991). A General Regression Neural Network.
Donald Specht. (1991). A General Regression Neural Network.
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) for (i in seq(5)) print(grnn.predone(gnet, X[i, ])) data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) for (i in seq(5)) print(grnn.predone(gnet, X[i, ]))
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) for (i in seq(5)) print(grnn.predone(gnet, X[i, ])) data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) for (i in seq(5)) print(grnn.predone(gnet, X[i, ]))
The function grnn.search_auc
searches for the optimal value of GRNN smoothing parameter by cross-validation.
It is applicable to the classification.
grnn.search_auc(net, sigmas, nfolds = 4, seed = 1)
grnn.search_auc(net, sigmas, nfolds = 4, seed = 1)
net |
A GRNN object generated by grnn.fit() |
sigmas |
A numeric vector to search for the best smoothing parameter |
nfolds |
A scalar for the number of n-fold, 4 by default |
seed |
The seed value for the n-fold cross-validation, 1 by default |
The list of all searching outcomes and the best outcome
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.search_auc(net = gnet, sigmas = c(3, 5, 7), nfolds = 2)
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.search_auc(net = gnet, sigmas = c(3, 5, 7), nfolds = 2)
The function grnn.search_rsq
searches for the optimal value of GRNN smoothing parameter by cross-validation.
It is applicable to the functional approximation
grnn.search_rsq(net, sigmas, nfolds = 4, seed = 1)
grnn.search_rsq(net, sigmas, nfolds = 4, seed = 1)
net |
A GRNN object generated by grnn.fit() |
sigmas |
A numeric vector to search for the best smoothing parameter |
nfolds |
A scalar for the number of n-fold, 4 by default |
seed |
The seed value for the n-fold cross-validation, 1 by default |
The list of all searching outcomes and the best outcome
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.search_rsq(net = gnet, sigmas = seq(3), nfolds = 2)
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.search_rsq(net = gnet, sigmas = seq(3), nfolds = 2)
The function grnn.x_imp
derives the importance of a predictor used in the GRNN
by using the loss of predictability after eliminating the impact of the predictor in interest.
grnn.x_imp(net, i, class = FALSE)
grnn.x_imp(net, i, class = FALSE)
net |
The GRNN object generated by grnn.fit() |
i |
The ith predictor in the GRNN |
class |
TRUE or FALSE, whether it is for the classification or not |
A vector with the variable name and two values of importance measurements, namely "imp1" and "imp2". The "imp1" measures the loss of predictability after replacing all values of the predictor with its mean. The "imp2" measures the loss of predictability after dropping the predictor from the GRNN.
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.x_imp(net = gnet, 1)
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.x_imp(net = gnet, 1)
The function grnn.x_pfi
derives the permutation feature importance (PFI) of a predictor used in the GRNN
grnn.x_pfi(net, i, class = FALSE, ntry = 1000, seed = 1)
grnn.x_pfi(net, i, class = FALSE, ntry = 1000, seed = 1)
net |
The GRNN object generated by grnn.fit() |
i |
The ith predictor in the GRNN |
class |
TRUE or FALSE, whether it is for the classification or not |
ntry |
The number of random permutations to try, 1e3 times by default |
seed |
The seed value for the random permutation |
A vector with the variable name and the PFI value.
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.x_pfi(net = gnet, 1)
data(iris, package = "datasets") Y <- ifelse(iris[, 5] == "setosa", 1, 0) X <- scale(iris[, 1:4]) gnet <- grnn.fit(x = X, y = Y) grnn.x_pfi(net = gnet, 1)