Title: | Projection Pursuit Classification Forest |
---|---|
Description: | Implements projection pursuit forest algorithm for supervised classification. |
Authors: | Natalia da Silva, Eun-Kyung Lee, Di Cook |
Maintainer: | Natalia da Silva <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.3 |
Built: | 2024-11-20 06:44:09 UTC |
Source: | CRAN |
For each bootstrap sample grow a projection pursuit tree (PPtree object).
baggtree( data, class, m = 500, PPmethod = "LDA", lambda = 0.1, size.p = 1, parallel = FALSE, cores = 2 )
baggtree( data, class, m = 500, PPmethod = "LDA", lambda = 0.1, size.p = 1, parallel = FALSE, cores = 2 )
data |
Data frame with the complete data set. |
class |
A character with the name of the class variable. |
m |
is the number of bootstrap replicates, this corresponds with the number of trees to grow. To ensure that each observation is predicted a few times we have to select this number no too small. |
PPmethod |
is the projection pursuit index to be optimized, options LDA or PDA, by default it is LDA. |
lambda |
a parameter for PDA index |
size.p |
proportion of random sample variables in each split. |
parallel |
logical condition, if it is TRUE then parallelize the function |
cores |
number of cores used in the parallelization |
data frame with trees_pp output for all the bootstraps samples.
#crab data set crab.trees <- baggtree(data = crab, class = 'Type', m = 200, PPmethod = 'LDA', lambda = .1, size.p = 0.5 , parallel = TRUE, cores = 2) str(crab.trees, max.level = 1)
#crab data set crab.trees <- baggtree(data = crab, class = 'Type', m = 200, PPmethod = 'LDA', lambda = .1, size.p = 0.5 , parallel = TRUE, cores = 2) str(crab.trees, max.level = 1)
Measurements on rock crabs of the genus Leptograpsus. The data set contains 200 observations from two species of crab (blue and orange), there are 50 specimens of each sex of each species, collected on site at Fremantle, Western Australia.
Type is the class variable and has 4 classes with the combinations of specie and sex (BlueMale, BlueFemale, OrangeMale and OrangeFemale).
FLthe size of the frontal lobe length, in mm
RWrear width, in mm
CLlength of midline of the carapace, in mm
CWmaximum width of carapace, in mm
BDdepth of the body; for females, measured after displacement of the abdomen, in mm
data(crab)
data(crab)
A data frame with 200 rows and 6 variables
Campbell, N. A. & Mahon, R. J. (1974), A Multivariate Study of Variation in Two Species of Rock Crab of genus Leptograpsus, Australian Journal of Zoology 22(3), 417 - 425.
There are 159 fishes of 7 species are caught and measured. Altogether there are 7 variables. All the fishes are caught from the same lake(Laengelmavesi) near Tampere in Finland.
Type has 7 fish classes, with 35 cases of Bream, 11 cases of Parkki, 56 cases of Perch 17 cases of Pike, 20 cases of Roach, 14 cases of Smelt and 6 cases of Whitewish.
weight Weight of the fish (in grams)
length1 Length from the nose to the beginning of the tail (in cm)
length2 Length from the nose to the notch of the tail (in cm)
length3 Length from the nose to the end of the tail (in cm)
height Maximal height as % of Length3
width Maximal width as % of Length3
data(fishcatch)
data(fishcatch)
A data frame with 159 rows and 7 variables
urlhttp://www.amstat.org/publications/jse/jse_data_archive.htm
Contains measurements 214 observations of 6 types of glass; defined in terms of their oxide content.
Type has 6 types of glasses
X1 refractive index
X2 Sodium (unit measurement: weight percent in corresponding oxide).
X3 Magnesium
X4 Aluminum
X5 Silicon
X6 Potassium
X7 Calcium
X8 Barium
X9 Iron
data(glass)
data(glass)
A data frame with 214 rows and 10 variables
contains 2310 observations of instances from 7 outdoor images
Type has 7 types of outdoor images, brickface, cement, foliage, grass, path, sky, and window.
X1 the column of the center pixel of the region
X2 the row of the center pixel of the region.
X3 the number of pixels in a region = 9.
X4 the results of a line extraction algorithm that counts how many lines of length 5 (any orientation) with low contrast, less than or equal to 5, go through the region.
X5 measure the contrast of horizontally adjacent pixels in the region. There are 6, the mean and standard deviation are given. This attribute is used as a vertical edge detector.
X6 X5 sd
X7 measures the contrast of vertically adjacent pixels. Used for horizontal line detection.
X8 sd X7
X9 the average over the region of (R + G + B)/3
X10 the average over the region of the R value.
X11 the average over the region of the B value.
X12 the average over the region of the G value.
X13 measure the excess red: (2R - (G + B))
X14 measure the excess blue: (2B - (G + R))
X15 measure the excess green: (2G - (R + B))
X16 3-d nonlinear transformation of RGB. (Algorithm can be found in Foley and VanDam, Fundamentals of Interactive Computer Graphics)
X17 mean of X16
X18 hue mean
data(image)
data(image)
A data frame contains 2310 observations and 19 variables
This dataset comes from a study of gene expression in two types of acute leukemias, acute lymphoblastic leukemia (ALL) and acute myeloid leukemia (AML). Gene expression levels were measured using Affymetrix high density oligonucleotide arrays containing 6817 human genes. A data set containing 72 observations from 3 leukemia types classes.
Type has 3 classes with 38 cases of B-cell ALL, 25 cases of AML and 9 cases of T-cell ALL.
Gene1 to Gen 40 gene expression levels
data(leukemia)
data(leukemia)
A data frame with 72 rows and 41 variables
Dudoit, S., Fridlyand, J. and Speed, T. P. (2002). Comparison of Discrimination Methods for the Classification of Tumors Using Gene Expression Data. Journal of the American statistical Association 97 77-87.
Gene expression in the three most prevalent adult lymphoid malignancies: B-cell chronic lymphocytic leukemia (B-CLL), follicular lymphoma (FL), and diffuse large B-cell lym- phoma (DLBCL). Gene expression levels were measured using a specialized cDNA microarray, the Lymphochip, containing genes that are preferentially expressed in lymphoid cells or that are of known immunologic or oncologic importance. This data set contain 80 observations from 3 lymphoma types.
Type Class variable has 3 classes with 29 cases of B-cell ALL (B-CLL), 42 cases of diffuse large B-cell lymphoma (DLBCL) and 9 cases of follicular lymphoma (FL).
Gene1 to Gen 50gene expression
data(lymphoma)
data(lymphoma)
A data frame with 80 rows and 51 variables
Dudoit, S., Fridlyand, J. and Speed, T. P. (2002). Comparison of Discrimination Methods for the Classification of Tumors Using Gene Ex- pression Data. Journal of the American statistical Association 97 77-87.
cDNA microarrays were used to examine the variation in gene expression among the 60 cell lines. The cell lines are derived from tumors with different sites of origin. This data set contain 61 observations and 30 feature variables from 8 different tissue types.
Type has 8 different tissue types, 9 cases of breast, 5 cases of central nervous system (CNS), 7 cases pf colon, 8 cases of leukemia, 8 cases of melanoma, 9 cases of non-small-cell lung carcinoma (NSCLC), 6 cases of ovarian and 9 cases of renal.
Gene1 to Gen 30 gene expression information
data(NCI60)
data(NCI60)
A data frame with 61 rows and 31 variables
Dudoit, S., Fridlyand, J. and Speed, T. P. (2002). Comparison of Discrimination Methods for the Classification of Tumors Using Gene Expression Data. Journal of the American statistical Association 97 77-87.
Data structure with the projected and boundary by node and class.
node_data(ppf, tr, Rule = 1)
node_data(ppf, tr, Rule = 1)
ppf |
is a PPforest object |
tr |
numerical value to identify a tree |
Rule |
split rule 1:mean of two group means, 2:weighted mean, 3: mean of max(left group) and min(right group), 4: weighted mean of max(left group) and min(right group) |
Data frame with projected data for each class and node id and the boundaries
#crab data set with all the observations used as training pprf.crab <- PPforest(data = crab, std =TRUE, class = 'Type', size.tr = 1, m = 200, size.p = .5, PPmethod = 'LDA') node_data(ppf = pprf.crab, tr = 1)
#crab data set with all the observations used as training pprf.crab <- PPforest(data = crab, std =TRUE, class = 'Type', size.tr = 1, m = 200, size.p = .5, PPmethod = 'LDA') node_data(ppf = pprf.crab, tr = 1)
contains 572 observations and 10 variables
RegionThree super-classes of Italy: North, South and the island of Sardinia
area Nine collection areas: three from North, four from South and 2 from Sardinia
palmitic fatty acids percent x 100
palmitoleic fatty acids percent x 100
stearicfatty acids percent x 100
oleicfatty acids percent x 100
linoleicfatty acids percent x 100
linolenicfatty acids percent x 100
arachidic fatty acids percent x 100
eicosenoic fatty acids percent x 100
data(olive)
data(olive)
A data frame contains 573 observations and 10 variables
A data set containing 195 observations from 2 parkinson types.
Type Class variable has 2 classes, there are 48 cases of healthy people and 147 cases with Parkinson. The feature variables are biomedical voice measures.
X1 Average vocal fundamental frequency
X2 Maximum vocal fundamental frequency
X3 Minimum vocal fundamental frequency
X4 MDVP:Jitter(%) measures of variation in fundamental frequency
X5 MDVP:Jitter(Abs) measures of variation in fundamental frequency
X6 MDVP:RAP measures of variation in fundamental frequency
X7 MDVP:PPQ measures of variation in fundamental frequency
X8 Jitter:DDP measures of variation in fundamental frequency
X9 MDVP:Shimmer measures of variation in amplitude
X10 MDVP:Shimmer(dB) measures of variation in amplitude
X11 Shimmer:APQ3 measures of variation in amplitude
X12 Shimmer:APQ5 measures of variation in amplitude
X13 MDVP:APQ measures of variation in amplitude
X14 Shimmer:DDA measures of variation in amplitude
X15 NHR measures of ratio of noise to tonal components in the voice
X16 HNR measures of ratio of noise to tonal components in the voice
X17 RPDE nonlinear dynamical complexity measures
X18 D2 nonlinear dynamical complexity measures
X19 DFA - Signal fractal scaling exponent
X20 spread1 Nonlinear measures of fundamental frequency variation
X21 spread2 Nonlinear measures of fundamental frequency variation
X22 PPE Nonlinear measures of fundamental frequency variation
data(parkinson)
data(parkinson)
A data frame with 195 rows and 23 variables
urlhttps://archive.ics.uci.edu/ml/datasets/Parkinsons
Obtain the permuted importance variable measure
permute_importance(ppf)
permute_importance(ppf)
ppf |
is a PPforest object |
A data frame with permuted importance measures, imp is the permuted importance measure defined in Brieman paper, imp2 is the permuted importance measure defined in randomForest package, the standard deviation (sd.im and sd.imp2) for each measure is computed and the also the standardized mesure.
pprf.crab <- PPforest(data = crab, class = 'Type', std = TRUE, size.tr = 1, m = 100, size.p = .4, PPmethod = 'LDA', parallel = TRUE, core = 2) permute_importance(ppf = pprf.crab)
pprf.crab <- PPforest(data = crab, class = 'Type', std = TRUE, size.tr = 1, m = 100, size.p = .4, PPmethod = 'LDA', parallel = TRUE, core = 2) permute_importance(ppf = pprf.crab)
Predict class for the test set and calculate prediction error after finding the PPtree structure, .
PPclassify2( Tree.result, test.data = NULL, Rule = 1, true.class = NULL)
PPclassify2( Tree.result, test.data = NULL, Rule = 1, true.class = NULL)
Tree.result |
the result of PP.Tree |
test.data |
the test dataset |
Rule |
split rule 1:mean of two group means, 2:weighted mean, 3: mean of max(left group) and min(right group), 4: weighted mean of max(left group) and min(right group) |
true.class |
true class of test dataset if available |
predict.class predicted class
predict.error prediction error
Lee, YD, Cook, D., Park JW, and Lee, EK(2013) PPtree: Projection pursuit classification tree, Electronic Journal of Statistics, 7:1369-1386.
#crab data set Tree.crab <- PPtree_split('Type~.', data = crab, PPmethod = 'LDA', size.p = 0.5) Tree.crab PPclassify2(Tree.crab)
#crab data set Tree.crab <- PPtree_split('Type~.', data = crab, PPmethod = 'LDA', size.p = 0.5) Tree.crab PPclassify2(Tree.crab)
Global importance measure for a PPforest object as the average IMP PPtree measure over all the trees in the forest
ppf_avg_imp(ppf, class)
ppf_avg_imp(ppf, class)
ppf |
is a PPforest object |
class |
A character with the name of the class variable. |
Data frame with the global importance measure
#crab data set with all the observations used as training pprf.crab <- PPforest(data = crab, std =TRUE, class = 'Type', size.tr = 1, m = 100, size.p = .5, PPmethod = 'LDA') ppf_avg_imp(pprf.crab, 'Type')
#crab data set with all the observations used as training pprf.crab <- PPforest(data = crab, std =TRUE, class = 'Type', size.tr = 1, m = 100, size.p = .5, PPmethod = 'LDA') ppf_avg_imp(pprf.crab, 'Type')
Global importance measure for a PPforest object
ppf_global_imp(data, class, ppf)
ppf_global_imp(data, class, ppf)
data |
Data frame with the complete data set. |
class |
A character with the name of the class variable. |
ppf |
is a PPforest object |
Data frame with the global importance measure
#crab data set with all the observations used as training pprf.crab <- PPforest(data = crab, std = TRUE, class = 'Type', size.tr = 1, m = 200, size.p = .5, PPmethod = 'LDA', parallel = TRUE, cores = 2) ppf_global_imp(data = crab, class = 'Type', pprf.crab)
#crab data set with all the observations used as training pprf.crab <- PPforest(data = crab, std = TRUE, class = 'Type', size.tr = 1, m = 200, size.p = .5, PPmethod = 'LDA', parallel = TRUE, cores = 2) ppf_global_imp(data = crab, class = 'Type', pprf.crab)
PPforest
implements a random forest using projection pursuit trees algorithm (based on PPtreeViz package).
PPforest(data, class, std = TRUE, size.tr, m, PPmethod, size.p, lambda = .1, parallel = FALSE, cores = 2, rule = 1)
PPforest(data, class, std = TRUE, size.tr, m, PPmethod, size.p, lambda = .1, parallel = FALSE, cores = 2, rule = 1)
data |
Data frame with the complete data set. |
class |
A character with the name of the class variable. |
std |
if TRUE standardize the data set, needed to compute global importance measure. |
size.tr |
is the size proportion of the training if we want to split the data in training and test. |
m |
is the number of bootstrap replicates, this corresponds with the number of trees to grow. To ensure that each observation is predicted a few times we have to select this number no too small. |
PPmethod |
is the projection pursuit index to optimize in each classification tree. The options are |
size.p |
proportion of variables randomly sampled in each split. |
lambda |
penalty parameter in PDA index and is between 0 to 1 . If |
parallel |
logical condition, if it is TRUE then parallelize the function |
cores |
number of cores used in the parallelization |
rule |
split rule 1: mean of two group means 2: weighted mean of two group means - weight with group size 3: weighted mean of two group means - weight with group sd 4: weighted mean of two group means - weight with group se 5: mean of two group medians 6: weighted mean of two group medians - weight with group size 7: weighted mean of two group median - weight with group IQR 8: weighted mean of two group median - weight with group IQR and size |
An object of class PPforest
with components.
prediction.training |
predicted values for training data set. |
training.error |
error of the training data set. |
prediction.test |
predicted values for the test data set if |
error.test |
error of the test data set if |
oob.error.forest |
out of bag error in the forest. |
oob.error.tree |
out of bag error for each tree in the forest. |
boot.samp |
information of bootrap samples. |
output.trees |
output from a |
proximity |
Proximity matrix, if two cases are classified in the same terminal node then the proximity matrix is increased by one in |
votes |
a matrix with one row for each input data point and one column for each class, giving the fraction of (OOB) votes from the |
n.tree |
number of trees grown in |
n.var |
number of predictor variables selected to use for spliting at each node. |
type |
classification. |
confusion |
confusion matrix of the prediction (based on OOB data). |
call |
the original call to |
train |
is the training data based on |
test |
is the test data based on |
Natalia da Silva, Dianne Cook & Eun-Kyung Lee (2021) A Projection Pursuit Forest Algorithm for Supervised Classification, Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2020.1870480
#crab example with all the observations used as training pprf.crab <- PPforest(data = crab, class = 'Type', std = FALSE, size.tr = 1, m = 200, size.p = .5, PPmethod = 'LDA' , parallel = TRUE, cores = 2, rule=1) pprf.crab
#crab example with all the observations used as training pprf.crab <- PPforest(data = crab, class = 'Type', std = FALSE, size.tr = 1, m = 200, size.p = .5, PPmethod = 'LDA' , parallel = TRUE, cores = 2, rule=1) pprf.crab
Find tree structure using various projection pursuit indices of classification in each split.
PPtree_split(form, data, PPmethod='LDA', size.p=1, lambda = 0.1,...)
PPtree_split(form, data, PPmethod='LDA', size.p=1, lambda = 0.1,...)
form |
A character with the name of the class variable. |
data |
Data frame with the complete data set. |
PPmethod |
index to use for projection pursuit: 'LDA', 'PDA' |
size.p |
proportion of variables randomly sampled in each split, default is 1, returns a PPtree. |
lambda |
penalty parameter in PDA index and is between 0 to 1 . If |
... |
arguments to be passed to methods |
An object of class PPtreeclass
with components
Tree.Struct |
Tree structure of projection pursuit classification tree |
projbest.node |
1-dim optimal projections of each split node |
splitCutoff.node |
cutoff values of each split node |
origclass |
original class |
origdata |
original data |
Lee, YD, Cook, D., Park JW, and Lee, EK (2013) PPtree: Projection pursuit classification tree, Electronic Journal of Statistics, 7:1369-1386.
#crab data set Tree.crab <- PPtree_split('Type~.', data = crab, PPmethod = 'LDA', size.p = 0.5) Tree.crab
#crab data set Tree.crab <- PPtree_split('Type~.', data = crab, PPmethod = 'LDA', size.p = 0.5) Tree.crab
Print PPforest object
## S3 method for class 'PPforest' print(x, ...)
## S3 method for class 'PPforest' print(x, ...)
x |
is a PPforest class object |
... |
additional parameter |
printed results for PPforest object
Data structure with the projected and boundary by node and class.
ternary_str(ppf, id, sp, dx, dy)
ternary_str(ppf, id, sp, dx, dy)
ppf |
is a PPforest object |
id |
is a vector with the selected projection directions |
sp |
is the simplex dimensions, if k is the number of classes sp = k - 1 |
dx |
first direction included in id |
dy |
second direction included in id |
Data frame needed to visualize a ternary plot
#crab data set with all the observations used as training pprf.crab <- PPforest(data = crab, std =TRUE, class = "Type", size.tr = 1, m = 100, size.p = .5, PPmethod = 'LDA') require(dplyr) pl_ter <- function(dat, dx, dy ){ p1 <- dat[[1]] %>% dplyr::filter(pair %in% paste(dx, dy, sep = "-") ) %>% dplyr::select(Class, x, y) %>% ggplot2::ggplot(ggplot2::aes(x, y, color = Class)) + ggplot2::geom_segment(data = dat[[2]], ggplot2::aes(x = x1, xend = x2, y = y1, yend = y2), color = "black" ) + ggplot2::geom_point(size = I(3), alpha = .5) + ggplot2::labs(y = " ", x = " ") + ggplot2::theme(legend.position = "none", aspect.ratio = 1) + ggplot2::scale_colour_brewer(type = "qual", palette = "Dark2") + ggplot2::labs(x = paste0("T", dx, " "), y = paste0("T", dy, " ")) + ggplot2::theme(aspect.ratio = 1) p1 } #ternary plot in tree different selected dierections pl_ter(ternary_str(pprf.crab, id = c(1, 2, 3), sp = 3, dx = 1, dy = 2), 1, 2 )
#crab data set with all the observations used as training pprf.crab <- PPforest(data = crab, std =TRUE, class = "Type", size.tr = 1, m = 100, size.p = .5, PPmethod = 'LDA') require(dplyr) pl_ter <- function(dat, dx, dy ){ p1 <- dat[[1]] %>% dplyr::filter(pair %in% paste(dx, dy, sep = "-") ) %>% dplyr::select(Class, x, y) %>% ggplot2::ggplot(ggplot2::aes(x, y, color = Class)) + ggplot2::geom_segment(data = dat[[2]], ggplot2::aes(x = x1, xend = x2, y = y1, yend = y2), color = "black" ) + ggplot2::geom_point(size = I(3), alpha = .5) + ggplot2::labs(y = " ", x = " ") + ggplot2::theme(legend.position = "none", aspect.ratio = 1) + ggplot2::scale_colour_brewer(type = "qual", palette = "Dark2") + ggplot2::labs(x = paste0("T", dx, " "), y = paste0("T", dy, " ")) + ggplot2::theme(aspect.ratio = 1) p1 } #ternary plot in tree different selected dierections pl_ter(ternary_str(pprf.crab, id = c(1, 2, 3), sp = 3, dx = 1, dy = 2), 1, 2 )
Obtain predicted class for new data from baggtree function or PPforest
trees_pred(object, xnew, parallel = FALSE, cores = 2, rule = 1)
trees_pred(object, xnew, parallel = FALSE, cores = 2, rule = 1)
object |
Projection pursuit classification forest structure from PPforest or baggtree |
xnew |
data frame with explicative variables used to get new predicted values. |
parallel |
logical condition, if it is TRUE then parallelize the function |
cores |
number of cores used in the parallelization |
rule |
split rule 1: mean of two group means 2: weighted mean of two group means - weight with group size 3: weighted mean of two group means - weight with group sd 4: weighted mean of two group means - weight with group se 5: mean of two group medians 6: weighted mean of two group medians - weight with group size 7: weighted mean of two group median - weight with group IQR 8: weighted mean of two group median - weight with group IQR and size |
predicted values from PPforest or baggtree
## Not run: crab.trees <- baggtree(data = crab, class = 'Type', m = 200, PPmethod = 'LDA', lambda = .1, size.p = 0.4 ) pr <- trees_pred( crab.trees,xnew = crab[, -1], parallel= FALSE, cores = 2) pprf.crab <- PPforest(data = crab, class = 'Type', std = FALSE, size.tr = 2/3, m = 100, size.p = .4, PPmethod = 'LDA', parallel = TRUE ) trees_pred(pprf.crab, xnew = pprf.crab$test ,parallel = TRUE) ## End(Not run)
## Not run: crab.trees <- baggtree(data = crab, class = 'Type', m = 200, PPmethod = 'LDA', lambda = .1, size.p = 0.4 ) pr <- trees_pred( crab.trees,xnew = crab[, -1], parallel= FALSE, cores = 2) pprf.crab <- PPforest(data = crab, class = 'Type', std = FALSE, size.tr = 2/3, m = 100, size.p = .4, PPmethod = 'LDA', parallel = TRUE ) trees_pred(pprf.crab, xnew = pprf.crab$test ,parallel = TRUE) ## End(Not run)
A data set containing 178 observations from 3 wine grown cultivares in Italy.
data(wine)
data(wine)
A data frame with 178 rows and 14 variables
Type Class variable has 3 classes that are 3 different wine grown cultivares in Italy.
X1 to X13Check vbles