Clustering if ICE and d-ICE curves by kmeans. All curves are centered to have mean 0 and then kmeans is applied to the curves with the specified number of clusters.
Usage
clusterICE(
ice_obj,
nClusters,
plot = TRUE,
plot_margin = 0.05,
colorvec,
plot_pdp = FALSE,
x_quantile = FALSE,
avg_lwd = 3,
centered = FALSE,
plot_legend = FALSE,
main = NULL,
num_cores = 1,
...
)Arguments
- ice_obj
Object of class
iceordiceto cluster.- nClusters
Number of clusters to find.
- plot
If
TRUE, plots the clusters.- plot_margin
Extra margin to pass to
ylimas a fraction of the range of cluster centers.- colorvec
Optional vector of colors to use for each cluster.
- plot_pdp
If
TRUE, the PDP (iceobject) or d-PDP (diceobject) is plotted with a dotted black line and highlighted in yellow.- x_quantile
If
TRUE, the plot is drawn with the x-axis taken to bequantile(gridpts). IfFALSE, the predictor's original scale is used.- avg_lwd
Average line width to use when plotting the cluster means. Line width is proportional to the cluster's size.
- centered
If
TRUE, all cluster means are shifted to be to be 0 at the minimum value of the predictor. IfFALSE, the original cluster means are used.- plot_legend
If
TRUEa legend mapping line colors to the proportion of the data in each cluster is added to the plot.- main
Optional title for the plot.
- num_cores
Integer number of cores to use for parallel operations. Default is 1.
- ...
Additional arguments for plotting.
Value
A list with the following elements:
- cl
The output of the
kmeanscall (a list of classkmeans).- plot
The ggplot object used for plotting (if
plot = TRUE).
Examples
if (FALSE) { # \dontrun{
require(ICEbox)
require(randomForest)
require(MASS) #has Boston Housing data, Pima
data(Boston) #Boston Housing data
X = Boston
y = X$medv
X$medv = NULL
## build a RF:
bh_rf = randomForest(X, y)
## Create an 'ice' object for the predictor "age":
bh.ice = ice(object = bh_rf, X = X, y = y, predictor = "age",
frac_to_build = .1)
## cluster the curves into 2 groups.
clusterICE(bh.ice, nClusters = 2, plot_legend = TRUE)
## cluster the curves into 3 groups, start all at 0.
clusterICE(bh.ice, nClusters = 3, plot_legend = TRUE, center = TRUE)
} # }