# rpart

0th

Percentile

##### Recursive Partitioning and Regression Trees

Fit a rpart model

Keywords
, rpart
##### Usage
rpart(formula, data, weights, subset, na.action=na.rpart, method,
model=F, x=F, y=T, parms, control=rpart.control(...), ...)
##### Arguments
formula
a formula, as in the lm function.
data
an optional data frame in which to interpret the variables named in the formula
weights
optional weights (currently ignored).
subset
optional expression saying that only a subset of the rows of the data should be used in the fit.
na.action
The default action deletes all observations for which y is missing, but keeps those in which one or more predictors are missing.
method
one of "anova", "poisson", "class" or "exp". If method is missing then the routine tries to make an intellegent guess. If y is a survival object, then method="exp"
model
keep a copy of the model frame in the result. If the input value for model is a model frame (likely from an earlier call to the rpart function), then this frame is used rather than constructing new data.
x
keep a copy of the x matrix in the result.
y
keep a copy of the dependent variable in the result.
parms
optional parameters for the splitting function. Anova splitting has no parameters. Poisson splitting has a single parameter, the coefficient of variation of the prior distribution on the rates. The default value is 1. Exponential splitting has the same p
control
options that control details of the rpart algorithm.
...
arguments to rpart.control may also be specified in the call to rpart.
##### Details

This differs from the tree function mainly in its handling of surrogate variables.

##### Value

• an object of class rpart, a superset of class tree.

##### References

Breiman, Friedman, Olshen, and Stone. (1984) Classification and Regression Trees. Wadsworth.

rpart.control, rpart.object, tree, summary.rpart, print.rpart

• rpart
##### Examples
data(kyphosis)
fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis)
fit2 <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis,
parms=list(prior=c(.65,.35), split='information'))
fit3 <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis,
control=rpart.control(cp=.05))
par(mfrow=c(1,2))
plot(fit)
text(fit,use.n=T)
plot(fit2)
text(fit2,use.n=T)
Documentation reproduced from package rpart, version 1.0-6, License: Unlimited distribution for noncommercial use

### Community examples

sayandutta13@gmail.com at Feb 28, 2017 rpart v4.1-10

# Set random seed. Don't remove this line. set.seed(1) # Take a look at the iris dataset str(iris) summary(iris) # A decision tree model has been built for you tree <- rpart(Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, data = iris, method = "class") # A dataframe containing unseen observations unseen <- data.frame(Sepal.Length = c(5.3, 7.2), Sepal.Width = c(2.9, 3.9), Petal.Length = c(1.7, 5.4), Petal.Width = c(0.8, 2.3)) # Predict the label of the unseen observations. Print out the result. predict(tree, unseen, type = "class")
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.2961946725845337, "perplexity": 8058.712126573429}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-16/segments/1585370497301.29/warc/CC-MAIN-20200330181842-20200330211842-00303.warc.gz"}