predict_membership | R Documentation |
Function to predict the membership matrix of a new set of observations
predict_membership(
object,
new_data,
nblistw = NULL,
window = NULL,
standardize = TRUE,
...
)
object |
A FCMres object, typically obtained from functions CMeans, GCMeans, SFCMeans, SGFCMeans. Can also be a simple membership matrix. |
new_data |
A DataFrame with the new observations or a list of rasters if object$isRaster is TRUE |
nblistw |
A list.w object describing the neighbours typically produced by the spdep package. Required if data is a dataframe, see the parameter window if you use a list of rasters as input. |
window |
If data is a list of rasters, then a window must be specified instead of a list.w object. It will be used to calculate a focal function on each raster. The window must be a square numeric matrix with odd dimensions (such 3x3). The values in the matrix indicate the weight to give to each pixel and the centre of the matrix is the centre of the focal function. |
standardize |
A boolean to specify if the variable must be centered and reduced (default = True) |
... |
not used |
A numeric matrix with the membership values for each new observation. If rasters were used, return a list of rasters with the membership values.
data(LyonIris)
AnalysisFields <-c("Lden","NO2","PM25","VegHautPrt","Pct0_14","Pct_65","Pct_Img",
"TxChom1564","Pct_brevet","NivVieMed")
# rescaling all the variables used in the analysis
for (field in AnalysisFields) {
LyonIris[[field]] <- scale(LyonIris[[field]])
}
# doing the initial clustering
dataset <- sf::st_drop_geometry(LyonIris[AnalysisFields])
queen <- spdep::poly2nb(LyonIris,queen=TRUE)
Wqueen <- spdep::nb2listw(queen,style="W")
result <- SGFCMeans(dataset, Wqueen,k = 5, m = 1.5, alpha = 1.5, beta = 0.5, standardize = FALSE)
# using a subset of the original dataframe as "new data"
new_data <- LyonIris[c(1, 27, 36, 44, 73),]
new_dataset <- sf::st_drop_geometry(new_data[AnalysisFields])
new_nb <- spdep::poly2nb(new_data,queen=TRUE)
new_Wqueen <- spdep::nb2listw(new_nb,style="W")
# doing the prediction
predictions <- predict_membership(result, new_dataset, new_Wqueen, standardize = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.