## S3 method for class 'factor'
fmi(actual, predicted, ...)
## S3 method for class 'cmatrix'
fmi(x, ...)
fmi(...)
Fowlkes-Mallows index
fmi.factor | R Documentation |
Description
The fmi()
-function computes the Fowlkes-Mallows Index (FMI), a measure of the similarity between two sets of clusterings, between two vectors of predicted and observed factor()
values.
Usage
Arguments
actual
|
A vector of |
predicted
|
A vector of |
…
|
Arguments passed into other methods |
x
|
A confusion matrix created |
Value
A <numeric>
-vector of length 1
Calculation
The metric is calculated for each class \(k\) as follows,
\[ \sqrt{\frac{\#TP_k}{\#TP_k + \#FP_k} \times \frac{\#TP_k}{\#TP_k + \#FN_k}} \]
Where \(\#TP_k\), \(\#FP_k\), and \(\#FN_k\) represent the number of true positives, false positives, and false negatives for each class \(k\), respectively.
Examples
# 1) recode Iris
# to binary classification
# problem
$species_num <- as.numeric(
iris$Species == "virginica"
iris
)
# 2) fit the logistic
# regression
<- glm(
model formula = species_num ~ Sepal.Length + Sepal.Width,
data = iris,
family = binomial(
link = "logit"
)
)
# 3) generate predicted
# classes
<- factor(
predicted as.numeric(
predict(model, type = "response") >` 0.5
),
levels = c(1,0),
labels = c("Virginica", "Others")
)
# 3.1) generate actual
# classes
actual <- factor(
x = iris$species_num,
levels = c(1,0),
labels = c("Virginica", "Others")
)
# 4) evaluate model performance
# using Fowlkes Mallows Index
cat(
"Fowlkes Mallows Index", fmi(
actual = actual,
predicted = predicted
),
sep = "\n"
)